Search in sources :

Example 1 with AccessTokenResponse

use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.

the class ZypeAuthentication method saveAccessToken.

public static void saveAccessToken(Map<String, Object> data) {
    String accessToken = ((AccessTokenResponse) data.get(RESPONSE_ACCESS_TOKEN)).getAccessToken();
    String refreshToken = ((AccessTokenResponse) data.get(RESPONSE_ACCESS_TOKEN)).getRefreshToken();
    long createdAt = 0;
    long expiresIn = 0;
    String resourceOwnerId = "";
    if (data.get(RESPONSE_ACCESS_TOKEN_INFO) != null) {
        createdAt = ((AccessTokenInfoResponse) data.get(RESPONSE_ACCESS_TOKEN_INFO)).createdAt;
        expiresIn = ((AccessTokenInfoResponse) data.get(RESPONSE_ACCESS_TOKEN_INFO)).expiresInSeconds;
        resourceOwnerId = ((AccessTokenInfoResponse) data.get(RESPONSE_ACCESS_TOKEN_INFO)).resourceOwnerId;
    }
    ConsumerData consumer = null;
    if (data.get(RESPONSE_CONSUMER) != null) {
        consumer = ((ConsumerResponse) data.get(RESPONSE_CONSUMER)).consumerData;
    }
    boolean isDeviceLinked = (Boolean) data.get(RESPONSE_IS_DEVICE_LINKED);
    if (com.amazon.android.module.BuildConfig.DEBUG) {
        Log.d(TAG, "Storing access token: " + accessToken);
    }
    Preferences.setString(IAuthentication.ACCESS_TOKEN, accessToken);
    Preferences.setLong(ZypeAuthentication.PREFERENCE_ACCESS_TOKEN_CREATED_AT, createdAt);
    Preferences.setLong(ZypeAuthentication.PREFERENCE_ACCESS_TOKEN_EXPIRES_IN, expiresIn);
    Preferences.setString(ZypeAuthentication.PREFERENCE_REFRESH_TOKEN, refreshToken);
    Preferences.setString(ZypeAuthentication.PREFERENCE_RESOURCE_OWNER_ID, resourceOwnerId);
    Preferences.setLong(ZypeAuthentication.PREFERENCE_CONSUMER_SUBSCRIPTION_COUNT, consumer.subscriptionCount);
    Preferences.setString(ZypeAuthentication.PREFERENCE_CONSUMER_EMAIL, consumer.email);
    Preferences.setString(ZypeAuthentication.PREFERENCE_CONSUMER_ID, consumer.id);
    Preferences.setBoolean(ZypeAuthentication.PREFERENCE_IS_DEVICE_LINKED, isDeviceLinked);
}
Also used : ConsumerData(com.zype.fire.api.Model.ConsumerData) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse)

Example 2 with AccessTokenResponse

use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.

the class ZypeAuthentication method getAccessTokenWithPin.

public static Map<String, Object> getAccessTokenWithPin(String deviceId, String pin) {
    AccessTokenResponse responseAccessToken = ZypeApi.getInstance().retrieveAccessTokenWithPin(deviceId, pin);
    AccessTokenInfoResponse responseAccessTokenInfo = null;
    ConsumerResponse responseConsumer = null;
    if (responseAccessToken != null) {
        responseAccessTokenInfo = ZypeApi.getInstance().getAccessTokenInfo(responseAccessToken.getAccessToken());
        if (responseAccessTokenInfo != null) {
            responseConsumer = ZypeApi.getInstance().getConsumer(responseAccessTokenInfo.resourceOwnerId, responseAccessToken.getAccessToken());
        }
    } else {
        return null;
    }
    Map<String, Object> result = new HashMap<>();
    result.put(RESPONSE_ACCESS_TOKEN, responseAccessToken);
    result.put(RESPONSE_ACCESS_TOKEN_INFO, responseAccessTokenInfo);
    result.put(RESPONSE_CONSUMER, responseConsumer);
    result.put(RESPONSE_IS_DEVICE_LINKED, true);
    return result;
}
Also used : HashMap(java.util.HashMap) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse)

Example 3 with AccessTokenResponse

use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.

the class ZypeApi method retrieveAccessTokenWithPin.

public AccessTokenResponse retrieveAccessTokenWithPin(String deviceId, String pin) {
    Map<String, String> params = new HashMap<>();
    params.put(LINKED_DEVICE_ID, deviceId);
    params.put(PIN, pin);
    params.put(CLIENT_ID, ZypeSettings.CLIENT_ID);
    params.put(CLIENT_GRANT_TYPE, "password");
    try {
        Response response = apiImpl.retrieveAccessToken(params).execute();
        if (response.isSuccessful()) {
            return (AccessTokenResponse) response.body();
        } else {
            return null;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Response(retrofit2.Response) VideoFavoritesResponse(com.zype.fire.api.Model.VideoFavoritesResponse) ChannelResponse(com.zype.fire.api.Model.ChannelResponse) DevicePinResponse(com.zype.fire.api.Model.DevicePinResponse) VideosResponse(com.zype.fire.api.Model.VideosResponse) AppResponse(com.zype.fire.api.Model.AppResponse) VideoResponse(com.zype.fire.api.Model.VideoResponse) VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) PlaylistsResponse(com.zype.fire.api.Model.PlaylistsResponse) ProgramResponse(com.zype.fire.api.Model.ProgramResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse) ZobjectContentResponse(com.zype.fire.api.Model.ZobjectContentResponse) PlanResponse(com.zype.fire.api.Model.PlanResponse) PlaylistResponse(com.zype.fire.api.Model.PlaylistResponse) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ZobjectTopPlaylistResponse(com.zype.fire.api.Model.ZobjectTopPlaylistResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) HashMap(java.util.HashMap) IOException(java.io.IOException) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse)

Example 4 with AccessTokenResponse

use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.

the class ZypeApi method refreshAccessToken.

public AccessTokenResponse refreshAccessToken(String refreshToken) {
    Map<String, String> params = new HashMap<>();
    params.put(REFRESH_TOKEN, refreshToken);
    params.put(CLIENT_ID, ZypeSettings.CLIENT_ID);
    params.put(CLIENT_GRANT_TYPE, "refresh_token");
    try {
        Response response = apiImpl.retrieveAccessToken(params).execute();
        if (response.isSuccessful()) {
            return (AccessTokenResponse) response.body();
        } else {
            return null;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Response(retrofit2.Response) VideoFavoritesResponse(com.zype.fire.api.Model.VideoFavoritesResponse) ChannelResponse(com.zype.fire.api.Model.ChannelResponse) DevicePinResponse(com.zype.fire.api.Model.DevicePinResponse) VideosResponse(com.zype.fire.api.Model.VideosResponse) AppResponse(com.zype.fire.api.Model.AppResponse) VideoResponse(com.zype.fire.api.Model.VideoResponse) VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) PlaylistsResponse(com.zype.fire.api.Model.PlaylistsResponse) ProgramResponse(com.zype.fire.api.Model.ProgramResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse) ZobjectContentResponse(com.zype.fire.api.Model.ZobjectContentResponse) PlanResponse(com.zype.fire.api.Model.PlanResponse) PlaylistResponse(com.zype.fire.api.Model.PlaylistResponse) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ZobjectTopPlaylistResponse(com.zype.fire.api.Model.ZobjectTopPlaylistResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) HashMap(java.util.HashMap) IOException(java.io.IOException) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse)

Example 5 with AccessTokenResponse

use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.

the class ZypeApi method retrieveAccessToken.

/*
     * OAuth
     */
public AccessTokenResponse retrieveAccessToken(String username, String password) {
    Map<String, String> params = new HashMap<>();
    params.put(USERNAME, username);
    params.put(PASSWORD, password);
    params.put(CLIENT_ID, ZypeSettings.CLIENT_ID);
    params.put(CLIENT_GRANT_TYPE, "password");
    try {
        Response response = apiImpl.retrieveAccessToken(params).execute();
        if (response.isSuccessful()) {
            return (AccessTokenResponse) response.body();
        } else {
            return null;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Response(retrofit2.Response) VideoFavoritesResponse(com.zype.fire.api.Model.VideoFavoritesResponse) ChannelResponse(com.zype.fire.api.Model.ChannelResponse) DevicePinResponse(com.zype.fire.api.Model.DevicePinResponse) VideosResponse(com.zype.fire.api.Model.VideosResponse) AppResponse(com.zype.fire.api.Model.AppResponse) VideoResponse(com.zype.fire.api.Model.VideoResponse) VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) PlaylistsResponse(com.zype.fire.api.Model.PlaylistsResponse) ProgramResponse(com.zype.fire.api.Model.ProgramResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse) ZobjectContentResponse(com.zype.fire.api.Model.ZobjectContentResponse) PlanResponse(com.zype.fire.api.Model.PlanResponse) PlaylistResponse(com.zype.fire.api.Model.PlaylistResponse) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ZobjectTopPlaylistResponse(com.zype.fire.api.Model.ZobjectTopPlaylistResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) HashMap(java.util.HashMap) IOException(java.io.IOException) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse)

Aggregations

AccessTokenResponse (com.zype.fire.api.Model.AccessTokenResponse)7 AccessTokenInfoResponse (com.zype.fire.api.Model.AccessTokenInfoResponse)6 ConsumerResponse (com.zype.fire.api.Model.ConsumerResponse)6 HashMap (java.util.HashMap)6 AppResponse (com.zype.fire.api.Model.AppResponse)3 ChannelResponse (com.zype.fire.api.Model.ChannelResponse)3 DevicePinResponse (com.zype.fire.api.Model.DevicePinResponse)3 PlanResponse (com.zype.fire.api.Model.PlanResponse)3 PlaylistResponse (com.zype.fire.api.Model.PlaylistResponse)3 PlaylistsResponse (com.zype.fire.api.Model.PlaylistsResponse)3 ProgramResponse (com.zype.fire.api.Model.ProgramResponse)3 VideoEntitlementsResponse (com.zype.fire.api.Model.VideoEntitlementsResponse)3 VideoFavoritesResponse (com.zype.fire.api.Model.VideoFavoritesResponse)3 VideoResponse (com.zype.fire.api.Model.VideoResponse)3 VideosResponse (com.zype.fire.api.Model.VideosResponse)3 ZobjectContentResponse (com.zype.fire.api.Model.ZobjectContentResponse)3 ZobjectTopPlaylistResponse (com.zype.fire.api.Model.ZobjectTopPlaylistResponse)3 IOException (java.io.IOException)3 Response (retrofit2.Response)3 ConsumerData (com.zype.fire.api.Model.ConsumerData)1