Java Code Examples for io.particle.android.sdk.utils.Py#truthy()

The following examples show how to use io.particle.android.sdk.utils.Py#truthy() . 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: ParticleAccessToken.java    From particle-android with Apache License 2.0 6 votes vote down vote up
@Nullable
public static synchronized ParticleAccessToken fromSavedSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    String accessToken = sensitiveDataStorage.getToken();
    String refreshToken = sensitiveDataStorage.getRefreshToken();
    Date expirationDate = sensitiveDataStorage.getTokenExpirationDate();

    // are either of the fields "falsey" or has the expr date passed?
    if (!Py.truthy(accessToken) || !Py.truthy(expirationDate) || expirationDate.before(new Date())) {
        return null;
    }

    ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
            new Handler(Looper.getMainLooper()));
    token.scheduleExpiration();
    return token;
}
 
Example 2
Source File: ParticleAccessToken.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@Nullable
public static synchronized ParticleAccessToken fromSavedSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    String accessToken = sensitiveDataStorage.getToken();
    String refreshToken = sensitiveDataStorage.getRefreshToken();
    Date expirationDate = sensitiveDataStorage.getTokenExpirationDate();

    // are either of the fields "falsey" or has the expr date passed?
    if (!Py.truthy(accessToken) || !Py.truthy(expirationDate) || expirationDate.before(new Date())) {
        return null;
    }

    ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
            new Handler(Looper.getMainLooper()));
    token.scheduleExpiration();
    return token;
}
 
Example 3
Source File: ParticleAccessToken.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public static synchronized ParticleAccessToken fromNewSession(Responses.LogInResponse logInResponse) {
    if (!Py.truthy(logInResponse.getAccessToken()) || !"bearer".equalsIgnoreCase(logInResponse.getTokenType())) {
        throw new IllegalArgumentException("Invalid LogInResponse: " + logInResponse);
    }

    long expirationMillis = logInResponse.getExpiresInSeconds() * 1000;
    Date expirationDate = new Date(System.currentTimeMillis() + expirationMillis);
    return fromTokenData(expirationDate, logInResponse.getAccessToken(), logInResponse.getRefreshToken());
}
 
Example 4
Source File: ParticleAccessToken.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
public static synchronized ParticleAccessToken fromNewSession(Responses.LogInResponse logInResponse) {
    if (!Py.truthy(logInResponse.accessToken) || !"bearer".equalsIgnoreCase(logInResponse.tokenType)) {
        throw new IllegalArgumentException("Invalid LogInResponse: " + logInResponse);
    }

    long expirationMillis = logInResponse.expiresInSeconds * 1000;
    Date expirationDate = new Date(System.currentTimeMillis() + expirationMillis);
    return fromTokenData(expirationDate, logInResponse.accessToken, logInResponse.refreshToken);
}