Java Code Examples for com.twitter.sdk.android.core.Callback#failure()
The following examples show how to use
com.twitter.sdk.android.core.Callback#failure() .
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 |
/** * 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: TimelineDelegate.java From twitter-kit-android with Apache License 2.0 | 5 votes |
/** * Checks the capacity and sets requestInFlight before calling timeline.next. */ void loadNext(Long minPosition, Callback<TimelineResult<T>> cb) { if (withinMaxCapacity()) { if (timelineStateHolder.startTimelineRequest()) { timeline.next(minPosition, cb); } else { cb.failure(new TwitterException("Request already in flight")); } } else { cb.failure(new TwitterException("Max capacity reached")); } }
Example 3
Source File: TimelineDelegate.java From twitter-kit-android with Apache License 2.0 | 5 votes |
/** * Checks the capacity and sets requestInFlight before calling timeline.previous. */ void loadPrevious(Long maxPosition, Callback<TimelineResult<T>> cb) { if (withinMaxCapacity()) { if (timelineStateHolder.startTimelineRequest()) { timeline.previous(maxPosition, cb); } else { cb.failure(new TwitterException("Request already in flight")); } } else { cb.failure(new TwitterException("Max capacity reached")); } }
Example 4
Source File: TweetRepository.java From twitter-kit-android with Apache License 2.0 | 5 votes |
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: OAuth1aServiceTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Test public void testCallbackWrapperFailure() { final Callback<OAuthResponse> authResponseCallback = mock(Callback.class); final Callback<ResponseBody> callbackWrapper = service.getCallbackWrapper(authResponseCallback); final TwitterException mockException = mock(TwitterException.class); callbackWrapper.failure(mockException); verify(authResponseCallback).failure(eq(mockException)); }
Example 6
Source File: OAuthControllerTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Test public void testNewRequestTempTokenCallback_failure() { final Callback<OAuthResponse> callback = controller.newRequestTempTokenCallback(); final TwitterException mockException = mock(TwitterException.class); callback.failure(mockException); verifyOnCompleteWithError("Failed to get request token"); }
Example 7
Source File: OAuthControllerTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Test public void testNewAccessTokenCallback_failure() { final Callback<OAuthResponse> callback = controller.newRequestAccessTokenCallback(); final TwitterException mockException = mock(TwitterException.class); callback.failure(mockException); verifyOnCompleteWithError("Failed to get access token"); }