GitHubUser.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. //
  2. // GitHubUser.m
  3. // ModelBenchmark
  4. //
  5. // Created by ibireme on 15/9/18.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "GitHubUser.h"
  9. #import "DateFormatter.h"
  10. @implementation GHUser
  11. #define GHUSER_MANUALLY_SETTER_LIST \
  12. SET_STR(_login, @"login"); \
  13. SET_NUM(_userID, @"id"); \
  14. SET_STR(_avatarURL, @"avatar_url"); \
  15. SET_STR(_gravatarID, @"gravatar_id"); \
  16. SET_STR(_url, @"url"); \
  17. SET_STR(_htmlURL, @"html_url"); \
  18. SET_STR(_followersURL, @"followers_url"); \
  19. SET_STR(_followingURL, @"following_url"); \
  20. SET_STR(_gistsURL, @"gists_url"); \
  21. SET_STR(_starredURL,@"starred_url"); \
  22. SET_STR(_subscriptionsURL, @"subscriptions_url"); \
  23. SET_STR(_organizationsURL, @"organizations_url"); \
  24. SET_STR(_reposURL, @"repos_url"); \
  25. SET_STR(_eventsURL, @"events_url"); \
  26. SET_STR(_receivedEventsURL, @"received_events_url"); \
  27. SET_STR(_type, @"type"); \
  28. SET_NUM(_siteAdmin, @"site_admin"); \
  29. SET_STR(_name, @"name"); \
  30. SET_STR(_company, @"company"); \
  31. SET_STR(_blog, @"blog"); \
  32. SET_STR(_location, @"location"); \
  33. SET_STR(_email, @"email"); \
  34. SET_STR(_hireable, @"hireable"); \
  35. SET_STR(_bio, @"bio"); \
  36. SET_NUM(_publicRepos, @"public_repos"); \
  37. SET_NUM(_publicGists, @"public_gists"); \
  38. SET_NUM(_followers, @"followers"); \
  39. SET_NUM(_following, @"following");
  40. - (instancetype)initWithJSONDictionary:(NSDictionary *)dic {
  41. self = [super init];
  42. if (![dic isKindOfClass:[NSDictionary class]]) return nil;
  43. NSString *str;
  44. NSNumber *num;
  45. #define SET_STR(_IVAR_, _JSON_KEY_) \
  46. str = dic[_JSON_KEY_]; \
  47. if ([str isKindOfClass:[NSString class]]) _IVAR_ = str;
  48. #define SET_NUM(_IVAR_, _JSON_KEY_) \
  49. num = dic[_JSON_KEY_]; \
  50. if ([num isKindOfClass:[NSNumber class]]) _IVAR_ = num.unsignedIntValue;
  51. GHUSER_MANUALLY_SETTER_LIST
  52. #undef SET_STR
  53. #undef SET_NUM
  54. return self;
  55. }
  56. - (NSDictionary *)convertToJSONDictionary {
  57. NSMutableDictionary *dic = [NSMutableDictionary new];
  58. #define SET_STR(_IVAR_, _JSON_KEY_) \
  59. if (_IVAR_) dic[_JSON_KEY_] = _IVAR_;
  60. #define SET_NUM(_IVAR_, _JSON_KEY_) \
  61. dic[_JSON_KEY_] = @(_IVAR_);
  62. GHUSER_MANUALLY_SETTER_LIST
  63. #undef SET_STR
  64. #undef SET_NUM
  65. return dic;
  66. }
  67. - (void)encodeWithCoder:(NSCoder *)aCoder {
  68. if (!aCoder) return;
  69. #define SET_STR(_IVAR_, _JSON_KEY_) \
  70. [aCoder encodeObject:_IVAR_ forKey:(__bridge NSString *)CFSTR(#_IVAR_)];
  71. #define SET_NUM(_IVAR_, _JSON_KEY_) \
  72. [aCoder encodeObject:@(_IVAR_) forKey:(__bridge NSString *)CFSTR(#_IVAR_)];
  73. GHUSER_MANUALLY_SETTER_LIST
  74. #undef SET_STR
  75. #undef SET_NUM
  76. }
  77. - (id)initWithCoder:(NSCoder *)aDecoder {
  78. self = [self init];
  79. if (!self) return nil;
  80. #define SET_STR(_IVAR_, _JSON_KEY_) \
  81. _IVAR_ = [aDecoder decodeObjectForKey:(__bridge NSString *)CFSTR(#_IVAR_)];
  82. #define SET_NUM(_IVAR_, _JSON_KEY_) \
  83. _IVAR_ = ((NSNumber *)[aDecoder decodeObjectForKey:(__bridge NSString *)CFSTR(#_IVAR_)]).unsignedIntValue;
  84. GHUSER_MANUALLY_SETTER_LIST
  85. #undef SET_STR
  86. #undef SET_NUM
  87. return self;
  88. }
  89. #undef GHUSER_MANUALLY_SETTER_LIST
  90. @end
  91. @implementation YYGHUser
  92. + (NSDictionary *)modelCustomPropertyMapper {
  93. return @{
  94. @"userID" : @"id",
  95. @"avatarURL" : @"avatar_url",
  96. @"gravatarID" : @"gravatar_id",
  97. @"htmlURL" : @"html_url",
  98. @"followersURL" : @"followers_url",
  99. @"followingURL" : @"following_url",
  100. @"gistsURL" : @"gists_url",
  101. @"starredURL" : @"starred_url",
  102. @"subscriptionsURL" : @"subscriptions_url",
  103. @"organizationsURL" : @"organizations_url",
  104. @"reposURL" : @"repos_url",
  105. @"eventsURL" : @"events_url",
  106. @"receivedEventsURL" : @"received_events_url",
  107. @"siteAdmin" : @"site_admin",
  108. @"publicRepos" : @"public_repos",
  109. @"publicGists" : @"public_gists",
  110. @"createdAt" : @"created_at",
  111. @"updatedAt" : @"updated_at",
  112. };
  113. }
  114. - (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
  115. - (id)initWithCoder:(NSCoder *)aDecoder { return [self yy_modelInitWithCoder:aDecoder]; }
  116. @end
  117. @implementation JSGHUser
  118. + (JSONKeyMapper *)keyMapper {
  119. return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
  120. @"userID" : @"id",
  121. @"avatarURL" : @"avatar_url",
  122. @"gravatarID" : @"gravatar_id",
  123. @"htmlURL" : @"html_url",
  124. @"followersURL" : @"followers_url",
  125. @"followingURL" : @"following_url",
  126. @"gistsURL" : @"gists_url",
  127. @"starredURL" : @"starred_url",
  128. @"subscriptionsURL" : @"subscriptions_url",
  129. @"organizationsURL" : @"organizations_url",
  130. @"reposURL" : @"repos_url",
  131. @"eventsURL" : @"events_url",
  132. @"receivedEventsURL" : @"received_events_url",
  133. @"siteAdmin" : @"site_admin",
  134. @"publicRepos" : @"public_repos",
  135. @"publicGists" : @"public_gists",
  136. @"createdAt" : @"created_at",
  137. @"updatedAt" : @"updated_at",
  138. }];
  139. }
  140. + (BOOL)propertyIsOptional:(NSString *)propertyName {
  141. return YES;
  142. }
  143. @end
  144. @implementation MTGHUser
  145. + (NSDictionary *)JSONKeyPathsByPropertyKey {
  146. return @{
  147. @"login" : @"login",
  148. @"userID" : @"id",
  149. @"avatarURL" : @"avatar_url",
  150. @"gravatarID" : @"gravatar_id",
  151. @"url" : @"url",
  152. @"htmlURL" : @"html_url",
  153. @"followersURL" : @"followers_url",
  154. @"followingURL" : @"following_url",
  155. @"gistsURL" : @"gists_url",
  156. @"starredURL" : @"starred_url",
  157. @"subscriptionsURL" : @"subscriptions_url",
  158. @"organizationsURL" : @"organizations_url",
  159. @"reposURL" : @"repos_url",
  160. @"eventsURL" : @"events_url",
  161. @"receivedEventsURL" : @"received_events_url",
  162. @"type" : @"type",
  163. @"siteAdmin" : @"site_admin",
  164. @"name" : @"name",
  165. @"company" : @"company",
  166. @"blog" : @"blog",
  167. @"location" : @"location",
  168. @"email" : @"email",
  169. @"hireable" : @"hireable",
  170. @"bio" : @"bio",
  171. @"publicRepos" : @"public_repos",
  172. @"publicGists" : @"public_gists",
  173. @"followers" : @"followers",
  174. @"following" : @"following",
  175. @"createdAt" : @"created_at",
  176. @"updatedAt" : @"updated_at",
  177. @"test" : @"test"
  178. };
  179. }
  180. @end
  181. @implementation FEGHUser
  182. + (FEMMapping *)defaultMapping {
  183. FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"FEGHUser"];
  184. [mapping addAttributesFromDictionary:@{
  185. @"login" : @"login",
  186. @"userID" : @"id",
  187. @"avatarURL" : @"avatar_url",
  188. @"gravatarID" : @"gravatar_id",
  189. @"url" : @"url",
  190. @"htmlURL" : @"html_url",
  191. @"followersURL" : @"followers_url",
  192. @"followingURL" : @"following_url",
  193. @"gistsURL" : @"gists_url",
  194. @"starredURL" : @"starred_url",
  195. @"subscriptionsURL" : @"subscriptions_url",
  196. @"organizationsURL" : @"organizations_url",
  197. @"reposURL" : @"repos_url",
  198. @"eventsURL" : @"events_url",
  199. @"receivedEventsURL" : @"received_events_url",
  200. @"type" : @"type",
  201. @"siteAdmin" : @"site_admin",
  202. @"name" : @"name",
  203. @"company" : @"company",
  204. @"blog" : @"blog",
  205. @"location" : @"location",
  206. @"email" : @"email",
  207. @"hireable" : @"hireable",
  208. @"bio" : @"bio",
  209. @"publicRepos" : @"public_repos",
  210. @"publicGists" : @"public_gists",
  211. @"followers" : @"followers",
  212. @"following" : @"following",
  213. @"createdAt" : @"created_at",
  214. @"updatedAt" : @"updated_at",
  215. @"test" : @"test"
  216. }];
  217. return mapping;
  218. }
  219. @end
  220. @implementation MJGHUser
  221. + (NSDictionary *)mj_replacedKeyFromPropertyName {
  222. return @{
  223. @"userID" : @"id",
  224. @"avatarURL" : @"avatar_url",
  225. @"gravatarID" : @"gravatar_id",
  226. @"htmlURL" : @"html_url",
  227. @"followersURL" : @"followers_url",
  228. @"followingURL" : @"following_url",
  229. @"gistsURL" : @"gists_url",
  230. @"starredURL" : @"starred_url",
  231. @"subscriptionsURL" : @"subscriptions_url",
  232. @"organizationsURL" : @"organizations_url",
  233. @"reposURL" : @"repos_url",
  234. @"eventsURL" : @"events_url",
  235. @"receivedEventsURL" : @"received_events_url",
  236. @"siteAdmin" : @"site_admin",
  237. @"publicRepos" : @"public_repos",
  238. @"publicGists" : @"public_gists",
  239. @"createdAt" : @"created_at",
  240. @"updatedAt" : @"updated_at",
  241. };
  242. }
  243. MJExtensionCodingImplementation
  244. @end