diff options
author | Vitaly Takmazov | 2017-12-09 23:47:30 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-12-09 23:47:30 +0300 |
commit | a38541e14ecfea8e37c80755fb3b2ef25cd81272 (patch) | |
tree | 3b26f5e4f86a4eb103193535abf7f9b15e0e67e6 /Juick/APIClient.m | |
parent | e2ac87809468e9487389e5d22ab9766996898478 (diff) |
working post/reply
Diffstat (limited to 'Juick/APIClient.m')
-rw-r--r-- | Juick/APIClient.m | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index abefa40..ecaf536 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -57,6 +57,26 @@ }]; } +-(void) postMessage:(NSString *)text result:(void (^)(Message *, NSError *))callback { + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; + [self.backgroundQueue addOperationWithBlock:^{ + [manager POST:@"/post" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { + [formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"]; + } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + NSLog(@"Success!"); + Message *result = [Message yy_modelWithJSON:responseObject]; + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(result, nil); + }]; + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"Error: %@", [error localizedDescription]); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(nil, error); + }]; + }]; + }]; +} + -(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text result:(void(^)(Message *, NSError *))callback { AFHTTPSessionManager *manager = [APIClient sharedClient].manager; [self.backgroundQueue addOperationWithBlock:^{ |