Java Code Examples for com.twitter.sdk.android.core.Callback#success()

The following examples show how to use com.twitter.sdk.android.core.Callback#success() . 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: AuthHandler.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
/**
 * Called when {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
 * is called to complete the authorization flow.
 *
 * @param requestCode the request code used for SSO
 * @param resultCode  the result code returned by the SSO activity
 * @param data        the result data returned by the SSO activity
 */
public boolean handleOnActivityResult(int requestCode, int resultCode, Intent data) {
    if (this.requestCode != requestCode) {
        return false;
    }

    final Callback<TwitterSession> callback = getCallback();
    if (callback != null) {
        if (resultCode == Activity.RESULT_OK) {
            final String token = data.getStringExtra(EXTRA_TOKEN);
            final String tokenSecret = data.getStringExtra(EXTRA_TOKEN_SECRET);
            final String screenName = data.getStringExtra(EXTRA_SCREEN_NAME);
            final long userId = data.getLongExtra(EXTRA_USER_ID, 0L);
            callback.success(new Result<>(new TwitterSession(
                    new TwitterAuthToken(token, tokenSecret), userId, screenName), null));
        } else if (data != null && data.hasExtra(EXTRA_AUTH_ERROR)) {
            callback.failure(
                    (TwitterAuthException) data.getSerializableExtra(EXTRA_AUTH_ERROR));
        } else {
            callback.failure(new TwitterAuthException("Authorize failed."));
        }
    }
    return true;
}
 
Example 2
Source File: OAuth1aServiceTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testCallbackWrapperSuccess_iOException() throws IOException {
    final Callback<OAuthResponse> callback = new Callback<OAuthResponse>() {
        @Override
        public void success(Result<OAuthResponse> result) {
            fail();
        }

        @Override
        public void failure(TwitterException exception) {
            assertNotNull(exception);
        }
    };
    final Callback<ResponseBody> callbackWrapper = service.getCallbackWrapper(callback);
    final ResponseBody responseBody = ResponseBody.create(MediaType.parse("application/json"), "");
    callbackWrapper.success(new Result<>(responseBody, Response.success(responseBody)));
}
 
Example 3
Source File: OAuthControllerTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testNewAccessTokenCallback_success() {
    final Callback<OAuthResponse> callback = controller.newRequestAccessTokenCallback();
    final OAuthResponse oAuthResponse = new OAuthResponse(
            new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET),
            TestFixtures.SCREEN_NAME, TestFixtures.USER_ID);
    callback.success(new Result<>(oAuthResponse, null));

    final ArgumentCaptor<Intent> intentArgCaptor = ArgumentCaptor.forClass(Intent.class);
    verify(mockListener).onComplete(eq(Activity.RESULT_OK), intentArgCaptor.capture());
    final Intent data = intentArgCaptor.getValue();
    assertEquals(TestFixtures.SCREEN_NAME, data.getStringExtra(AuthHandler.EXTRA_SCREEN_NAME));
    assertEquals(TestFixtures.USER_ID, data.getLongExtra(AuthHandler.EXTRA_USER_ID, 0L));
    assertEquals(TestFixtures.TOKEN, data.getStringExtra(AuthHandler.EXTRA_TOKEN));
    assertEquals(TestFixtures.SECRET, data.getStringExtra(AuthHandler.EXTRA_TOKEN_SECRET));
}
 
Example 4
Source File: TweetRepository.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
void getUserSession(final Callback<TwitterSession> cb) {
    final TwitterSession session = userSessionManagers.getActiveSession();
    if (session == null) {
        cb.failure(new TwitterAuthException("User authorization required"));
    } else {
        cb.success(new Result<>(session, null));
    }
}
 
Example 5
Source File: FixedTweetTimeline.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
public void next(Long minPosition, Callback<TimelineResult<Tweet>> cb) {
    // always return the same fixed set of 'latest' Tweets
    final TimelineResult<Tweet> timelineResult
            = new TimelineResult<>(new TimelineCursor(tweets), tweets);
    cb.success(new Result(timelineResult, null));
}
 
Example 6
Source File: FixedTweetTimeline.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
public void previous(Long maxPosition, Callback<TimelineResult<Tweet>> cb) {
    final List<Tweet> empty = Collections.emptyList();
    final TimelineResult<Tweet> timelineResult = new TimelineResult<>(new TimelineCursor(empty),
            empty);
    cb.success(new Result(timelineResult, null));
}
 
Example 7
Source File: TweetTimelineListAdapterTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
public void next(Long sinceId, Callback<TimelineResult<Tweet>> cb) {
    final List<Tweet> tweets = TestFixtures.getTweetList(numItems);
    final TimelineCursor timelineCursor = new TimelineCursor(tweets);
    final TimelineResult<Tweet> timelineResult
            = new TimelineResult<>(timelineCursor, tweets);
    cb.success(new Result<>(timelineResult, null));
}
 
Example 8
Source File: TweetTimelineListAdapterTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
public void previous(Long maxId, Callback<TimelineResult<Tweet>> cb) {
    final List<Tweet> tweets = TestFixtures.getTweetList(numItems);
    final TimelineCursor timelineCursor = new TimelineCursor(tweets);
    final TimelineResult<Tweet> timelineResult
            = new TimelineResult<>(timelineCursor, tweets);
    cb.success(new Result<>(timelineResult, null));
}
 
Example 9
Source File: TweetTimelineRecyclerViewAdapterTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
public void next(Long sinceId, Callback<TimelineResult<Tweet>> cb) {
    final List<Tweet> tweets = TestFixtures.getTweetList(numItems);
    final TimelineCursor timelineCursor = new TimelineCursor(tweets);
    final TimelineResult<Tweet> timelineResult
            = new TimelineResult<>(timelineCursor, tweets);
    cb.success(new Result<>(timelineResult, null));
}
 
Example 10
Source File: TweetTimelineRecyclerViewAdapterTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
public void previous(Long maxId, Callback<TimelineResult<Tweet>> cb) {
    final List<Tweet> tweets = TestFixtures.getTweetList(numItems);
    final TimelineCursor timelineCursor = new TimelineCursor(tweets);
    final TimelineResult<Tweet> timelineResult
            = new TimelineResult<>(timelineCursor, tweets);
    cb.success(new Result<>(timelineResult, null));
}
 
Example 11
Source File: TimelineDelegateTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
public void next(Long sinceId, Callback<TimelineResult<TestItem>> cb) {
    final List<TestItem> testItems = new ArrayList<>();
    TestItem.populateList(testItems, numItems);
    final TimelineResult<TestItem> timelineResult
            = new TimelineResult<>(new TimelineCursor(minPosition, maxPosition), testItems);
    cb.success(new Result<>(timelineResult, null));
}
 
Example 12
Source File: TimelineDelegateTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
public void previous(Long maxId, Callback<TimelineResult<TestItem>> cb) {
    final List<TestItem> testItems = new ArrayList<>();
    TestItem.populateList(testItems, numItems);
    final TimelineResult<TestItem> timelineResult
            = new TimelineResult<>(new TimelineCursor(minPosition, maxPosition), testItems);
    cb.success(new Result<>(timelineResult, null));
}
 
Example 13
Source File: OAuth1aServiceTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
private void setupCallbackWrapperTest(String responseStr,
                                      Callback<OAuthResponse> authResponseCallback) throws IOException {
    final Callback<ResponseBody> callbackWrapper = service.getCallbackWrapper(authResponseCallback);
    final ResponseBody responseBody = ResponseBody.create(MediaType.parse("application/json"), responseStr);
    final Response<ResponseBody> response = Response.success(responseBody);

    callbackWrapper.success(new Result<>(responseBody, response));
}
 
Example 14
Source File: OAuthControllerTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewRequestTempTokenCallback_success() {
    final Callback<OAuthResponse> callback = controller.newRequestTempTokenCallback();
    final TwitterAuthToken mockRequestToken = mock(TwitterAuthToken.class);
    final OAuthResponse oAuthResponse = new OAuthResponse(mockRequestToken, null, 0L);
    callback.success(new Result<>(oAuthResponse, null));

    assertEquals(mockRequestToken, controller.requestToken);
    verify(mockOAuth1aService).getAuthorizeUrl(eq(mockRequestToken));
}