summaryrefslogtreecommitdiff
path: root/Juick/Model
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-12-02 23:23:31 +0300
committerGravatar Vitaly Takmazov2018-12-02 23:23:31 +0300
commita293a8e049fea49b8c2b8262fb92a29f73d66989 (patch)
tree2201a139fc19fcac59714e915f08b0aa7e816517 /Juick/Model
parent3bc3a38be7ccaf9622bdc86ffac37827af36f0f1 (diff)
Drop YYModel
Diffstat (limited to 'Juick/Model')
-rw-r--r--Juick/Model/Attachment.h2
-rw-r--r--Juick/Model/Attachment.m17
-rw-r--r--Juick/Model/Chat.h3
-rw-r--r--Juick/Model/Chat.m11
-rw-r--r--Juick/Model/DeviceRegistration.h8
-rw-r--r--Juick/Model/Entity.h2
-rw-r--r--Juick/Model/Entity.m10
-rw-r--r--Juick/Model/Message.h2
-rw-r--r--Juick/Model/Message.m24
-rw-r--r--Juick/Model/User.h2
-rw-r--r--Juick/Model/User.m10
11 files changed, 85 insertions, 6 deletions
diff --git a/Juick/Model/Attachment.h b/Juick/Model/Attachment.h
index 26fc1c0..47c6c3a 100644
--- a/Juick/Model/Attachment.h
+++ b/Juick/Model/Attachment.h
@@ -15,4 +15,6 @@
@property(nonatomic, strong) Attachment *small;
@property(nonatomic, strong) Attachment *medium;
@property(nonatomic, strong) Attachment *thumbnail;
+
++(Attachment *) fromJSON:(NSDictionary *)jsonData;
@end
diff --git a/Juick/Model/Attachment.m b/Juick/Model/Attachment.m
index a54e462..006b72e 100644
--- a/Juick/Model/Attachment.m
+++ b/Juick/Model/Attachment.m
@@ -10,4 +10,21 @@
@implementation Attachment
++(Attachment *) fromJSON:(NSDictionary *)jsonData {
+ Attachment *attachment = [Attachment new];
+ attachment.url = jsonData[@"url"];
+ attachment.width = jsonData[@"width"];
+ attachment.height = jsonData[@"height"];
+ if (jsonData[@"small"]) {
+ attachment.small = [Attachment fromJSON:jsonData[@"small"]];
+ }
+ if (jsonData[@"medium"]) {
+ attachment.medium = [Attachment fromJSON:jsonData[@"medium"]];
+ }
+ if (jsonData[@"thumbnail"]) {
+ attachment.thumbnail = [Attachment fromJSON:jsonData[@"thumbnail"]];
+ }
+ return attachment;
+}
+
@end
diff --git a/Juick/Model/Chat.h b/Juick/Model/Chat.h
index 1e80bdf..4b7ec30 100644
--- a/Juick/Model/Chat.h
+++ b/Juick/Model/Chat.h
@@ -17,4 +17,7 @@
@property NSNumber *unreadCount;
@property NSDate *lastMessageTimestamp;
@property NSString *lastMessageText;
+
++ (Chat *) fromJSON:(NSDictionary *)jsonData;
+
@end
diff --git a/Juick/Model/Chat.m b/Juick/Model/Chat.m
index ff5fb83..66ed394 100644
--- a/Juick/Model/Chat.m
+++ b/Juick/Model/Chat.m
@@ -10,4 +10,15 @@
@implementation Chat
++(Chat *) fromJSON:(NSDictionary *)jsonData {
+ Chat *user = [Chat new];
+ user.uid = jsonData[@"uid"];
+ user.uname = jsonData[@"uname"];
+ user.avatar = jsonData[@"avatar"];
+ user.unreadCount = jsonData[@"unreadCount"];
+ user.lastMessageTimestamp = jsonData[@"lastMessageTimestamp"];
+ user.lastMessageText = jsonData[@"lastMessageText"];
+ return user;
+}
+
@end
diff --git a/Juick/Model/DeviceRegistration.h b/Juick/Model/DeviceRegistration.h
index e629637..d5b620c 100644
--- a/Juick/Model/DeviceRegistration.h
+++ b/Juick/Model/DeviceRegistration.h
@@ -11,7 +11,15 @@
@interface DeviceRegistration : NSObject
@property NSString *type;
@property NSString *token;
+
+-(NSDictionary *) toJSON;
@end
@implementation DeviceRegistration
+-(NSDictionary *) toJSON {
+ return @{
+ @"type": self.type,
+ @"token": self.token
+ };
+}
@end
diff --git a/Juick/Model/Entity.h b/Juick/Model/Entity.h
index 13142f1..4cdffc0 100644
--- a/Juick/Model/Entity.h
+++ b/Juick/Model/Entity.h
@@ -16,4 +16,6 @@
@property NSNumber *start;
@property NSNumber *end;
++(Entity *) fromJSON:(NSDictionary *)jsonData;
+
@end
diff --git a/Juick/Model/Entity.m b/Juick/Model/Entity.m
index ac53a1f..cf23a2a 100644
--- a/Juick/Model/Entity.m
+++ b/Juick/Model/Entity.m
@@ -10,4 +10,14 @@
@implementation Entity
++(Entity *) fromJSON:(NSDictionary *)jsonData {
+ Entity *entity = [Entity new];
+ entity.start = jsonData[@"start"];
+ entity.end = jsonData[@"end"];
+ entity.type = jsonData[@"type"];
+ entity.text = jsonData[@"text"];
+ entity.link = jsonData[@"url"];
+ return entity;
+}
+
@end
diff --git a/Juick/Model/Message.h b/Juick/Model/Message.h
index 8e1b01a..f822fdf 100644
--- a/Juick/Model/Message.h
+++ b/Juick/Model/Message.h
@@ -26,4 +26,6 @@
@property Attachment *attachment;
@property BOOL service;
++(Message *) fromJSON:(NSDictionary *)jsonData;
+
@end
diff --git a/Juick/Model/Message.m b/Juick/Model/Message.m
index d00f705..68cc7c9 100644
--- a/Juick/Model/Message.m
+++ b/Juick/Model/Message.m
@@ -11,10 +11,24 @@
@implementation Message
-+ (NSDictionary *)modelCustomPropertyMapper {
- return @{@"text" : @"body",
- @"attach" : @"photo.small",
- @"repliesCount": @"replies",
- @"repliesBy": @"repliesby"};
++ (Message *) fromJSON:(NSDictionary *)jsonData {
+ Message * message = [Message new];
+ message.mid = jsonData[@"mid"];
+ message.rid = jsonData[@"rid"];
+ message.text = jsonData[@"body"];
+ message.attach = jsonData[@"photo"][@"small"];
+ message.repliesCount = jsonData[@"replies"];
+ message.repliesBy = jsonData[@"repliesby"];
+ message.user = [User fromJSON:jsonData[@"user"]];
+ message.timestamp = jsonData[@"timestamp"];
+ message.service = jsonData[@"service"];
+ message.tags = jsonData[@"tags"];
+ NSMutableArray *entitiesArray = [NSMutableArray new];
+ for (NSDictionary *entityData in jsonData[@"entities"]) {
+ [entitiesArray addObject:[Entity fromJSON:entityData]];
+ }
+ message.entities = [entitiesArray copy];
+ message.attachment = [Attachment fromJSON:jsonData[@"attachment"]];
+ return message;
}
@end
diff --git a/Juick/Model/User.h b/Juick/Model/User.h
index 8120dec..59b010d 100644
--- a/Juick/Model/User.h
+++ b/Juick/Model/User.h
@@ -13,6 +13,8 @@
@property (nonatomic, strong) NSString *uid;
@property (nonatomic, strong) NSString *avatar;
++ (User *) fromJSON:(NSDictionary *)jsonData;
+
+ (void) get:(NSString *)name callback:(void(^)(User *))callback;
+ (BOOL) isAuthenticated;
diff --git a/Juick/Model/User.m b/Juick/Model/User.m
index 36a9b4c..a2f874c 100644
--- a/Juick/Model/User.m
+++ b/Juick/Model/User.m
@@ -11,6 +11,14 @@
@implementation User
++ (User *) fromJSON:(NSDictionary *)jsonData {
+ User *user = [User new];
+ user.uid = jsonData[@"uid"];
+ user.uname = jsonData[@"uname"];
+ user.avatar = jsonData[@"avatar"];
+ return user;
+}
+
+(BOOL) isAuthenticated {
return [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] != nil;
}
@@ -46,7 +54,7 @@
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:name, @"uname", nil];
[manager GET:@"users" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- callback([User yy_modelWithJSON:[(NSArray *)responseObject firstObject]]);
+ callback([User fromJSON:[(NSArray *)responseObject firstObject]]);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
callback(nil);
}];