JSWeiboModel.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // JSWeiboModel.m
  3. // ModelBenchmark
  4. //
  5. // Created by ibireme on 15/9/18.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "JSWeiboModel.h"
  9. #import "DateFormatter.h"
  10. @implementation JSWeiboPictureMetadata
  11. + (JSONKeyMapper *)keyMapper {
  12. return [[JSONKeyMapper alloc] initWithDictionary:@{ @"cut_type" : @"cutType" }];
  13. }
  14. +(BOOL)propertyIsOptional:(NSString*)propertyName {
  15. return YES;
  16. }
  17. @end
  18. @implementation JSWeiboPicture
  19. + (JSONKeyMapper *)keyMapper {
  20. return [[JSONKeyMapper alloc] initWithDictionary:@{
  21. @"pic_id" : @"picID",
  22. @"keep_size" : @"keepSize",
  23. @"photo_tag" : @"photoTag",
  24. @"object_id" : @"objectID",
  25. @"middleplus" : @"middlePlus"
  26. }];
  27. }
  28. +(BOOL)propertyIsOptional:(NSString*)propertyName {
  29. return YES;
  30. }
  31. @end
  32. @implementation JSWeiboURL
  33. + (JSONKeyMapper *)keyMapper {
  34. return [[JSONKeyMapper alloc] initWithDictionary:@{
  35. @"ori_url" : @"oriURL",
  36. @"url_title" : @"urlTitle",
  37. @"url_type_pic" : @"urlTypePic",
  38. @"url_type" : @"urlType",
  39. @"short_url" : @"shortURL",
  40. @"actionlog" : @"actionLog",
  41. @"page_id" : @"pageID",
  42. @"storage_type" : @"storageType"
  43. }];
  44. }
  45. +(BOOL)propertyIsOptional:(NSString*)propertyName {
  46. return YES;
  47. }
  48. @end
  49. @implementation JSWeiboUser
  50. + (JSONKeyMapper *)keyMapper {
  51. return [[JSONKeyMapper alloc] initWithDictionary:@{
  52. @"id" : @"userID",
  53. @"idstr" : @"idString",
  54. @"gender" : @"genderString",
  55. @"bi_followers_count" : @"biFollowersCount",
  56. @"profile_image_url" : @"profileImageURL",
  57. @"class" : @"uclass",
  58. @"verified_contact_email" : @"verifiedContactEmail",
  59. @"statuses_count" : @"statusesCount",
  60. @"geo_enabled" : @"geoEnabled",
  61. @"follow_me" : @"followMe",
  62. @"cover_image_phone" : @"coverImagePhone",
  63. @"description" : @"desc",
  64. @"followers_count" : @"followersCount",
  65. @"verified_contact_mobile" : @"verifiedContactMobile",
  66. @"avatar_large" : @"avatarLarge",
  67. @"verified_trade" : @"verifiedTrade",
  68. @"profile_url" : @"profileURL",
  69. @"cover_image" : @"coverImage",
  70. @"online_status" : @"onlineStatus",
  71. @"badge_top" : @"badgeTop",
  72. @"verified_contact_name" : @"verifiedContactName",
  73. @"screen_name" : @"screenName",
  74. @"verified_source_url" : @"verifiedSourceURL",
  75. @"pagefriends_count" : @"pagefriendsCount",
  76. @"vverified_reason" : @"erifiedReason",
  77. @"friends_count" : @"friendsCount",
  78. @"block_app" : @"blockApp",
  79. @"has_ability_tag" : @"hasAbilityTag",
  80. @"avatar_hd" : @"avatarHD",
  81. @"credit_score" : @"creditScore",
  82. @"created_at" : @"createdAt",
  83. @"block_word" : @"blockWord",
  84. @"allow_all_act_msg" : @"allowAllActMsg",
  85. @"verified_state" : @"verifiedState",
  86. @"verified_reason_modified" : @"verifiedReasonModified",
  87. @"allow_all_comment" : @"allowAllComment",
  88. @"verified_level" : @"verifiedLevel",
  89. @"verified_reason_url" : @"verifiedReasonURL",
  90. @"favourites_count" : @"favouritesCount",
  91. @"verified_type" : @"verifiedType",
  92. @"verified_source" : @"verifiedSource",
  93. @"user_ability" : @"userAbility"}];
  94. }
  95. +(BOOL)propertyIsOptional:(NSString*)propertyName {
  96. return YES;
  97. }
  98. @end
  99. @implementation JSWeiboStatus
  100. + (JSONKeyMapper *)keyMapper {
  101. return [[JSONKeyMapper alloc] initWithDictionary:@{
  102. @"id" : @"statusID",
  103. @"created_at" : @"createdAt",
  104. @"attitudes_status" : @"attitudesStatus",
  105. @"in_reply_to_screen_name" : @"inReplyToScreenName",
  106. @"source_type" : @"sourceType",
  107. @"comments_count" : @"commentsCount",
  108. @"recom_state" : @"recomState",
  109. @"source_allowclick" : @"sourceAllowClick",
  110. @"biz_feature" : @"bizFeature",
  111. @"mblogtypename" : @"mblogTypeName",
  112. @"url_struct" : @"urlStruct",
  113. @"mblogtype" : @"mblogType",
  114. @"in_reply_to_status_id" : @"inReplyToStatusId",
  115. @"pic_ids" : @"picIds",
  116. @"reposts_count" : @"repostsCount",
  117. @"attitudes_count" : @"attitudesCount",
  118. @"darwin_tags" : @"darwinTags",
  119. @"userType" : @"userType",
  120. @"pic_infos" : @"picInfos",
  121. @"in_reply_to_user_id" : @"inReplyToUserId"
  122. }];
  123. }
  124. +(BOOL)propertyIsOptional:(NSString*)propertyName {
  125. return YES;
  126. }
  127. @end
  128. /**
  129. JSONModel use a global transformer to transform value...
  130. But how to create a custom transformer for a specified model ?!!!!
  131. */
  132. @interface JSONValueTransformer(CustomDate)
  133. -(NSDate*)__NSDateFromNSString:(NSString*)string;
  134. @end
  135. #pragma clang diagnostic push
  136. #pragma clang diagnostic ignored "-Wincomplete-implementation"
  137. @implementation JSONValueTransformer (CustomDate)
  138. - (NSDate *)NSDateFromNSString:(NSString *)string {
  139. if (string.length == 30) {
  140. return [[DateFormatter weiboDataFormatter] dateFromString:string];
  141. } else {
  142. return [self __NSDateFromNSString:string];
  143. }
  144. }
  145. @end
  146. #pragma clang diagnostic pop