Search in sources :

Example 1 with DownloadVideoResponse

use of com.zype.android.webapi.model.download.DownloadVideoResponse in project zype-android by zype.

the class WebApiManager method executeJob.

private DataEvent executeJob(Job job) {
    Request request = job.getRequest();
    Bundle args = job.getOptions();
    RequestTicket ticket = job.getTicket();
    HashMap<String, String> pathParams = (HashMap<String, String>) args.getSerializable(ParamsBuilder.PATH_PARAMS);
    HashMap<String, String> postParams = (HashMap<String, String>) args.getSerializable(ParamsBuilder.POST_PARAMS);
    HashMap<String, String> getParams = (HashMap<String, String>) args.getSerializable(ParamsBuilder.GET_PARAMS);
    String videoId;
    String playlistId;
    assert getParams != null;
    assert pathParams != null;
    // Making sure we add the token to the request on the same thread that it is refreshed on.
    // This way we don't have to worry about any timing issues with accessing it and refreshing it at the same time
    String accessToken = "access_token";
    if (getParams.containsKey(accessToken))
        getParams.put(accessToken, SettingsProvider.getInstance().getAccessToken());
    if (pathParams.containsKey(accessToken))
        pathParams.put(accessToken, SettingsProvider.getInstance().getAccessToken());
    if (postParams != null && postParams.containsKey(accessToken))
        postParams.put(accessToken, SettingsProvider.getInstance().getAccessToken());
    switch(request) {
        case AUTH_REFRESH_ACCESS_TOKEN:
            return new RefreshAccessTokenEvent(ticket, new RefreshAccessToken(mApi.authRefreshAccessToken(postParams)));
        case AUTH_RETRIEVE_ACCESS_TOKEN:
            return new RetrieveAccessTokenEvent(ticket, new RetrieveAccessToken(mApi.authRetrieveAccessToken(postParams)));
        case TOKEN_INFO:
            String token = getParams.get(AuthParamsBuilder.ACCESS_TOKEN);
            return new AccessTokenInfoEvent(ticket, new AccessTokenInfoResponse(mApi.getTokenInfo(token)));
        case VIDEO_LATEST_GET:
            return new RetrieveVideoEvent(ticket, new VideoResponse(mApi.getVideoList(getParams)));
        case VIDEO_HIGHLIGHT_GET:
            return new RetrieveHighLightVideoEvent(ticket, new VideoResponse(mApi.getVideoList(getParams)));
        case CONSUMER_FAVORITE_VIDEO_GET:
            return new ConsumerFavoriteVideoEvent(ticket, new ConsumerFavoriteVideoResponse(mApi.getFavoriteVideoList(SettingsProvider.getInstance().getConsumerId(), getParams)));
        case FAVORITE:
            return new FavoriteEvent(ticket, new FavoriteResponse(mApi.setFavoriteVideo(SettingsProvider.getInstance().getConsumerId(), postParams)));
        case UN_FAVORITE:
            String favoriteId = pathParams.get(FavoriteParamsBuilder.FAVORITE_ID);
            videoId = pathParams.get(FavoriteParamsBuilder.VIDEO_ID);
            return new UnfavoriteEvent(ticket, new UnfavoriteResponse(mApi.setUnFavoriteVideo(SettingsProvider.getInstance().getConsumerId(), favoriteId, postParams)), videoId);
        case CONSUMER_CREATE:
            return new ConsumerEvent(ticket, new ConsumerResponse(mApi.createConsumer(getParams, postParams)));
        case CONSUMER_GET:
            return new ConsumerEvent(ticket, new ConsumerResponse(mApi.getConsumer(SettingsProvider.getInstance().getAccessTokenResourceOwnerId(), getParams)));
        case CATEGORY:
            return new CategoryEvent(ticket, new CategoryResponse(mApi.getCategory(getParams)));
        case Z_OBJECT:
            return new ZObjectEvent(ticket, new ZObjectResponse(mApi.getZobject(getParams)));
        case GET_SETTINGS:
            return new SettingsEvent(ticket, new SettingsResponse(mApi.getSettings(getParams)));
        case CONTENT_SETTINGS:
            return new ContentSettingsEvent(ticket, new ContentSettingsResponse(mApi.getContentSettings(getParams)));
        case LIVE_STREAM_SETTINGS:
            return new LiveStreamSettingsEvent(ticket, new LiveStreamSettingsResponse(mApi.getLiveStreamSettings(getParams)));
        case SEARCH:
            return new SearchEvent(ticket, new SearchResponse(mApi.getSearchVideo(getParams)));
        case PLAYER_VIDEO:
            videoId = getParams.get(PlayerParamsBuilder.VIDEO_ID);
            return new PlayerVideoEvent(ticket, new PlayerVideoResponse(mDownloadApi.getVideoPlayer(videoId, getParams)));
        case PLAYER_AUDIO:
            videoId = getParams.get(PlayerParamsBuilder.VIDEO_ID);
            return new PlayerAudioEvent(ticket, new PlayerAudioResponse(mApi.getAudioPlayer(videoId, getParams)));
        case PLAYER_DOWNLOAD_VIDEO:
            videoId = pathParams.get(DownloadVideoParamsBuilder.VIDEO_ID);
            return new DownloadVideoEvent(ticket, new DownloadVideoResponse(mDownloadApi.getDownloadVideo(videoId, getParams)), videoId);
        case PLAYER_DOWNLOAD_AUDIO:
            videoId = pathParams.get(DownloadAudioParamsBuilder.VIDEO_ID);
            return new DownloadAudioEvent(ticket, new DownloadAudioResponse(mDownloadApi.getDownloadAudio(videoId, getParams)), videoId);
        case ON_AIR:
            return new OnAirEvent(ticket, new OnAirResponse(mApi.getOnAir(getParams)));
        case PLAYER_ON_AIR_VIDEO:
            videoId = getParams.get(PlayerParamsBuilder.VIDEO_ID);
            getParams.remove(PlayerParamsBuilder.VIDEO_ID);
            return new OnAirVideoEvent(ticket, new OnAirVideoResponse(mCookieApi.getOnAirVideo(videoId, getParams)));
        case PLAYER_ON_AIR_AUDIO:
            videoId = getParams.get(PlayerParamsBuilder.VIDEO_ID);
            getParams.remove(PlayerParamsBuilder.VIDEO_ID);
            return new OnAirAudioEvent(ticket, new OnAirAudioResponse(mCookieApi.getOnAirAudio(videoId, getParams)));
        case PLAYLIST_GET:
            return new PlaylistEvent(ticket, new PlaylistResponse(mApi.getPlaylists(getParams)));
        case VIDEO_FROM_PLAYLIST:
            if (pathParams.containsKey(VideoParamsBuilder.PLAYLIST_ID)) {
                playlistId = pathParams.get(VideoParamsBuilder.PLAYLIST_ID);
                return new RetrieveVideoEvent(ticket, new VideoResponse(mApi.getVideosFromPlaylist(playlistId, getParams)));
            } else {
                throw new IllegalStateException("VideoParamsBuilder.PLAYLIST_ID can not be null");
            }
        case CHECK_VIDEO_ENTITLEMENT:
            videoId = pathParams.get(EntitlementParamsBuilder.VIDEO_ID);
            return new VideoEntitlementEvent(ticket, args, new VideoEntitlementResponse(mApi.checkVideoEntitlement(videoId, getParams)));
        case VIDEO_ENTITLEMENTS:
            return new VideoEntitlementsEvent(ticket, new VideoEntitlementsResponse(mApi.getVideoEntitlements(getParams)));
        default:
            throw new RuntimeException("Unknown request:" + request);
    }
}
Also used : PlayerVideoResponse(com.zype.android.webapi.model.player.PlayerVideoResponse) HashMap(java.util.HashMap) VideoEntitlementResponse(com.zype.android.webapi.model.entitlements.VideoEntitlementResponse) PlayerAudioEvent(com.zype.android.webapi.events.player.PlayerAudioEvent) VideoEntitlementsResponse(com.zype.android.webapi.model.entitlements.VideoEntitlementsResponse) RetrieveVideoEvent(com.zype.android.webapi.events.video.RetrieveVideoEvent) ContentSettingsResponse(com.zype.android.webapi.model.settings.ContentSettingsResponse) LiveStreamSettingsResponse(com.zype.android.webapi.model.settings.LiveStreamSettingsResponse) SettingsResponse(com.zype.android.webapi.model.settings.SettingsResponse) PlaylistEvent(com.zype.android.webapi.events.playlist.PlaylistEvent) ZObjectResponse(com.zype.android.webapi.model.zobjects.ZObjectResponse) PlayerAudioResponse(com.zype.android.webapi.model.player.PlayerAudioResponse) ZObjectEvent(com.zype.android.webapi.events.zobject.ZObjectEvent) SearchResponse(com.zype.android.webapi.model.search.SearchResponse) LiveStreamSettingsResponse(com.zype.android.webapi.model.settings.LiveStreamSettingsResponse) RetrieveAccessToken(com.zype.android.webapi.model.auth.RetrieveAccessToken) ConsumerFavoriteVideoResponse(com.zype.android.webapi.model.consumers.ConsumerFavoriteVideoResponse) OnAirAudioEvent(com.zype.android.webapi.events.onair.OnAirAudioEvent) UnfavoriteEvent(com.zype.android.webapi.events.favorite.UnfavoriteEvent) OnAirEvent(com.zype.android.webapi.events.onair.OnAirEvent) RetrieveHighLightVideoEvent(com.zype.android.webapi.events.video.RetrieveHighLightVideoEvent) ConsumerEvent(com.zype.android.webapi.events.consumer.ConsumerEvent) ContentSettingsEvent(com.zype.android.webapi.events.settings.ContentSettingsEvent) SettingsEvent(com.zype.android.webapi.events.settings.SettingsEvent) LiveStreamSettingsEvent(com.zype.android.webapi.events.settings.LiveStreamSettingsEvent) AccessTokenInfoEvent(com.zype.android.webapi.events.auth.AccessTokenInfoEvent) ContentSettingsEvent(com.zype.android.webapi.events.settings.ContentSettingsEvent) CategoryResponse(com.zype.android.webapi.model.category.CategoryResponse) PlaylistResponse(com.zype.android.webapi.model.playlist.PlaylistResponse) RefreshAccessTokenEvent(com.zype.android.webapi.events.auth.RefreshAccessTokenEvent) PlayerVideoEvent(com.zype.android.webapi.events.player.PlayerVideoEvent) VideoEntitlementEvent(com.zype.android.webapi.events.entitlements.VideoEntitlementEvent) AccessTokenInfoResponse(com.zype.android.webapi.model.auth.AccessTokenInfoResponse) UnfavoriteResponse(com.zype.android.webapi.model.favorite.UnfavoriteResponse) FavoriteResponse(com.zype.android.webapi.model.favorite.FavoriteResponse) PlayerVideoResponse(com.zype.android.webapi.model.player.PlayerVideoResponse) DownloadVideoResponse(com.zype.android.webapi.model.download.DownloadVideoResponse) OnAirVideoResponse(com.zype.android.webapi.model.onair.OnAirVideoResponse) ConsumerFavoriteVideoResponse(com.zype.android.webapi.model.consumers.ConsumerFavoriteVideoResponse) VideoResponse(com.zype.android.webapi.model.video.VideoResponse) LiveStreamSettingsEvent(com.zype.android.webapi.events.settings.LiveStreamSettingsEvent) OnAirResponse(com.zype.android.webapi.model.onair.OnAirResponse) FavoriteEvent(com.zype.android.webapi.events.favorite.FavoriteEvent) RetrieveAccessTokenEvent(com.zype.android.webapi.events.auth.RetrieveAccessTokenEvent) DownloadVideoResponse(com.zype.android.webapi.model.download.DownloadVideoResponse) OnAirAudioResponse(com.zype.android.webapi.model.onair.OnAirAudioResponse) DownloadVideoEvent(com.zype.android.webapi.events.download.DownloadVideoEvent) ConsumerFavoriteVideoEvent(com.zype.android.webapi.events.consumer.ConsumerFavoriteVideoEvent) ContentSettingsResponse(com.zype.android.webapi.model.settings.ContentSettingsResponse) VideoEntitlementsEvent(com.zype.android.webapi.events.entitlements.VideoEntitlementsEvent) Bundle(android.os.Bundle) RefreshAccessToken(com.zype.android.webapi.model.auth.RefreshAccessToken) DownloadAudioResponse(com.zype.android.webapi.model.download.DownloadAudioResponse) SearchEvent(com.zype.android.webapi.events.search.SearchEvent) OnAirVideoResponse(com.zype.android.webapi.model.onair.OnAirVideoResponse) DownloadAudioEvent(com.zype.android.webapi.events.download.DownloadAudioEvent) CategoryEvent(com.zype.android.webapi.events.category.CategoryEvent) ConsumerResponse(com.zype.android.webapi.model.consumers.ConsumerResponse) OnAirVideoEvent(com.zype.android.webapi.events.onair.OnAirVideoEvent)

Aggregations

Bundle (android.os.Bundle)1 AccessTokenInfoEvent (com.zype.android.webapi.events.auth.AccessTokenInfoEvent)1 RefreshAccessTokenEvent (com.zype.android.webapi.events.auth.RefreshAccessTokenEvent)1 RetrieveAccessTokenEvent (com.zype.android.webapi.events.auth.RetrieveAccessTokenEvent)1 CategoryEvent (com.zype.android.webapi.events.category.CategoryEvent)1 ConsumerEvent (com.zype.android.webapi.events.consumer.ConsumerEvent)1 ConsumerFavoriteVideoEvent (com.zype.android.webapi.events.consumer.ConsumerFavoriteVideoEvent)1 DownloadAudioEvent (com.zype.android.webapi.events.download.DownloadAudioEvent)1 DownloadVideoEvent (com.zype.android.webapi.events.download.DownloadVideoEvent)1 VideoEntitlementEvent (com.zype.android.webapi.events.entitlements.VideoEntitlementEvent)1 VideoEntitlementsEvent (com.zype.android.webapi.events.entitlements.VideoEntitlementsEvent)1 FavoriteEvent (com.zype.android.webapi.events.favorite.FavoriteEvent)1 UnfavoriteEvent (com.zype.android.webapi.events.favorite.UnfavoriteEvent)1 OnAirAudioEvent (com.zype.android.webapi.events.onair.OnAirAudioEvent)1 OnAirEvent (com.zype.android.webapi.events.onair.OnAirEvent)1 OnAirVideoEvent (com.zype.android.webapi.events.onair.OnAirVideoEvent)1 PlayerAudioEvent (com.zype.android.webapi.events.player.PlayerAudioEvent)1 PlayerVideoEvent (com.zype.android.webapi.events.player.PlayerVideoEvent)1 PlaylistEvent (com.zype.android.webapi.events.playlist.PlaylistEvent)1 SearchEvent (com.zype.android.webapi.events.search.SearchEvent)1