appjam 0.1.8.6 → 0.1.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/lib/appjam.rb +1 -1
  2. data/lib/appjam/generators/blank.rb +133 -0
  3. data/lib/appjam/generators/help.rb +5 -3
  4. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.pbxproj +855 -0
  5. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  6. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  7. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/EiffelApplication.xcscheme +96 -0
  8. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
  9. data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.h.tt +22 -0
  10. data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.m.tt +156 -0
  11. data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Info.plist +45 -0
  12. data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Prefix.pch.tt +30 -0
  13. data/lib/appjam/generators/templates/blank/EiffelApplication/en.lproj/InfoPlist.strings +2 -0
  14. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.h +636 -0
  15. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.m +1359 -0
  16. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.h +133 -0
  17. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.m +318 -0
  18. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.h +108 -0
  19. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.m +234 -0
  20. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.h +71 -0
  21. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.m +142 -0
  22. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  23. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.m +145 -0
  24. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworking.h +43 -0
  25. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  26. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.m +142 -0
  27. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.h +379 -0
  28. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.m +818 -0
  29. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.h +89 -0
  30. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.m +166 -0
  31. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.h +78 -0
  32. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.m +184 -0
  33. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.h +251 -0
  34. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.m +3067 -0
  35. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.h +155 -0
  36. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.m +1162 -0
  37. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.h +37 -0
  38. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.m +163 -0
  39. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.h +75 -0
  40. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.m +244 -0
  41. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.h +38 -0
  42. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.m +176 -0
  43. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.h +104 -0
  44. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.m +413 -0
  45. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.h +78 -0
  46. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.m +370 -0
  47. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.h +41 -0
  48. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.m +99 -0
  49. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
  50. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
  51. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.h +334 -0
  52. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.m +1353 -0
  53. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.h +601 -0
  54. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.m +1083 -0
  55. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.h +167 -0
  56. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.m +1479 -0
  57. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
  58. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
  59. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
  60. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
  61. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.h +33 -0
  62. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.m +122 -0
  63. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.h +72 -0
  64. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.m +305 -0
  65. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USConstants.h +38 -0
  66. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.h +57 -0
  67. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.m +188 -0
  68. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.h +89 -0
  69. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.m +261 -0
  70. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore-Prefix.pch +7 -0
  71. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.h +50 -0
  72. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.m +100 -0
  73. data/lib/appjam/generators/templates/blank/EiffelApplication/main.m.tt +18 -0
  74. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests-Info.plist +22 -0
  75. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.h.tt +13 -0
  76. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.m.tt +32 -0
  77. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/en.lproj/InfoPlist.strings +2 -0
  78. data/lib/appjam/generators/templates/resources/Default-568h@2x.png +0 -0
  79. data/lib/appjam/generators/templates/resources/Default.png +0 -0
  80. data/lib/appjam/generators/templates/resources/Default@2x.png +0 -0
  81. data/lib/appjam/generators/templates/resources/contents.tt +4 -0
  82. data/lib/appjam/version.rb +1 -1
  83. metadata +462 -326
  84. data/test/helper.rb +0 -132
  85. data/test/test_model_generator.rb +0 -28
  86. data/test/test_project_generator.rb +0 -38
@@ -0,0 +1,133 @@
1
+ // AFHTTPRequestOperation.h
2
+ //
3
+ // Copyright (c) 2011 Gowalla (http://gowalla.com/)
4
+ //
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the "Software"), to deal
7
+ // in the Software without restriction, including without limitation the rights
8
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ // copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+ //
12
+ // The above copyright notice and this permission notice shall be included in
13
+ // all copies or substantial portions of the Software.
14
+ //
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ // THE SOFTWARE.
22
+
23
+ #import <Foundation/Foundation.h>
24
+ #import "AFURLConnectionOperation.h"
25
+
26
+ /**
27
+ `AFHTTPRequestOperation` is a subclass of `AFURLConnectionOperation` for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request.
28
+ */
29
+ @interface AFHTTPRequestOperation : AFURLConnectionOperation
30
+
31
+ ///----------------------------------------------
32
+ /// @name Getting HTTP URL Connection Information
33
+ ///----------------------------------------------
34
+
35
+ /**
36
+ The last HTTP response received by the operation's connection.
37
+ */
38
+ @property (readonly, nonatomic, strong) NSHTTPURLResponse *response;
39
+
40
+ ///----------------------------------------------------------
41
+ /// @name Managing And Checking For Acceptable HTTP Responses
42
+ ///----------------------------------------------------------
43
+
44
+ /**
45
+ A Boolean value that corresponds to whether the status code of the response is within the specified set of acceptable status codes. Returns `YES` if `acceptableStatusCodes` is `nil`.
46
+ */
47
+ @property (nonatomic, readonly) BOOL hasAcceptableStatusCode;
48
+
49
+ /**
50
+ A Boolean value that corresponds to whether the MIME type of the response is among the specified set of acceptable content types. Returns `YES` if `acceptableContentTypes` is `nil`.
51
+ */
52
+ @property (nonatomic, readonly) BOOL hasAcceptableContentType;
53
+
54
+ /**
55
+ The callback dispatch queue on success. If `NULL` (default), the main queue is used.
56
+ */
57
+ @property (nonatomic, assign) dispatch_queue_t successCallbackQueue;
58
+
59
+ /**
60
+ The callback dispatch queue on failure. If `NULL` (default), the main queue is used.
61
+ */
62
+ @property (nonatomic, assign) dispatch_queue_t failureCallbackQueue;
63
+
64
+ ///------------------------------------------------------------
65
+ /// @name Managing Acceptable HTTP Status Codes & Content Types
66
+ ///------------------------------------------------------------
67
+
68
+ /**
69
+ Returns an `NSIndexSet` object containing the ranges of acceptable HTTP status codes. When non-`nil`, the operation will set the `error` property to an error in `AFErrorDomain`. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
70
+
71
+ By default, this is the range 200 to 299, inclusive.
72
+ */
73
+ + (NSIndexSet *)acceptableStatusCodes;
74
+
75
+ /**
76
+ Adds status codes to the set of acceptable HTTP status codes returned by `+acceptableStatusCodes` in subsequent calls by this class and its descendants.
77
+
78
+ @param statusCodes The status codes to be added to the set of acceptable HTTP status codes
79
+ */
80
+ + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes;
81
+
82
+ /**
83
+ Returns an `NSSet` object containing the acceptable MIME types. When non-`nil`, the operation will set the `error` property to an error in `AFErrorDomain`. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
84
+
85
+ By default, this is `nil`.
86
+ */
87
+ + (NSSet *)acceptableContentTypes;
88
+
89
+ /**
90
+ Adds content types to the set of acceptable MIME types returned by `+acceptableContentTypes` in subsequent calls by this class and its descendants.
91
+
92
+ @param contentTypes The content types to be added to the set of acceptable MIME types
93
+ */
94
+ + (void)addAcceptableContentTypes:(NSSet *)contentTypes;
95
+
96
+
97
+ ///-----------------------------------------------------
98
+ /// @name Determining Whether A Request Can Be Processed
99
+ ///-----------------------------------------------------
100
+
101
+ /**
102
+ A Boolean value determining whether or not the class can process the specified request. For example, `AFJSONRequestOperation` may check to make sure the content type was `application/json` or the URL path extension was `.json`.
103
+
104
+ @param urlRequest The request that is determined to be supported or not supported for this class.
105
+ */
106
+ + (BOOL)canProcessRequest:(NSURLRequest *)urlRequest;
107
+
108
+ ///-----------------------------------------------------------
109
+ /// @name Setting Completion Block Success / Failure Callbacks
110
+ ///-----------------------------------------------------------
111
+
112
+ /**
113
+ Sets the `completionBlock` property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If `error` returns a value, which can be caused by an unacceptable status code or content type, then `failure` is executed. Otherwise, `success` is executed.
114
+
115
+ @param success The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request.
116
+ @param failure The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occurred during the request.
117
+
118
+ @discussion This method should be overridden in subclasses in order to specify the response object passed into the success block.
119
+ */
120
+ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
121
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
122
+
123
+ @end
124
+
125
+ ///----------------
126
+ /// @name Functions
127
+ ///----------------
128
+
129
+ /**
130
+ Returns a set of MIME types detected in an HTTP `Accept` or `Content-Type` header.
131
+ */
132
+ extern NSSet * AFContentTypesFromHTTPHeader(NSString *string);
133
+
@@ -0,0 +1,318 @@
1
+ // AFHTTPRequestOperation.m
2
+ //
3
+ // Copyright (c) 2011 Gowalla (http://gowalla.com/)
4
+ //
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the "Software"), to deal
7
+ // in the Software without restriction, including without limitation the rights
8
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ // copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+ //
12
+ // The above copyright notice and this permission notice shall be included in
13
+ // all copies or substantial portions of the Software.
14
+ //
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ // THE SOFTWARE.
22
+
23
+ #import "AFHTTPRequestOperation.h"
24
+ #import <objc/runtime.h>
25
+
26
+ // Workaround for change in imp_implementationWithBlock() with Xcode 4.5
27
+ #if defined(__IPHONE_6_0) || defined(__MAC_10_8)
28
+ #define AF_CAST_TO_BLOCK id
29
+ #else
30
+ #define AF_CAST_TO_BLOCK __bridge void *
31
+ #endif
32
+
33
+ #pragma clang diagnostic push
34
+ #pragma clang diagnostic ignored "-Wstrict-selector-match"
35
+
36
+ NSSet * AFContentTypesFromHTTPHeader(NSString *string) {
37
+ if (!string) {
38
+ return nil;
39
+ }
40
+
41
+ NSArray *mediaRanges = [string componentsSeparatedByString:@","];
42
+ NSMutableSet *mutableContentTypes = [NSMutableSet setWithCapacity:mediaRanges.count];
43
+
44
+ [mediaRanges enumerateObjectsUsingBlock:^(NSString *mediaRange, __unused NSUInteger idx, __unused BOOL *stop) {
45
+ NSRange parametersRange = [mediaRange rangeOfString:@";"];
46
+ if (parametersRange.location != NSNotFound) {
47
+ mediaRange = [mediaRange substringToIndex:parametersRange.location];
48
+ }
49
+
50
+ mediaRange = [mediaRange stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
51
+
52
+ if (mediaRange.length > 0) {
53
+ [mutableContentTypes addObject:mediaRange];
54
+ }
55
+ }];
56
+
57
+ return [NSSet setWithSet:mutableContentTypes];
58
+ }
59
+
60
+ static void AFGetMediaTypeAndSubtypeWithString(NSString *string, NSString **type, NSString **subtype) {
61
+ NSScanner *scanner = [NSScanner scannerWithString:string];
62
+ [scanner setCharactersToBeSkipped:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
63
+ [scanner scanUpToString:@"/" intoString:type];
64
+ [scanner scanString:@"/" intoString:nil];
65
+ [scanner scanUpToString:@";" intoString:subtype];
66
+ }
67
+
68
+ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
69
+ NSMutableString *string = [NSMutableString string];
70
+
71
+ NSRange range = NSMakeRange([indexSet firstIndex], 1);
72
+ while (range.location != NSNotFound) {
73
+ NSUInteger nextIndex = [indexSet indexGreaterThanIndex:range.location];
74
+ while (nextIndex == range.location + range.length) {
75
+ range.length++;
76
+ nextIndex = [indexSet indexGreaterThanIndex:nextIndex];
77
+ }
78
+
79
+ if (string.length) {
80
+ [string appendString:@","];
81
+ }
82
+
83
+ if (range.length == 1) {
84
+ [string appendFormat:@"%lu", (long)range.location];
85
+ } else {
86
+ NSUInteger firstIndex = range.location;
87
+ NSUInteger lastIndex = firstIndex + range.length - 1;
88
+ [string appendFormat:@"%lu-%lu", (long)firstIndex, (long)lastIndex];
89
+ }
90
+
91
+ range.location = nextIndex;
92
+ range.length = 1;
93
+ }
94
+
95
+ return string;
96
+ }
97
+
98
+ static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, id block) {
99
+ Method originalMethod = class_getClassMethod(klass, selector);
100
+ IMP implementation = imp_implementationWithBlock((AF_CAST_TO_BLOCK)block);
101
+ class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod));
102
+ }
103
+
104
+ #pragma mark -
105
+
106
+ @interface AFHTTPRequestOperation ()
107
+ @property (readwrite, nonatomic, strong) NSURLRequest *request;
108
+ @property (readwrite, nonatomic, strong) NSHTTPURLResponse *response;
109
+ @property (readwrite, nonatomic, strong) NSError *HTTPError;
110
+ @end
111
+
112
+ @implementation AFHTTPRequestOperation
113
+ @synthesize HTTPError = _HTTPError;
114
+ @synthesize successCallbackQueue = _successCallbackQueue;
115
+ @synthesize failureCallbackQueue = _failureCallbackQueue;
116
+ @dynamic request;
117
+ @dynamic response;
118
+
119
+ - (void)dealloc {
120
+ if (_successCallbackQueue) {
121
+ #if !OS_OBJECT_USE_OBJC
122
+ dispatch_release(_successCallbackQueue);
123
+ #endif
124
+ _successCallbackQueue = NULL;
125
+ }
126
+
127
+ if (_failureCallbackQueue) {
128
+ #if !OS_OBJECT_USE_OBJC
129
+ dispatch_release(_failureCallbackQueue);
130
+ #endif
131
+ _failureCallbackQueue = NULL;
132
+ }
133
+ }
134
+
135
+ - (NSError *)error {
136
+ if (!self.HTTPError && self.response) {
137
+ if (![self hasAcceptableStatusCode] || ![self hasAcceptableContentType]) {
138
+ NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
139
+ [userInfo setValue:self.responseString forKey:NSLocalizedRecoverySuggestionErrorKey];
140
+ [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
141
+ [userInfo setValue:self.request forKey:AFNetworkingOperationFailingURLRequestErrorKey];
142
+ [userInfo setValue:self.response forKey:AFNetworkingOperationFailingURLResponseErrorKey];
143
+
144
+ if (![self hasAcceptableStatusCode]) {
145
+ NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200;
146
+ [userInfo setValue:[NSString stringWithFormat:NSLocalizedStringFromTable(@"Expected status code in (%@), got %d", @"AFNetworking", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), statusCode] forKey:NSLocalizedDescriptionKey];
147
+ self.HTTPError = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo];
148
+ } else if (![self hasAcceptableContentType]) {
149
+ // Don't invalidate content type if there is no content
150
+ if ([self.responseData length] > 0) {
151
+ [userInfo setValue:[NSString stringWithFormat:NSLocalizedStringFromTable(@"Expected content type %@, got %@", @"AFNetworking", nil), [[self class] acceptableContentTypes], [self.response MIMEType]] forKey:NSLocalizedDescriptionKey];
152
+ self.HTTPError = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo];
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ if (self.HTTPError) {
159
+ return self.HTTPError;
160
+ } else {
161
+ return [super error];
162
+ }
163
+ }
164
+
165
+ - (NSStringEncoding)responseStringEncoding {
166
+ // When no explicit charset parameter is provided by the sender, media subtypes of the "text" type are defined to have a default charset value of "ISO-8859-1" when received via HTTP. Data in character sets other than "ISO-8859-1" or its subsets MUST be labeled with an appropriate charset value.
167
+ // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.4.1
168
+ if (self.response && !self.response.textEncodingName && self.responseData) {
169
+ NSString *type = nil;
170
+ AFGetMediaTypeAndSubtypeWithString([[self.response allHeaderFields] valueForKey:@"Content-Type"], &type, nil);
171
+
172
+ if ([type isEqualToString:@"text"]) {
173
+ return NSISOLatin1StringEncoding;
174
+ }
175
+ }
176
+
177
+ return [super responseStringEncoding];
178
+ }
179
+
180
+ - (void)pause {
181
+ unsigned long long offset = 0;
182
+ if ([self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey]) {
183
+ offset = [[self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey] unsignedLongLongValue];
184
+ } else {
185
+ offset = [[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length];
186
+ }
187
+
188
+ NSMutableURLRequest *mutableURLRequest = [self.request mutableCopy];
189
+ if ([[self.response allHeaderFields] valueForKey:@"ETag"]) {
190
+ [mutableURLRequest setValue:[[self.response allHeaderFields] valueForKey:@"ETag"] forHTTPHeaderField:@"If-Range"];
191
+ }
192
+ [mutableURLRequest setValue:[NSString stringWithFormat:@"bytes=%llu-", offset] forHTTPHeaderField:@"Range"];
193
+ self.request = mutableURLRequest;
194
+
195
+ [super pause];
196
+ }
197
+
198
+ - (BOOL)hasAcceptableStatusCode {
199
+ if (!self.response) {
200
+ return NO;
201
+ }
202
+
203
+ NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200;
204
+ return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:statusCode];
205
+ }
206
+
207
+ - (BOOL)hasAcceptableContentType {
208
+ if (!self.response) {
209
+ return NO;
210
+ }
211
+
212
+ // Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream".
213
+ // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html
214
+ NSString *contentType = [self.response MIMEType];
215
+ if (!contentType) {
216
+ contentType = @"application/octet-stream";
217
+ }
218
+
219
+ return ![[self class] acceptableContentTypes] || [[[self class] acceptableContentTypes] containsObject:contentType];
220
+ }
221
+
222
+ - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue {
223
+ if (successCallbackQueue != _successCallbackQueue) {
224
+ if (_successCallbackQueue) {
225
+ #if !OS_OBJECT_USE_OBJC
226
+ dispatch_release(_successCallbackQueue);
227
+ #endif
228
+ _successCallbackQueue = NULL;
229
+ }
230
+
231
+ if (successCallbackQueue) {
232
+ #if !OS_OBJECT_USE_OBJC
233
+ dispatch_retain(successCallbackQueue);
234
+ #endif
235
+ _successCallbackQueue = successCallbackQueue;
236
+ }
237
+ }
238
+ }
239
+
240
+ - (void)setFailureCallbackQueue:(dispatch_queue_t)failureCallbackQueue {
241
+ if (failureCallbackQueue != _failureCallbackQueue) {
242
+ if (_failureCallbackQueue) {
243
+ #if !OS_OBJECT_USE_OBJC
244
+ dispatch_release(_failureCallbackQueue);
245
+ #endif
246
+ _failureCallbackQueue = NULL;
247
+ }
248
+
249
+ if (failureCallbackQueue) {
250
+ #if !OS_OBJECT_USE_OBJC
251
+ dispatch_retain(failureCallbackQueue);
252
+ #endif
253
+ _failureCallbackQueue = failureCallbackQueue;
254
+ }
255
+ }
256
+ }
257
+
258
+ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
259
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
260
+ {
261
+ // completionBlock is manually nilled out in AFURLConnectionOperation to break the retain cycle.
262
+ #pragma clang diagnostic push
263
+ #pragma clang diagnostic ignored "-Warc-retain-cycles"
264
+ self.completionBlock = ^{
265
+ if (self.error) {
266
+ if (failure) {
267
+ dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
268
+ failure(self, self.error);
269
+ });
270
+ }
271
+ } else {
272
+ if (success) {
273
+ dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
274
+ success(self, self.responseData);
275
+ });
276
+ }
277
+ }
278
+ };
279
+ #pragma clang diagnostic pop
280
+ }
281
+
282
+ #pragma mark - AFHTTPRequestOperation
283
+
284
+ + (NSIndexSet *)acceptableStatusCodes {
285
+ return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
286
+ }
287
+
288
+ + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes {
289
+ NSMutableIndexSet *mutableStatusCodes = [[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]];
290
+ [mutableStatusCodes addIndexes:statusCodes];
291
+ AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), ^(__unused id _self) {
292
+ return mutableStatusCodes;
293
+ });
294
+ }
295
+
296
+ + (NSSet *)acceptableContentTypes {
297
+ return nil;
298
+ }
299
+
300
+ + (void)addAcceptableContentTypes:(NSSet *)contentTypes {
301
+ NSMutableSet *mutableContentTypes = [[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES];
302
+ [mutableContentTypes unionSet:contentTypes];
303
+ AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), ^(__unused id _self) {
304
+ return mutableContentTypes;
305
+ });
306
+ }
307
+
308
+ + (BOOL)canProcessRequest:(NSURLRequest *)request {
309
+ if ([[self class] isEqual:[AFHTTPRequestOperation class]]) {
310
+ return YES;
311
+ }
312
+
313
+ return [[self acceptableContentTypes] intersectsSet:AFContentTypesFromHTTPHeader([request valueForHTTPHeaderField:@"Accept"])];
314
+ }
315
+
316
+ @end
317
+
318
+ #pragma clang diagnostic pop