| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
| 12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
| 13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
| 14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
| 15 * | 15 * |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #import "ARDLogging.h" | |
| 29 #import "ARDUtilities.h" | 28 #import "ARDUtilities.h" |
| 30 | 29 |
| 30 #import "RTCLogging.h" |
| 31 |
| 31 @implementation NSDictionary (ARDUtilites) | 32 @implementation NSDictionary (ARDUtilites) |
| 32 | 33 |
| 33 + (NSDictionary *)dictionaryWithJSONString:(NSString *)jsonString { | 34 + (NSDictionary *)dictionaryWithJSONString:(NSString *)jsonString { |
| 34 NSParameterAssert(jsonString.length > 0); | 35 NSParameterAssert(jsonString.length > 0); |
| 35 NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; | 36 NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; |
| 36 NSError *error = nil; | 37 NSError *error = nil; |
| 37 NSDictionary *dict = | 38 NSDictionary *dict = |
| 38 [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; | 39 [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; |
| 39 if (error) { | 40 if (error) { |
| 40 ARDLog(@"Error parsing JSON: %@", error.localizedDescription); | 41 RTCLogError(@"Error parsing JSON: %@", error.localizedDescription); |
| 41 } | 42 } |
| 42 return dict; | 43 return dict; |
| 43 } | 44 } |
| 44 | 45 |
| 45 + (NSDictionary *)dictionaryWithJSONData:(NSData *)jsonData { | 46 + (NSDictionary *)dictionaryWithJSONData:(NSData *)jsonData { |
| 46 NSError *error = nil; | 47 NSError *error = nil; |
| 47 NSDictionary *dict = | 48 NSDictionary *dict = |
| 48 [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; | 49 [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; |
| 49 if (error) { | 50 if (error) { |
| 50 ARDLog(@"Error parsing JSON: %@", error.localizedDescription); | 51 RTCLogError(@"Error parsing JSON: %@", error.localizedDescription); |
| 51 } | 52 } |
| 52 return dict; | 53 return dict; |
| 53 } | 54 } |
| 54 | 55 |
| 55 @end | 56 @end |
| 56 | 57 |
| 57 @implementation NSURLConnection (ARDUtilities) | 58 @implementation NSURLConnection (ARDUtilities) |
| 58 | 59 |
| 59 + (void)sendAsyncRequest:(NSURLRequest *)request | 60 + (void)sendAsyncRequest:(NSURLRequest *)request |
| 60 completionHandler:(void (^)(NSURLResponse *response, | 61 completionHandler:(void (^)(NSURLResponse *response, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 78 completionHandler:(void (^)(BOOL succeeded, | 79 completionHandler:(void (^)(BOOL succeeded, |
| 79 NSData *data))completionHandler { | 80 NSData *data))completionHandler { |
| 80 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; | 81 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; |
| 81 request.HTTPMethod = @"POST"; | 82 request.HTTPMethod = @"POST"; |
| 82 request.HTTPBody = data; | 83 request.HTTPBody = data; |
| 83 [[self class] sendAsyncRequest:request | 84 [[self class] sendAsyncRequest:request |
| 84 completionHandler:^(NSURLResponse *response, | 85 completionHandler:^(NSURLResponse *response, |
| 85 NSData *data, | 86 NSData *data, |
| 86 NSError *error) { | 87 NSError *error) { |
| 87 if (error) { | 88 if (error) { |
| 88 ARDLog(@"Error posting data: %@", error.localizedDescription); | 89 RTCLogError(@"Error posting data: %@", error.localizedDescription); |
| 89 if (completionHandler) { | 90 if (completionHandler) { |
| 90 completionHandler(NO, data); | 91 completionHandler(NO, data); |
| 91 } | 92 } |
| 92 return; | 93 return; |
| 93 } | 94 } |
| 94 NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; | 95 NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; |
| 95 if (httpResponse.statusCode != 200) { | 96 if (httpResponse.statusCode != 200) { |
| 96 NSString *serverResponse = data.length > 0 ? | 97 NSString *serverResponse = data.length > 0 ? |
| 97 [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] : | 98 [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] : |
| 98 nil; | 99 nil; |
| 99 ARDLog(@"Received bad response: %@", serverResponse); | 100 RTCLogError(@"Received bad response: %@", serverResponse); |
| 100 if (completionHandler) { | 101 if (completionHandler) { |
| 101 completionHandler(NO, data); | 102 completionHandler(NO, data); |
| 102 } | 103 } |
| 103 return; | 104 return; |
| 104 } | 105 } |
| 105 if (completionHandler) { | 106 if (completionHandler) { |
| 106 completionHandler(YES, data); | 107 completionHandler(YES, data); |
| 107 } | 108 } |
| 108 }]; | 109 }]; |
| 109 } | 110 } |
| 110 | 111 |
| 111 @end | 112 @end |
| OLD | NEW |