use of com.zype.android.webapi.model.consumers.ConsumerResponse 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);
}
}
Aggregations