123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- //
- // FKDetailRequest.m
- // FirstLink
- //
- // Created by jack on 15/9/23.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "FKDetailRequest.h"
- @implementation FKDetailRequest
- + (void)requestWithType:(kRequestType)type info:(NSDictionary *)info delegate:(id <FLNetworkDelegate>)delegate{
- NSString *itemJsonString = [self jsonStringForRequestType:type info:info];
- NSDictionary *para = [self getCommonParaWithType:type itemJson:itemJsonString];
- NSString *urlString = [self urlStringForRequestType:type];
-
- [[FLDataCenter sharedDataCenter] POST:urlString para:para identify:type delegate:delegate];
- }
- + (NSDictionary *)getCommonParaWithType:(kRequestType)type itemJson:(NSString *)itemJson {
- if (!itemJson || itemJson.length == 0) return nil;
-
- NSString *itemJsonKey = nil;
- switch (type) {
- case kRequestTypeDetail:
- case kRequestTypeRefreshComment:
- case kRequestTypeRefreshCommentScroll:
- itemJsonKey = @"post_json";
- break;
- case kRequestTypeAddSelfComment:
- case kRequestTypeAddOtherComment:
- case kRequestTypeRemoveComment:
- itemJsonKey = @"item_comment_json";
- break;
- case kRequestTypeAddCollect:
- case kRequestTypeRemoveCollect:
- itemJsonKey = @"item_favorite_json";
- break;
- case kRequestTypeAddLike:
- case kRequestTypeRemoveLike:
- itemJsonKey = @"like_json";
- break;
- case kRequestTypeShareUrlCircle:
- case kRequestTypeShareUrlFriend:
- itemJsonKey = @"share_item_json";
- break;
- default:
- break;
- }
- if (itemJsonKey) {
- NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
- [dictM setValue:itemJson forKey:itemJsonKey];
- [dictM addEntriesFromDictionary:[FLRequestHelper commonParamater]];
- return dictM;
- }
- return nil;
- }
- + (NSString *)jsonStringForRequestType:(kRequestType)type info:(NSDictionary *)dict {
- switch (type) {
- case kRequestTypeDetail:
- case kRequestTypeRefreshComment:
- case kRequestTypeRefreshCommentScroll:
- return [FLRequestHelper JSONStringWithKeys:@[@"id", @"user_id"]
- values:@[dict[DETAIL_POSTID_KEY],
- dict[DETAIL_USERID_KEY]]];
- case kRequestTypeAddSelfComment:
- return [FLRequestHelper JSONStringWithKeys:@[@"item_id",
- @"seller_id",
- @"content"]
- values:@[dict[DETAIL_POSTID_KEY],
- dict[DETAIL_USERID_KEY],
- dict[COMMENT_CONTENT_KEY]]];
- case kRequestTypeAddOtherComment:
- return [FLRequestHelper JSONStringWithKeys:@[@"item_id",
- @"seller_id",
- @"reply_to_user_id",
- @"content"]
- values:@[dict[DETAIL_POSTID_KEY],
- dict[DETAIL_USERID_KEY],
- dict[REPLY_TO_USER_ID_KEY],
- dict[COMMENT_CONTENT_KEY]]];
- case kRequestTypeRemoveComment:
- return [FLRequestHelper JSONStringWithKeys:@[@"id",
- @"item_id",
- @"seller_id"]
- values:@[dict[COMMENT_ID_KEY],
- dict[COMMENT_ITEM_ID_KEY],
- dict[COMMENT_SELLER_ID_KEY]]];
- case kRequestTypeAddCollect:
- return [FLRequestHelper JSONStringWithKeys:@[@"item_id",
- @"seller_id",
- @"type"]
- values:@[dict[DETAIL_POSTID_KEY],
- dict[DETAIL_USERID_KEY],
- @"6"]];
- case kRequestTypeRemoveCollect:
- return [FLRequestHelper JSONStringWithKeys:@[@"item_id"]
- values:@[dict[DETAIL_POSTID_KEY]]];
- case kRequestTypeAddLike:
- case kRequestTypeRemoveLike:
- return [FLRequestHelper JSONStringWithKeys:@[@"id",
- @"user_id",
- @"type"]
- values:@[dict[DETAIL_POSTID_KEY],
- dict[DETAIL_USERID_KEY],
- @"6"]];
- case kRequestTypeShareUrlCircle:
- case kRequestTypeShareUrlFriend:
- return [FLRequestHelper JSONStringWithKeys:@[@"item_id",
- @"seller_id",
- @"share_channel_id",
- @"type"]
- values:@[dict[DETAIL_POSTID_KEY],
- dict[DETAIL_USERID_KEY],
- @"11",
- @"2"]];
- default:
- break;
- }
- return nil;
- }
- + (NSString *)urlStringForRequestType:(kRequestType)type
- {
- NSString *detailString = nil;
- switch (type) {
- case kRequestTypeDetail:{
- case kRequestTypeRefreshComment:
- case kRequestTypeRefreshCommentScroll:
- if ([FKUserManager sharedManager].applicationMode == ApplicationModeVisitor) {
- detailString = @"post/get_groupon_detail.json";
- } else {
- detailString = @"post/get_groupon.json";
- }
- }
- break;
- case kRequestTypeAddSelfComment:
- case kRequestTypeAddOtherComment:
- detailString = @"item_comment/create_item_comment.json";
- break;
- case kRequestTypeRemoveComment:
- detailString = @"item_comment/remove_item_comment.json";
- break;
- case kRequestTypeAddCollect:
- detailString = @"item_favorite/create_item_favorite.json";
- break;
- case kRequestTypeRemoveCollect:
- detailString = @"item_favorite/remove_item_favorite.json";
- break;
- case kRequestTypeAddLike:
- detailString = @"like/create_like.json";
- break;
- case kRequestTypeRemoveLike:
- detailString = @"like/remove_like.json";
- break;
- case kRequestTypeShareUrlCircle:
- case kRequestTypeShareUrlFriend:
- detailString = @"share/get_share_item_url.json";
- break;
- default:
- break;
- }
- if (detailString) {
- return [self commonURLwithString:detailString];
- }
- return nil;
- }
- + (NSString *)commonURLwithString:(NSString *)string
- {
- return [NSString stringWithFormat:@"%@/link-site/api/%@", [[FKServerUtil sharedInstance] apiServer], string];
- }
- @end
|