From a38541e14ecfea8e37c80755fb3b2ef25cd81272 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 9 Dec 2017 23:47:30 +0300 Subject: working post/reply --- Juick/APIClient.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Juick/APIClient.m') 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 _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:^{ -- cgit v1.2.3