Skip to content

Instantly share code, notes, and snippets.

@Sottti
Created October 18, 2015 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sottti/fc2cfa8ff672d5cd2915 to your computer and use it in GitHub Desktop.
Save Sottti/fc2cfa8ff672d5cd2915 to your computer and use it in GitHub Desktop.
Retrofit set up
public class ApiCalls
{
public static Call<DummyObject> getDummyObjectCall()
{
return ApiServices
.getDummyService()
.getDummyObject();
}
public static Call<List<DummyObject>> getDummyObjectListCall()
{
return ApiServices
.getDummyService()
.getDummyObjectList();
}
}
public class ApiClients
{
private static Retrofit mClient;
public static Retrofit getApiClient()
{
if (mClient == null)
{
mClient = new Retrofit
.Builder()
.baseUrl(BuildConfig.apiDomainName)
.addConverterFactory(MoshiConverterFactory.create())
.build();
}
return mClient;
}
}
public class ApiServices
{
private static DummyService mDummyService;
public interface DummyService
{
@GET("/v2/55973508b0e9e4a71a02f05f")
Call<DummyObject> getDummyObject();
@GET ("/v2/5597d86a6344715505576725")
Call<List<DummyObject>> getDummyObjectList();
}
public static DummyService getDummyService()
{
if (mDummyService == null)
{
mDummyService = ApiClients
.getApiClient()
.create(DummyService.class);
}
return mDummyService;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment