JSWeiboModel.m 5.3 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] initWithModelToJSONDictionary:@{ @"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] initWithModelToJSONDictionary:@{
  21. @"url" : @"url",
  22. @"width" : @"width",
  23. @"height" : @"height",
  24. @"type" : @"type",
  25. @"cutType" : @"cut_type"
  26. }];
  27. }
  28. +(BOOL)propertyIsOptional:(NSString*)propertyName {
  29. return YES;
  30. }
  31. @end
  32. @implementation JSWeiboURL
  33. + (JSONKeyMapper *)keyMapper {
  34. return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
  35. @"oriURL" : @"ori_url",
  36. @"urlTitle" : @"url_title",
  37. @"urlTypePic" : @"url_type_pic",
  38. @"urlType" : @"url_type",
  39. @"shortURL" : @"short_url",
  40. @"actionLog" : @"actionlog",
  41. @"pageID" : @"page_id",
  42. @"storageType" : @"storage_type"
  43. }];
  44. }
  45. +(BOOL)propertyIsOptional:(NSString*)propertyName {
  46. return YES;
  47. }
  48. @end
  49. @implementation JSWeiboUser
  50. + (JSONKeyMapper *)keyMapper {
  51. return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
  52. @"userID" : @"id",
  53. @"idString" : @"idstr",
  54. @"genderString" : @"gender",
  55. @"biFollowersCount" : @"bi_followers_count",
  56. @"profileImageURL" : @"profile_image_url",
  57. @"uclass" : @"class",
  58. @"verifiedContactEmail" : @"verified_contact_email",
  59. @"statusesCount" : @"statuses_count",
  60. @"geoEnabled" : @"geo_enabled",
  61. @"followMe" : @"follow_me",
  62. @"coverImagePhone" : @"cover_image_phone",
  63. @"desc" : @"description",
  64. @"followersCount" : @"followers_count",
  65. @"verifiedContactMobile" : @"verified_contact_mobile",
  66. @"avatarLarge" : @"avatar_large",
  67. @"verifiedTrade" : @"verified_trade",
  68. @"profileURL" : @"profile_url",
  69. @"coverImage" : @"cover_image",
  70. @"onlineStatus" : @"online_status",
  71. @"badgeTop" : @"badge_top",
  72. @"verifiedContactName" : @"verified_contact_name",
  73. @"screenName" : @"screen_name",
  74. @"verifiedSourceURL" : @"verified_source_url",
  75. @"pagefriendsCount" : @"pagefriends_count",
  76. @"verifiedReason" : @"verified_reason",
  77. @"friendsCount" : @"friends_count",
  78. @"blockApp" : @"block_app",
  79. @"hasAbilityTag" : @"has_ability_tag",
  80. @"avatarHD" : @"avatar_hd",
  81. @"creditScore" : @"credit_score",
  82. @"createdAt" : @"created_at",
  83. @"blockWord" : @"block_word",
  84. @"allowAllActMsg" : @"allow_all_act_msg",
  85. @"verifiedState" : @"verified_state",
  86. @"verifiedReasonModified" : @"verified_reason_modified",
  87. @"allowAllComment" : @"allow_all_comment",
  88. @"verifiedLevel" : @"verified_level",
  89. @"verifiedReasonURL" : @"verified_reason_url",
  90. @"favouritesCount" : @"favourites_count",
  91. @"verifiedType" : @"verified_type",
  92. @"verifiedSource" : @"verified_source",
  93. @"userAbility" : @"user_ability"}];
  94. }
  95. +(BOOL)propertyIsOptional:(NSString*)propertyName {
  96. return YES;
  97. }
  98. @end
  99. @implementation JSWeiboStatus
  100. + (JSONKeyMapper *)keyMapper {
  101. return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
  102. @"statusID" : @"id",
  103. @"createdAt" : @"created_at",
  104. @"attitudesStatus" : @"attitudes_status",
  105. @"inReplyToScreenName" : @"in_reply_to_screen_name",
  106. @"sourceType" : @"source_type",
  107. @"commentsCount" : @"comments_count",
  108. @"urlStruct" : @"url_struct",
  109. @"recomState" : @"recom_state",
  110. @"sourceAllowClick" : @"source_allowclick",
  111. @"bizFeature" : @"biz_feature",
  112. @"mblogTypeName" : @"mblogtypename",
  113. @"mblogType" : @"mblogtype",
  114. @"inReplyToStatusId" : @"in_reply_to_status_id",
  115. @"picIds" : @"pic_ids",
  116. @"repostsCount" : @"reposts_count",
  117. @"attitudesCount" : @"attitudes_count",
  118. @"darwinTags" : @"darwin_tags",
  119. @"userType" : @"userType",
  120. @"picInfos" : @"pic_infos",
  121. @"inReplyToUserId" : @"in_reply_to_user_id"
  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