Aucune description

FKDetailRequest.m 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // FKDetailRequest.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/9/23.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKDetailRequest.h"
  9. @implementation FKDetailRequest
  10. + (void)requestWithType:(kRequestType)type info:(NSDictionary *)info delegate:(id <FLNetworkDelegate>)delegate{
  11. NSString *itemJsonString = [self jsonStringForRequestType:type info:info];
  12. NSDictionary *para = [self getCommonParaWithType:type itemJson:itemJsonString];
  13. NSString *urlString = [self urlStringForRequestType:type];
  14. [[FLDataCenter sharedDataCenter] POST:urlString para:para identify:type delegate:delegate];
  15. }
  16. + (NSDictionary *)getCommonParaWithType:(kRequestType)type itemJson:(NSString *)itemJson {
  17. if (!itemJson || itemJson.length == 0) return nil;
  18. NSString *itemJsonKey = nil;
  19. switch (type) {
  20. case kRequestTypeDetail:
  21. case kRequestTypeRefreshComment:
  22. case kRequestTypeRefreshCommentScroll:
  23. itemJsonKey = @"post_json";
  24. break;
  25. case kRequestTypeAddSelfComment:
  26. case kRequestTypeAddOtherComment:
  27. case kRequestTypeRemoveComment:
  28. itemJsonKey = @"item_comment_json";
  29. break;
  30. case kRequestTypeAddCollect:
  31. case kRequestTypeRemoveCollect:
  32. itemJsonKey = @"item_favorite_json";
  33. break;
  34. case kRequestTypeAddLike:
  35. case kRequestTypeRemoveLike:
  36. itemJsonKey = @"like_json";
  37. break;
  38. case kRequestTypeShareUrlCircle:
  39. case kRequestTypeShareUrlFriend:
  40. itemJsonKey = @"share_item_json";
  41. break;
  42. default:
  43. break;
  44. }
  45. if (itemJsonKey) {
  46. NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
  47. [dictM setValue:itemJson forKey:itemJsonKey];
  48. [dictM addEntriesFromDictionary:[FLRequestHelper commonParamater]];
  49. return dictM;
  50. }
  51. return nil;
  52. }
  53. + (NSString *)jsonStringForRequestType:(kRequestType)type info:(NSDictionary *)dict {
  54. switch (type) {
  55. case kRequestTypeDetail:
  56. case kRequestTypeRefreshComment:
  57. case kRequestTypeRefreshCommentScroll:
  58. return [FLRequestHelper JSONStringWithKeys:@[@"id", @"user_id"]
  59. values:@[dict[DETAIL_POSTID_KEY],
  60. dict[DETAIL_USERID_KEY]]];
  61. case kRequestTypeAddSelfComment:
  62. return [FLRequestHelper JSONStringWithKeys:@[@"item_id",
  63. @"seller_id",
  64. @"content"]
  65. values:@[dict[DETAIL_POSTID_KEY],
  66. dict[DETAIL_USERID_KEY],
  67. dict[COMMENT_CONTENT_KEY]]];
  68. case kRequestTypeAddOtherComment:
  69. return [FLRequestHelper JSONStringWithKeys:@[@"item_id",
  70. @"seller_id",
  71. @"reply_to_user_id",
  72. @"content"]
  73. values:@[dict[DETAIL_POSTID_KEY],
  74. dict[DETAIL_USERID_KEY],
  75. dict[REPLY_TO_USER_ID_KEY],
  76. dict[COMMENT_CONTENT_KEY]]];
  77. case kRequestTypeRemoveComment:
  78. return [FLRequestHelper JSONStringWithKeys:@[@"id",
  79. @"item_id",
  80. @"seller_id"]
  81. values:@[dict[COMMENT_ID_KEY],
  82. dict[COMMENT_ITEM_ID_KEY],
  83. dict[COMMENT_SELLER_ID_KEY]]];
  84. case kRequestTypeAddCollect:
  85. return [FLRequestHelper JSONStringWithKeys:@[@"item_id",
  86. @"seller_id",
  87. @"type"]
  88. values:@[dict[DETAIL_POSTID_KEY],
  89. dict[DETAIL_USERID_KEY],
  90. @"6"]];
  91. case kRequestTypeRemoveCollect:
  92. return [FLRequestHelper JSONStringWithKeys:@[@"item_id"]
  93. values:@[dict[DETAIL_POSTID_KEY]]];
  94. case kRequestTypeAddLike:
  95. case kRequestTypeRemoveLike:
  96. return [FLRequestHelper JSONStringWithKeys:@[@"id",
  97. @"user_id",
  98. @"type"]
  99. values:@[dict[DETAIL_POSTID_KEY],
  100. dict[DETAIL_USERID_KEY],
  101. @"6"]];
  102. case kRequestTypeShareUrlCircle:
  103. case kRequestTypeShareUrlFriend:
  104. return [FLRequestHelper JSONStringWithKeys:@[@"item_id",
  105. @"seller_id",
  106. @"share_channel_id",
  107. @"type"]
  108. values:@[dict[DETAIL_POSTID_KEY],
  109. dict[DETAIL_USERID_KEY],
  110. @"11",
  111. @"2"]];
  112. default:
  113. break;
  114. }
  115. return nil;
  116. }
  117. + (NSString *)urlStringForRequestType:(kRequestType)type
  118. {
  119. NSString *detailString = nil;
  120. switch (type) {
  121. case kRequestTypeDetail:{
  122. case kRequestTypeRefreshComment:
  123. case kRequestTypeRefreshCommentScroll:
  124. if ([FKUserManager sharedManager].applicationMode == ApplicationModeVisitor) {
  125. detailString = @"post/get_groupon_detail.json";
  126. } else {
  127. detailString = @"post/get_groupon.json";
  128. }
  129. }
  130. break;
  131. case kRequestTypeAddSelfComment:
  132. case kRequestTypeAddOtherComment:
  133. detailString = @"item_comment/create_item_comment.json";
  134. break;
  135. case kRequestTypeRemoveComment:
  136. detailString = @"item_comment/remove_item_comment.json";
  137. break;
  138. case kRequestTypeAddCollect:
  139. detailString = @"item_favorite/create_item_favorite.json";
  140. break;
  141. case kRequestTypeRemoveCollect:
  142. detailString = @"item_favorite/remove_item_favorite.json";
  143. break;
  144. case kRequestTypeAddLike:
  145. detailString = @"like/create_like.json";
  146. break;
  147. case kRequestTypeRemoveLike:
  148. detailString = @"like/remove_like.json";
  149. break;
  150. case kRequestTypeShareUrlCircle:
  151. case kRequestTypeShareUrlFriend:
  152. detailString = @"share/get_share_item_url.json";
  153. break;
  154. default:
  155. break;
  156. }
  157. if (detailString) {
  158. return [self commonURLwithString:detailString];
  159. }
  160. return nil;
  161. }
  162. + (NSString *)commonURLwithString:(NSString *)string
  163. {
  164. return [NSString stringWithFormat:@"%@/link-site/api/%@", [[FKServerUtil sharedInstance] apiServer], string];
  165. }
  166. @end