com.twitter.sdk.android.core.TwitterApiClient Java Examples

The following examples show how to use com.twitter.sdk.android.core.TwitterApiClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TweetRepositoryTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    anyIds.add(anyId);
    mockTwitterCore = mock(TwitterCore.class);
    mockApiClient = mock(TwitterApiClient.class);
    mockStatusesService = mock(StatusesService.class, Mockito.RETURNS_MOCKS);
    when(mockApiClient.getStatusesService()).thenReturn(mockStatusesService);
    mockFavoriteService = mock(FavoriteService.class, Mockito.RETURNS_MOCKS);
    when(mockApiClient.getFavoriteService()).thenReturn(mockFavoriteService);
    when(mockTwitterCore.getApiClient(any(TwitterSession.class))).thenReturn(mockApiClient);
    when(mockTwitterCore.getApiClient()).thenReturn(mockApiClient);
    mockSessionManager = mock(SessionManager.class);
    when(mockSessionManager.getActiveSession()).thenReturn(mock(TwitterSession.class));
    mockHandler = mock(Handler.class);
    tweetRepository = new TweetRepository(mockHandler, mockSessionManager, mockTwitterCore);
}
 
Example #2
Source File: TweetUploadServiceTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    context = RuntimeEnvironment.application;
    mockMediaService = mock(MediaService.class);
    mockStatusesService = mock(StatusesService.class);
    tweet =  new TweetBuilder().setId(123L).setText(EXPECTED_TWEET_TEXT).build();
    when(mockMediaService
            .upload(any(RequestBody.class), any(RequestBody.class), any(RequestBody.class)))
            .thenReturn(mock(Call.class));
    when(mockStatusesService.update(anyString(), isNull(Long.class), isNull(Boolean.class),
            isNull(Double.class), isNull(Double.class), isNull(String.class),
            isNull(Boolean.class), eq(true), isNull(String.class)))
            .thenReturn(Calls.response(tweet));

    mockTwitterApiClient = mock(TwitterApiClient.class);
    when(mockTwitterApiClient.getStatusesService()).thenReturn(mockStatusesService);
    when(mockTwitterApiClient.getMediaService()).thenReturn(mockMediaService);

    mockDependencyProvider = mock(TweetUploadService.DependencyProvider.class);
    when(mockDependencyProvider.getTwitterApiClient(any(TwitterSession.class)))
            .thenReturn(mockTwitterApiClient);

    service = spy(Robolectric.buildService(TweetUploadService.class).create().get());
    service.dependencyProvider = mockDependencyProvider;
}
 
Example #3
Source File: ComposerControllerTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    mockComposerView = mock(ComposerView.class);
    mockContext = mock(Context.class);
    when(mockComposerView.getContext()).thenReturn(mockContext);

    mockFinisher = mock(ComposerActivity.Finisher.class);
    mockAuthToken = mock(TwitterAuthToken.class);
    mockTwitterSession = mock(TwitterSession.class);
    when(mockTwitterSession.getAuthToken()).thenReturn(mockAuthToken);

    final TwitterApiClient mockTwitterApiClient = mock(TwitterApiClient.class);
    mockAccountService = mock(AccountService.class);
    when(mockAccountService
            .verifyCredentials(any(Boolean.class), any(Boolean.class), any(Boolean.class)))
            .thenReturn(mock(Call.class));
    when(mockTwitterApiClient.getAccountService()).thenReturn(mockAccountService);


    mockDependencyProvider = mock(ComposerController.DependencyProvider.class);
    when(mockDependencyProvider.getApiClient(any(TwitterSession.class)))
            .thenReturn(mockTwitterApiClient);
    when(mockDependencyProvider.getTweetValidator()).thenReturn(new Validator());
}
 
Example #4
Source File: TweetUploadService.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
void uploadTweetWithMedia(TwitterSession session, String text, String mediaId) {
    final TwitterApiClient client = dependencyProvider.getTwitterApiClient(session);

    client.getStatusesService().update(text, null, null, null, null, null, null, true, mediaId)
            .enqueue(
                    new Callback<Tweet>() {
                        @Override
                        public void success(Result<Tweet> result) {
                            sendSuccessBroadcast(result.data.getId());
                            stopSelf();
                        }

                        @Override
                        public void failure(TwitterException exception) {
                            fail(exception);
                        }
                    });
}
 
Example #5
Source File: TwitterSignUpActivity.java    From socialmediasignup with MIT License 6 votes vote down vote up
private void handleSuccess(final TwitterSession session) {
    TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
    AccountService accountService = twitterApiClient.getAccountService();
    call = accountService.verifyCredentials(false, true, true);
    call.enqueue(new Callback<User>() {
        @Override
        public void success(Result<User> userResult) {
            SocialMediaUser user = new SocialMediaUser();
            User data = userResult.data;
            user.setUserId(String.valueOf(data.getId()));
            user.setAccessToken(session.getAuthToken().token);
            user.setProfilePictureUrl(String.format(PROFILE_PIC_URL, data.screenName));
            user.setEmail(data.email != null ? data.email : "");
            user.setFullName(data.name);
            user.setUsername(data.screenName);
            user.setPageLink(String.format(PAGE_LINK, data.screenName));
            handleSuccess(SocialMediaSignUp.SocialMediaType.TWITTER, user);
        }

        public void failure(TwitterException error) {
            handleError(error);
        }
    });
}
 
Example #6
Source File: TweetUiTestCase.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
private void createMocks() {
    mainHandler = mock(Handler.class);
    picasso = MockUtils.mockPicasso(mock(Picasso.class), mock(RequestCreator.class));

    apiClient = mock(TwitterApiClient.class);
    MockUtils.mockApiClient(apiClient);

    clients = mock(ConcurrentHashMap.class);
    MockUtils.mockClients(clients, apiClient);
}
 
Example #7
Source File: TwitterListTimelineTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    twitterCore = mock(TwitterCore.class);
    apiClient = mock(TwitterApiClient.class);
    listService = mock(ListService.class, new MockCallAnswer());

    when(apiClient.getListService()).thenReturn(listService);
    when(twitterCore.getApiClient()).thenReturn(apiClient);
}
 
Example #8
Source File: UserTimelineTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    twitterCore = mock(TwitterCore.class);
    apiClient = mock(TwitterApiClient.class);
    statusesService = mock(StatusesService.class, new MockCallAnswer());

    when(apiClient.getStatusesService()).thenReturn(statusesService);
    when(twitterCore.getApiClient()).thenReturn(apiClient);
}
 
Example #9
Source File: CollectionTimelineTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    testUserMap.put(TEST_USER_1.id, TEST_USER_1);
    testUserMap.put(TEST_USER_2.id, TEST_USER_2);
    testTweetMap.put(TEST_TWEET_1.id, TEST_TWEET_1);
    testTweetMap.put(TEST_TWEET_2.id, TEST_TWEET_2);
    testTweetMap.put(TEST_TWEET_QUOTE.id, TEST_TWEET_QUOTE);
    // testItems order Test Tweet 1, then 2
    testItems.add(new TwitterCollection.TimelineItem(
            new TwitterCollection.TimelineItem.TweetItem(5858L)));
    testItems.add(new TwitterCollection.TimelineItem(
            new TwitterCollection.TimelineItem.TweetItem(8585L)));
    testItems.add(new TwitterCollection.TimelineItem(
            new TwitterCollection.TimelineItem.TweetItem(858909L)));
    // testItemsRev orders Test Tweet 2, then 1
    testItemsRev.add(new TwitterCollection.TimelineItem(
            new TwitterCollection.TimelineItem.TweetItem(858909L)));
    testItemsRev.add(new TwitterCollection.TimelineItem(
            new TwitterCollection.TimelineItem.TweetItem(8585L)));
    testItemsRev.add(new TwitterCollection.TimelineItem(
            new TwitterCollection.TimelineItem.TweetItem(5858L)));

    twitterCore = mock(TwitterCore.class);
    apiClient = mock(TwitterApiClient.class);
    collectionService = mock(CollectionService.class, new MockCallAnswer());

    when(apiClient.getCollectionService()).thenReturn(collectionService);
    when(twitterCore.getApiClient()).thenReturn(apiClient);
}
 
Example #10
Source File: TwitterLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void fetchUserInfo(final BaseToken token) {
    mSubscribe = Flowable.create(new FlowableOnSubscribe<TwitterUser>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<TwitterUser> userEmitter) {

            TwitterApiClient apiClient = TwitterCore.getInstance().getApiClient();
            Call<User> userCall = apiClient.getAccountService().verifyCredentials(true, false, false);

            try {
                Response<User> execute = userCall.execute();
                userEmitter.onNext(new TwitterUser(execute.body()));
                userEmitter.onComplete();
            } catch (Exception e) {
                ShareLogger.e(ShareLogger.INFO.FETCH_USER_INOF_ERROR);
                userEmitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<TwitterUser>() {
                @Override
                public void accept(@NonNull TwitterUser user) {
                    mLoginListener.loginSuccess(new LoginResultData(LoginPlatform.TWITTER, token, user));
                    LoginUtil.recycle();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) {
                    mLoginListener.loginFailure(new Exception(throwable), ShareLogger.INFO.ERR_FETCH_CODE);
                    LoginUtil.recycle();
                }
            });
}
 
Example #11
Source File: SearchTimelineTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    twitterCore = mock(TwitterCore.class);
    apiClient = mock(TwitterApiClient.class);
    searchService = mock(SearchService.class, new MockCallAnswer());

    when(apiClient.getSearchService()).thenReturn(searchService);
    when(twitterCore.getApiClient()).thenReturn(apiClient);
}
 
Example #12
Source File: TwitterAuthClientTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
private void setupMockAccountService(Call<User> call) {
    final AccountService mockAccountService = mock(AccountService.class);
    when(mockAccountService.verifyCredentials(anyBoolean(), anyBoolean(), eq(true)))
            .thenReturn(call);
    final TwitterApiClient mockApiClient = mock(TwitterApiClient.class);
    when(mockApiClient.getAccountService()).thenReturn(mockAccountService);
    when(mockTwitterCore.getApiClient(any(TwitterSession.class))).thenReturn(mockApiClient);
}
 
Example #13
Source File: TweetUploadService.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
void uploadMedia(TwitterSession session, Uri imageUri, Callback<Media> callback) {
    final TwitterApiClient client = dependencyProvider.getTwitterApiClient(session);

    final String path = FileUtils.getPath(TweetUploadService.this, imageUri);
    if (path == null) {
        fail(new TwitterException("Uri file path resolved to null"));
        return;
    }
    final File file = new File(path);
    final String mimeType = FileUtils.getMimeType(file);
    final RequestBody media = RequestBody.create(MediaType.parse(mimeType), file);

    client.getMediaService().upload(media, null, null).enqueue(callback);
}
 
Example #14
Source File: MockUtils.java    From twitter-kit-android with Apache License 2.0 4 votes vote down vote up
static void mockClients(ConcurrentHashMap<Session, TwitterApiClient> clients,
                               TwitterApiClient apiClient) {
    when(clients.get(anyObject())).thenReturn(apiClient);
    when(clients.contains(anyObject())).thenReturn(true);
}
 
Example #15
Source File: TwitterSessionVerifier.java    From twitter-kit-android with Apache License 2.0 4 votes vote down vote up
public AccountService getAccountService(TwitterSession session) {
    return new TwitterApiClient(session).getAccountService();
}
 
Example #16
Source File: MockUtils.java    From twitter-kit-android with Apache License 2.0 4 votes vote down vote up
static void mockApiClient(TwitterApiClient apiClient) {
    final StatusesService statusesService = mock(StatusesService.class, new MockCallAnswer());

    when(apiClient.getStatusesService()).thenReturn(statusesService);
}
 
Example #17
Source File: TweetUploadService.java    From twitter-kit-android with Apache License 2.0 4 votes vote down vote up
TwitterApiClient getTwitterApiClient(TwitterSession session) {
    return TwitterCore.getInstance().getApiClient(session);
}
 
Example #18
Source File: ComposerController.java    From twitter-kit-android with Apache License 2.0 4 votes vote down vote up
TwitterApiClient getApiClient(TwitterSession session) {
    return TwitterCore.getInstance().getApiClient(session);
}
 
Example #19
Source File: WebModule.java    From photosearcher with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
public TwitterApiClient twitterApiClient() {
    return TwitterCore.getInstance().getApiClient();
}