Created
January 31, 2018 17:00
-
-
Save husaynhakeem/2f0a77598ab5abe2d60bd5f856c86b2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import android.content.Context; | |
| import com.google.gson.GsonBuilder; | |
| import com.maketrumptweetseightagain.R; | |
| import com.twitter.sdk.android.core.models.Tweet; | |
| import java.util.List; | |
| import javax.inject.Inject; | |
| import io.reactivex.Single; | |
| import okhttp3.OkHttpClient; | |
| import retrofit2.Retrofit; | |
| import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; | |
| import retrofit2.converter.gson.GsonConverterFactory; | |
| public class TweetsService { | |
| private static final String SCREEN_NAME = "realDonaldTrump"; | |
| private static final String TWEET_MODE = "extended"; | |
| private static final boolean TRIM_USER = true; | |
| private static final int COUNT = 150; | |
| private TweetsApi tweetsApi; | |
| @Inject | |
| public TweetsService(Context context) { | |
| Retrofit retrofit = new Retrofit.Builder().baseUrl(context.getString(R.string.tweets_base_url)) | |
| .addCallAdapterFactory(RxJava2CallAdapterFactory()) | |
| .addConverterFactory(gsonConverterFactory()) | |
| .client(client(context)) | |
| .build(); | |
| tweetsApi = retrofit.create(TweetsApi.class); | |
| } | |
| private RxJava2CallAdapterFactory RxJava2CallAdapterFactory() { | |
| return RxJava2CallAdapterFactory.create(); | |
| } | |
| private GsonConverterFactory gsonConverterFactory() { | |
| return GsonConverterFactory.create(new GsonBuilder().create()); | |
| } | |
| private OkHttpClient client(Context context) { | |
| OkHttpClient.Builder builder = new OkHttpClient.Builder(); | |
| builder.addNetworkInterceptor(interceptor(context)); | |
| return builder.build(); | |
| } | |
| private Oauth1SigningInterceptor interceptor(Context context) { | |
| return new Oauth1SigningInterceptor.Builder() | |
| .accessToken(context.getString(R.string.token)) | |
| .accessSecret(context.getString(R.string.token_secret)) | |
| .consumerKey(context.getString(R.string.consumer_key)) | |
| .consumerSecret(context.getString(R.string.consumer_secret)) | |
| .clock(new Oauth1SigningInterceptor.Clock()) | |
| .build(); | |
| } | |
| public Single<List<Tweet>> getTweets(int page) { | |
| return tweetsApi.getTweets(SCREEN_NAME, TRIM_USER, TWEET_MODE, COUNT, page); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment