MJWeiboModel.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // MJWeiboModel.m
  3. // ModelBenchmark
  4. //
  5. // Created by ibireme on 15/9/18.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "MJWeiboModel.h"
  9. #import "DateFormatter.h"
  10. @implementation MJWeiboPictureMetadata
  11. MJExtensionCodingImplementation
  12. + (NSDictionary *)replacedKeyFromPropertyName {
  13. return @{@"cutType" : @"cut_type"};
  14. }
  15. @end
  16. @implementation MJWeiboPicture
  17. MJExtensionCodingImplementation
  18. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  19. return @{@"picID" : @"pic_id",
  20. @"keepSize" : @"keep_size",
  21. @"photoTag" : @"photo_tag",
  22. @"objectID" : @"object_id",
  23. @"middlePlus" : @"middleplus"};
  24. }
  25. @end
  26. @implementation MJWeiboURL
  27. MJExtensionCodingImplementation
  28. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  29. return @{@"oriURL" : @"ori_url",
  30. @"urlTitle" : @"url_title",
  31. @"urlTypePic" : @"url_type_pic",
  32. @"urlType" : @"url_type",
  33. @"shortURL" : @"short_url",
  34. @"actionLog" : @"actionlog",
  35. @"pageID" : @"page_id",
  36. @"storageType" : @"storage_type"};
  37. }
  38. @end
  39. @implementation MJWeiboUser
  40. MJExtensionCodingImplementation
  41. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  42. return @{@"userID" : @"id",
  43. @"idString" : @"idstr",
  44. @"genderString" : @"gender",
  45. @"biFollowersCount" : @"bi_followers_count",
  46. @"profileImageURL" : @"profile_image_url",
  47. @"uclass" : @"class",
  48. @"verifiedContactEmail" : @"verified_contact_email",
  49. @"statusesCount" : @"statuses_count",
  50. @"geoEnabled" : @"geo_enabled",
  51. @"followMe" : @"follow_me",
  52. @"coverImagePhone" : @"cover_image_phone",
  53. @"desc" : @"description",
  54. @"followersCount" : @"followers_count",
  55. @"verifiedContactMobile" : @"verified_contact_mobile",
  56. @"avatarLarge" : @"avatar_large",
  57. @"verifiedTrade" : @"verified_trade",
  58. @"profileURL" : @"profile_url",
  59. @"coverImage" : @"cover_image",
  60. @"onlineStatus" : @"online_status",
  61. @"badgeTop" : @"badge_top",
  62. @"verifiedContactName" : @"verified_contact_name",
  63. @"screenName" : @"screen_name",
  64. @"verifiedSourceURL" : @"verified_source_url",
  65. @"pagefriendsCount" : @"pagefriends_count",
  66. @"verifiedReason" : @"verified_reason",
  67. @"friendsCount" : @"friends_count",
  68. @"blockApp" : @"block_app",
  69. @"hasAbilityTag" : @"has_ability_tag",
  70. @"avatarHD" : @"avatar_hd",
  71. @"creditScore" : @"credit_score",
  72. @"createdAt" : @"created_at",
  73. @"blockWord" : @"block_word",
  74. @"allowAllActMsg" : @"allow_all_act_msg",
  75. @"verifiedState" : @"verified_state",
  76. @"verifiedReasonModified" : @"verified_reason_modified",
  77. @"allowAllComment" : @"allow_all_comment",
  78. @"verifiedLevel" : @"verified_level",
  79. @"verifiedReasonURL" : @"verified_reason_url",
  80. @"favouritesCount" : @"favourites_count",
  81. @"verifiedType" : @"verified_type",
  82. @"verifiedSource" : @"verified_source",
  83. @"userAbility" : @"user_ability"};
  84. }
  85. - (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property {
  86. if ([property.name isEqualToString:@"createdAt"]) {
  87. return [[DateFormatter weiboDataFormatter] dateFromString:oldValue];
  88. }
  89. return oldValue;
  90. }
  91. @end
  92. @implementation MJWeiboStatus
  93. MJExtensionCodingImplementation
  94. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  95. return @{@"statusID" : @"id",
  96. @"createdAt" : @"created_at",
  97. @"attitudesStatus" : @"attitudes_status",
  98. @"inReplyToScreenName" : @"in_reply_to_screen_name",
  99. @"sourceType" : @"source_type",
  100. @"commentsCount" : @"comments_count",
  101. @"urlStruct" : @"url_struct",
  102. @"recomState" : @"recom_state",
  103. @"sourceAllowClick" : @"source_allowclick",
  104. @"bizFeature" : @"biz_feature",
  105. @"mblogTypeName" : @"mblogtypename",
  106. @"mblogType" : @"mblogtype",
  107. @"inReplyToStatusId" : @"in_reply_to_status_id",
  108. @"picIds" : @"pic_ids",
  109. @"repostsCount" : @"reposts_count",
  110. @"attitudesCount" : @"attitudes_count",
  111. @"darwinTags" : @"darwin_tags",
  112. @"userType" : @"userType",
  113. @"picInfos" : @"pic_infos",
  114. @"inReplyToUserId" : @"in_reply_to_user_id"};
  115. }
  116. + (NSDictionary *)mj_objectClassInArray {
  117. return @{@"picIds" : @"NSString",
  118. @"urlStruct" : @"MJWeiboURL"};
  119. }
  120. - (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property {
  121. if ([property.name isEqualToString:@"createdAt"]) {
  122. if ([oldValue isKindOfClass:[NSString class]]) {
  123. return [[DateFormatter weiboDataFormatter] dateFromString:oldValue];
  124. }
  125. return nil;
  126. } else if ([property.name isEqualToString:@"picInfos"]) {
  127. if (!oldValue || oldValue == [NSNull null]) return nil;
  128. if (![oldValue isKindOfClass:[NSDictionary class]]) return nil;
  129. NSMutableDictionary *pics = [NSMutableDictionary new];
  130. [((NSDictionary *)oldValue) enumerateKeysAndObjectsUsingBlock:^(id key, NSDictionary *obj, BOOL *stop) {
  131. if ([obj isKindOfClass:[NSDictionary class]]) {
  132. MJWeiboPicture *pic = [MJWeiboPicture mj_objectWithKeyValues:obj];
  133. if (pic) pics[key] = pic;
  134. }
  135. }];
  136. return pics;
  137. }
  138. return oldValue;
  139. }
  140. @end