OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <Foundation/Foundation.h> |
| 6 #include "OmahaCommunication.h" |
| 7 |
| 8 @implementation OmahaCommunication : NSObject |
| 9 |
| 10 @synthesize requestXMLBody; |
| 11 @synthesize sessionHelper; |
| 12 |
| 13 - (id)init { |
| 14 return [self initWithBody:[[NSXMLDocument alloc] init]]; |
| 15 } |
| 16 - (id)initWithBody:(NSXMLDocument*) xmlBody { |
| 17 if ((self = [super init])) { |
| 18 sessionHelper = [[NetworkCommunication alloc] init]; |
| 19 requestXMLBody = xmlBody; |
| 20 [self createOmahaRequest]; |
| 21 } |
| 22 return self; |
| 23 } |
| 24 |
| 25 - (NSURLRequest*)createOmahaRequest { |
| 26 NSMutableURLRequest* request = [sessionHelper |
| 27 createRequestWithURLasString:@"https://tools.google.com/service/update2" |
| 28 andXMLBody:requestXMLBody]; |
| 29 request.HTTPMethod = @"POST"; |
| 30 return request; |
| 31 } |
| 32 |
| 33 - (void)sendRequestWithBlock:(OmahaRequestCompletionHandler) block { |
| 34 DataTaskCompletionHandler cHandler = ^(NSData* _Nullable data, |
| 35 NSURLResponse* _Nullable response, |
| 36 NSError* _Nullable error) { |
| 37 if (error) { |
| 38 NSLog(@"%@", error); |
| 39 block(data, error); |
| 40 return; |
| 41 } |
| 42 |
| 43 NSHTTPURLResponse* HTTPResponse = (NSHTTPURLResponse*)response; |
| 44 if (HTTPResponse.statusCode != 200) { |
| 45 NSLog(@"HTTP response: %ld", (unsigned long)HTTPResponse.statusCode); |
| 46 } |
| 47 |
| 48 block(data, error); |
| 49 |
| 50 }; |
| 51 |
| 52 [sessionHelper sendDataRequestWithCompletionHandler:cHandler]; |
| 53 } |
| 54 |
| 55 @end |
OLD | NEW |