Created
November 26, 2014 12:21
-
-
Save Krishan14sharma/ab6eb298287b7315223f to your computer and use it in GitHub Desktop.
Quick way to create RetrofitApiClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package krishan.dhancha.api; | |
import com.squareup.okhttp.Cache; | |
import com.squareup.okhttp.OkHttpClient; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.List; | |
import krishan.dhancha.BaseApp; | |
import krishan.dhancha.model.Movie; | |
import retrofit.Callback; | |
import retrofit.RestAdapter; | |
import retrofit.client.OkClient; | |
import retrofit.http.GET; | |
import retrofit.http.Query; | |
/** | |
* Created by krishan on 26/11/14. | |
*/ | |
public class ApiClient { | |
private static ApiInterface apiInterface; | |
private static final String ENDPOINT="https://yts.re/api"; | |
public static ApiInterface getApiClient() { | |
if (apiInterface == null) { | |
OkHttpClient okHttpClient = new OkHttpClient(); | |
File cacheDir = new File(BaseApp.getContext().getCacheDir(),"response"); | |
Cache httpResponseCache = null; | |
try { | |
httpResponseCache = new Cache(cacheDir, 10 * 1024 * 1024); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
okHttpClient.setCache(httpResponseCache); | |
RestAdapter restAdapter = new RestAdapter.Builder() | |
.setEndpoint(ENDPOINT) | |
.setLogLevel(RestAdapter.LogLevel.BASIC) | |
.setClient(new OkClient(okHttpClient)) | |
.build(); | |
apiInterface = restAdapter.create(ApiInterface.class); | |
} | |
return apiInterface; | |
} | |
public interface ApiInterface { | |
@GET("/upcoming.json") | |
void getStreams(@Query("limit") int limit, @Query("set") int offset, Callback<List<Movie>> callback); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment