Search in sources :

Example 1 with DevicePinResponse

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

the class ZypeLoginActivity method getAccessTokenWithPin.

public void getAccessTokenWithPin() {
    if (NetworkUtils.isConnectedToNetwork(this)) {
        (new AsyncTask<Void, Void, Map>() {

            @Override
            protected Map<String, Object> doInBackground(Void... params) {
                String deviceId = AdMacrosHelper.getAdvertisingId(ZypeLoginActivity.this);
                // Check if the device is linked
                DevicePinResponse responseDevicePin = ZypeApi.getInstance().getDevicePin(deviceId);
                if (responseDevicePin != null) {
                    if (responseDevicePin.data.linked) {
                        // If linked get access token with device pin
                        return ZypeAuthentication.getAccessTokenWithPin(deviceId, pin);
                    } else {
                        return null;
                    }
                } else {
                    return null;
                }
            }

            @Override
            protected void onPostExecute(Map response) {
                super.onPostExecute(response);
                if (response != null) {
                    // Successful login.
                    ZypeAuthentication.saveAccessToken(response);
                    setResult(RESULT_OK);
                    buttonLogin.setEnabled(true);
                    finish();
                } else {
                    buttonLogin.setEnabled(true);
                    // There was an error authenticating the user entered token.
                    setResultAndReturn(null, AuthenticationConstants.AUTHENTICATION_ERROR_CATEGORY);
                }
            }
        }).execute();
    } else {
        setResultAndReturn(null, AuthenticationConstants.NETWORK_ERROR_CATEGORY);
    }
}
Also used : AsyncTask(android.os.AsyncTask) DevicePinResponse(com.zype.fire.api.Model.DevicePinResponse) Map(java.util.Map)

Example 2 with DevicePinResponse

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

the class ZypeApi method createDevicePin.

public DevicePinResponse createDevicePin(String deviceId) {
    try {
        HashMap<String, String> params = new HashMap<>();
        params.put(APP_KEY, ZypeSettings.APP_KEY);
        params.put(LINKED_DEVICE_ID, deviceId);
        Response response = apiImpl.createDevicePin(params).execute();
        if (response.isSuccessful()) {
            return (DevicePinResponse) 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) DevicePinResponse(com.zype.fire.api.Model.DevicePinResponse) IOException(java.io.IOException)

Example 3 with DevicePinResponse

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

the class ZypeApi method getDevicePin.

public DevicePinResponse getDevicePin(String deviceId) {
    try {
        HashMap<String, String> params = new HashMap<>();
        params.put(APP_KEY, ZypeSettings.APP_KEY);
        params.put(LINKED_DEVICE_ID, deviceId);
        Response response = apiImpl.getDevicePin(params).execute();
        if (response.isSuccessful()) {
            return (DevicePinResponse) 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) DevicePinResponse(com.zype.fire.api.Model.DevicePinResponse) IOException(java.io.IOException)

Aggregations

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