WBModel.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //
  2. // WBModel.m
  3. // YYKitExample
  4. //
  5. // Created by ibireme on 15/9/4.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "WBModel.h"
  9. @implementation WBPictureMetadata
  10. + (NSDictionary *)modelCustomPropertyMapper {
  11. return @{@"cutType" : @"cut_type"};
  12. }
  13. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  14. if ([_type isEqualToString:@"GIF"]) {
  15. _badgeType = WBPictureBadgeTypeGIF;
  16. } else {
  17. if (_width > 0 && (float)_height / _width > 3) {
  18. _badgeType = WBPictureBadgeTypeLong;
  19. }
  20. }
  21. return YES;
  22. }
  23. @end
  24. @implementation WBPicture
  25. + (NSDictionary *)modelCustomPropertyMapper {
  26. return @{@"picID" : @"pic_id",
  27. @"keepSize" : @"keep_size",
  28. @"photoTag" : @"photo_tag",
  29. @"objectID" : @"object_id",
  30. @"middlePlus" : @"middleplus"};
  31. }
  32. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  33. WBPictureMetadata *meta = _large ? _large : _largest ? _largest : _original;
  34. _badgeType = meta.badgeType;
  35. return YES;
  36. }
  37. @end
  38. @implementation WBURL
  39. + (NSDictionary *)modelCustomPropertyMapper {
  40. return @{@"oriURL" : @"ori_url",
  41. @"urlTitle" : @"url_title",
  42. @"urlTypePic" : @"url_type_pic",
  43. @"urlType" : @"url_type",
  44. @"shortURL" : @"short_url",
  45. @"actionLog" : @"actionlog",
  46. @"pageID" : @"page_id",
  47. @"storageType" : @"storage_type",
  48. @"picIds" : @"pic_ids",
  49. @"picInfos" : @"pic_infos"};
  50. }
  51. + (NSDictionary *)modelContainerPropertyGenericClass {
  52. return @{@"picIds" : [NSString class],
  53. @"picInfos" : [WBPicture class]};
  54. }
  55. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  56. // 自动 model-mapper 不能完成的,这里可以进行额外处理
  57. _pics = nil;
  58. if (_picIds.count != 0) {
  59. NSMutableArray *pics = [NSMutableArray new];
  60. for (NSString *picId in _picIds) {
  61. WBPicture *pic = _picInfos[picId];
  62. if (pic) {
  63. [pics addObject:pic];
  64. }
  65. }
  66. _pics = pics;
  67. }
  68. return YES;
  69. }
  70. @end
  71. @implementation WBTopic
  72. + (NSDictionary *)modelCustomPropertyMapper {
  73. return @{@"topicTitle" : @"topic_title",
  74. @"topicURL" : @"topic_url"};
  75. }
  76. @end
  77. @implementation WBTag
  78. + (NSDictionary *)modelCustomPropertyMapper {
  79. return @{@"tagHidden" : @"tag_hidden",
  80. @"tagName" : @"tag_name",
  81. @"tagScheme" : @"tag_scheme",
  82. @"tagType" : @"tag_type",
  83. @"urlTypePic" : @"url_type_pic"};
  84. }
  85. @end
  86. @implementation WBButtonLink
  87. @end
  88. @implementation WBPageInfo
  89. + (NSDictionary *)modelCustomPropertyMapper {
  90. return @{@"pageTitle" : @"page_title",
  91. @"pageID" : @"page_id",
  92. @"pageDesc" : @"page_desc",
  93. @"objectType" : @"object_type",
  94. @"objectID" : @"object_id",
  95. @"isAsyn" : @"is_asyn",
  96. @"pageURL" : @"page_url",
  97. @"pagePic" : @"page_pic",
  98. @"actStatus" : @"act_status",
  99. @"mediaInfo" : @"media_info",
  100. @"typeIcon" : @"type_icon"};
  101. }
  102. + (NSDictionary *)modelContainerPropertyGenericClass {
  103. return @{@"buttons" : [WBButtonLink class]};
  104. }
  105. @end
  106. @implementation WBStatusTitle
  107. + (NSDictionary *)modelCustomPropertyMapper {
  108. return @{@"baseColor" : @"base_color",
  109. @"iconURL" : @"icon_url"};
  110. }
  111. @end
  112. @implementation WBUser
  113. + (NSDictionary *)modelCustomPropertyMapper {
  114. return @{@"userID" : @"id",
  115. @"idString" : @"idstr",
  116. @"genderString" : @"gender",
  117. @"biFollowersCount" : @"bi_followers_count",
  118. @"profileImageURL" : @"profile_image_url",
  119. @"uclass" : @"class",
  120. @"verifiedContactEmail" : @"verified_contact_email",
  121. @"statusesCount" : @"statuses_count",
  122. @"geoEnabled" : @"geo_enabled",
  123. @"topicsCount" : @"topics_count",
  124. @"blockedCount" : @"blocked_count",
  125. @"followMe" : @"follow_me",
  126. @"coverImagePhone" : @"cover_image_phone",
  127. @"desc" : @"description",
  128. @"followersCount" : @"followers_count",
  129. @"verifiedContactMobile" : @"verified_contact_mobile",
  130. @"avatarLarge" : @"avatar_large",
  131. @"verifiedTrade" : @"verified_trade",
  132. @"profileURL" : @"profile_url",
  133. @"coverImage" : @"cover_image",
  134. @"onlineStatus" : @"online_status",
  135. @"badgeTop" : @"badge_top",
  136. @"verifiedContactName" : @"verified_contact_name",
  137. @"screenName" : @"screen_name",
  138. @"verifiedSourceURL" : @"verified_source_url",
  139. @"pagefriendsCount" : @"pagefriends_count",
  140. @"verifiedReason" : @"verified_reason",
  141. @"friendsCount" : @"friends_count",
  142. @"blockApp" : @"block_app",
  143. @"hasAbilityTag" : @"has_ability_tag",
  144. @"avatarHD" : @"avatar_hd",
  145. @"creditScore" : @"credit_score",
  146. @"createdAt" : @"created_at",
  147. @"blockWord" : @"block_word",
  148. @"allowAllActMsg" : @"allow_all_act_msg",
  149. @"verifiedState" : @"verified_state",
  150. @"verifiedReasonModified" : @"verified_reason_modified",
  151. @"allowAllComment" : @"allow_all_comment",
  152. @"verifiedLevel" : @"verified_level",
  153. @"verifiedReasonURL" : @"verified_reason_url",
  154. @"favouritesCount" : @"favourites_count",
  155. @"verifiedType" : @"verified_type",
  156. @"verifiedSource" : @"verified_source",
  157. @"userAbility" : @"user_ability"};
  158. }
  159. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  160. // 自动 model-mapper 不能完成的,这里可以进行额外处理
  161. _gender = 0;
  162. if ([_genderString isEqualToString:@"m"]) {
  163. _gender = 1;
  164. } else if ([_genderString isEqualToString:@"f"]) {
  165. _gender = 2;
  166. }
  167. // 这个不一定准。。
  168. if (_verified) {
  169. _userVerifyType = WBUserVerifyTypeStandard;
  170. } else if (_verifiedType == 220) {
  171. _userVerifyType = WBUserVerifyTypeClub;
  172. } else if (_verifiedType == -1 && _verifiedLevel == 3) {
  173. _userVerifyType = WBUserVerifyTypeOrganization;
  174. } else {
  175. _userVerifyType = WBUserVerifyTypeNone;
  176. }
  177. return YES;
  178. }
  179. @end
  180. @implementation WBStatus
  181. + (NSDictionary *)modelCustomPropertyMapper {
  182. return @{@"statusID" : @"id",
  183. @"createdAt" : @"created_at",
  184. @"attitudesStatus" : @"attitudes_status",
  185. @"inReplyToScreenName" : @"in_reply_to_screen_name",
  186. @"sourceType" : @"source_type",
  187. @"picBg" : @"pic_bg",
  188. @"commentsCount" : @"comments_count",
  189. @"thumbnailPic" : @"thumbnail_pic",
  190. @"recomState" : @"recom_state",
  191. @"sourceAllowClick" : @"source_allowclick",
  192. @"bizFeature" : @"biz_feature",
  193. @"retweetedStatus" : @"retweeted_status",
  194. @"mblogTypeName" : @"mblogtypename",
  195. @"urlStruct" : @"url_struct",
  196. @"topicStruct" : @"topic_struct",
  197. @"tagStruct" : @"tag_struct",
  198. @"pageInfo" : @"page_info",
  199. @"bmiddlePic" : @"bmiddle_pic",
  200. @"inReplyToStatusId" : @"in_reply_to_status_id",
  201. @"picIds" : @"pic_ids",
  202. @"repostsCount" : @"reposts_count",
  203. @"attitudesCount" : @"attitudes_count",
  204. @"darwinTags" : @"darwin_tags",
  205. @"userType" : @"userType",
  206. @"picInfos" : @"pic_infos",
  207. @"inReplyToUserId" : @"in_reply_to_user_id",
  208. @"originalPic" : @"original_pic"};
  209. }
  210. + (NSDictionary *)modelContainerPropertyGenericClass {
  211. return @{@"picIds" : [NSString class],
  212. @"picInfos" : [WBPicture class],
  213. @"urlStruct" : [WBURL class],
  214. @"topicStruct" : [WBTopic class],
  215. @"tagStruct" : [WBTag class]};
  216. }
  217. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  218. // 自动 model-mapper 不能完成的,这里可以进行额外处理
  219. _pics = nil;
  220. if (_picIds.count != 0) {
  221. NSMutableArray *pics = [NSMutableArray new];
  222. for (NSString *picId in _picIds) {
  223. WBPicture *pic = _picInfos[picId];
  224. if (pic) {
  225. [pics addObject:pic];
  226. }
  227. }
  228. _pics = pics;
  229. }
  230. if (_retweetedStatus) {
  231. if (_retweetedStatus.urlStruct.count == 0) {
  232. _retweetedStatus.urlStruct = _urlStruct;
  233. }
  234. if (_retweetedStatus.pageInfo == nil) {
  235. _retweetedStatus.pageInfo = _pageInfo;
  236. }
  237. }
  238. return YES;
  239. }
  240. @end
  241. @implementation WBTimelineItem
  242. + (NSDictionary *)modelCustomPropertyMapper {
  243. return @{@"hasVisible" : @"hasvisible",
  244. @"previousCursor" : @"previous_cursor",
  245. @"uveBlank" : @"uve_blank",
  246. @"hasUnread" : @"has_unread",
  247. @"totalNumber" : @"total_number",
  248. @"maxID" : @"max_id",
  249. @"sinceID" : @"since_id",
  250. @"nextCursor" : @"next_cursor"};
  251. }
  252. + (NSDictionary *)modelContainerPropertyGenericClass {
  253. return @{@"statuses" : [WBStatus class]};
  254. }
  255. @end
  256. @implementation WBEmoticon
  257. + (NSArray *)modelPropertyBlacklist {
  258. return @[@"group"];
  259. }
  260. @end
  261. @implementation WBEmoticonGroup
  262. + (NSDictionary *)modelCustomPropertyMapper {
  263. return @{@"groupID" : @"id",
  264. @"nameCN" : @"group_name_cn",
  265. @"nameEN" : @"group_name_en",
  266. @"nameTW" : @"group_name_tw",
  267. @"displayOnly" : @"display_only",
  268. @"groupType" : @"group_type"};
  269. }
  270. + (NSDictionary *)modelContainerPropertyGenericClass {
  271. return @{@"emoticons" : [WBEmoticon class]};
  272. }
  273. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
  274. [_emoticons enumerateObjectsUsingBlock:^(WBEmoticon *emoticon, NSUInteger idx, BOOL *stop) {
  275. emoticon.group = self;
  276. }];
  277. return YES;
  278. }
  279. @end