diff options
author | Vitaly Takmazov | 2018-04-08 23:17:47 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-04-08 23:17:47 +0300 |
commit | f6fed5b2374c7d847c68efccce363f9513aa2efb (patch) | |
tree | 74021a451bd5cfb1df1a7771a32dbc121a7163c6 /Juick/APIClient.m | |
parent | 6f8855ce3b83cc50583b62b4a1960c27fdf66bb3 (diff) |
PM posts
Diffstat (limited to 'Juick/APIClient.m')
-rw-r--r-- | Juick/APIClient.m | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 079db5a..1b3fb6e 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -102,6 +102,25 @@ }]; }]; } +-(void) postPMToUser:(NSString *)uname text:(NSString *)text result:(void (^)(NSError *))callback { + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; + [self.backgroundQueue addOperationWithBlock:^{ + [manager POST:@"/pm" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { + [formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"]; + [formData appendPartWithFormData:[uname dataUsingEncoding:NSUTF8StringEncoding] name:@"uname"]; + } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(nil); + }]; + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"Error: %@", [error localizedDescription]); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(error); + }]; + }]; + }]; +} + -(void) fetchChats:(void (^)(NSArray *, NSError *))callback { AFHTTPSessionManager *manager = [APIClient sharedClient].manager; [self.backgroundQueue addOperationWithBlock:^{ |