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

The following examples show how to use com.twitter.sdk.android.core.Session. 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: SessionMonitorTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    mockSessionManager = mock(SessionManager.class);
    mockSystemCurrentTimeProvider = mock(SystemCurrentTimeProvider.class);
    mockExecutorService = mock(ExecutorService.class);
    mockMonitorState = mock(SessionMonitor.MonitorState.class);
    mockSessionVerifier = mock(SessionVerifier.class);
    sessionMonitor = new SessionMonitor<>(mockSessionManager, mockSystemCurrentTimeProvider,
            mockExecutorService, mockMonitorState, mockSessionVerifier);
    monitorState = new SessionMonitor.MonitorState();
    final Session testSession = mock(Session.class);
    when(testSession.getId()).thenReturn(1L);
    sessionMap = new HashMap<>();
    sessionMap.put(1L, testSession);

    when(mockSessionManager.getSessionMap()).thenReturn(sessionMap);
    when(mockSessionManager.getActiveSession()).thenReturn(testSession);
}
 
Example #2
Source File: OkHttpClientHelper.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
public static OkHttpClient getOkHttpClient(Session<? extends TwitterAuthToken> session,
        TwitterAuthConfig authConfig) {
    if (session == null) {
        throw new IllegalArgumentException("Session must not be null.");
    }

    return addSessionAuth(new OkHttpClient.Builder(), session, authConfig).build();
}
 
Example #3
Source File: OkHttpClientHelper.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
public static OkHttpClient getCustomOkHttpClient(
        OkHttpClient httpClient,
        Session<? extends TwitterAuthToken> session,
        TwitterAuthConfig authConfig) {
    if (session == null) {
        throw new IllegalArgumentException("Session must not be null.");
    }

    if (httpClient == null) {
        throw new IllegalArgumentException("HttpClient must not be null.");
    }

    return addSessionAuth(httpClient.newBuilder(), session, authConfig)
            .build();
}
 
Example #4
Source File: OkHttpClientHelper.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
static OkHttpClient.Builder addSessionAuth(OkHttpClient.Builder builder,
                                           Session<? extends TwitterAuthToken> session,
                                           TwitterAuthConfig authConfig) {
    return builder
            .certificatePinner(getCertificatePinner())
            .addInterceptor(new OAuth1aInterceptor(session, authConfig));
}
 
Example #5
Source File: SessionMonitor.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
/**
 * triggerVerificationIfNecessary checks if there are any sessions to verify and if enough time
 * has passed in order to run another verification. If it determines it can verify, it submits a
 * runnable that does the verification in a background thread.
 */
public void triggerVerificationIfNecessary() {
    final Session session = sessionManager.getActiveSession();
    final long currentTime = time.getCurrentTimeMillis();
    final boolean startVerification = session != null &&
            monitorState.beginVerification(currentTime);
    if (startVerification) {
        executorService.submit(this::verifyAll);
    }
}
 
Example #6
Source File: SessionMonitorTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testVerifySession_callsAccountService() {
    when(mockMonitorState.beginVerification(anyLong())).thenReturn(Boolean.TRUE);
    sessionMonitor.triggerVerificationIfNecessary();
    final ArgumentCaptor<Runnable> runnableArgumentCaptor = ArgumentCaptor.forClass(Runnable
            .class);
    verify(mockExecutorService).submit(runnableArgumentCaptor.capture());
    final Runnable tasks = runnableArgumentCaptor.getValue();
    tasks.run();
    verify(mockSessionVerifier).verifySession(any(Session.class));
}
 
Example #7
Source File: SessionRecorder.java    From cannonball-android with Apache License 2.0 5 votes vote down vote up
public static Session recordInitialSessionState(Session twitterSession,
                                                Session digitsSession) {
    if (twitterSession != null) {
        recordSessionActive("Splash: user with active Twitter session", twitterSession);
        return twitterSession;
    } else if (digitsSession != null) {
        recordSessionActive("Splash: user with active Digits session", digitsSession);
        return digitsSession;
    } else {
        recordSessionInactive("Splash: anonymous user");
        return null;
    }
}
 
Example #8
Source File: InitialActivity.java    From cannonball-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Session activeSession = SessionRecorder.recordInitialSessionState(
            Twitter.getSessionManager().getActiveSession(),
            Digits.getSessionManager().getActiveSession()
    );

    if (activeSession != null) {
        startThemeActivity();
    } else {
        startLoginActivity();
    }
}
 
Example #9
Source File: RxTwitterApiClient.java    From photosearcher with Apache License 2.0 4 votes vote down vote up
public RxTwitterApiClient(Session session) {
    super(session);
}
 
Example #10
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 #11
Source File: OAuth1aInterceptor.java    From twitter-kit-android with Apache License 2.0 4 votes vote down vote up
public OAuth1aInterceptor(Session<? extends TwitterAuthToken> session,
        TwitterAuthConfig authConfig) {
    this.session = session;
    this.authConfig = authConfig;
}
 
Example #12
Source File: SessionMonitorTest.java    From twitter-kit-android with Apache License 2.0 4 votes vote down vote up
@Test
public void testVerifyAll_verifiesAllSessions() {
    sessionMap.put(2L, mock(Session.class));
    sessionMonitor.verifyAll();
    verify(mockSessionVerifier, times(2)).verifySession(any(Session.class));
}
 
Example #13
Source File: SessionRecorder.java    From cannonball-android with Apache License 2.0 4 votes vote down vote up
public static void recordSessionActive(String message, Session session) {
    recordSessionActive(message, String.valueOf(session.getId()));
}