afmotion 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/AFMotion.gemspec +1 -1
  2. data/Gemfile.lock +1 -1
  3. data/lib/afmotion/version.rb +1 -1
  4. metadata +3 -67
  5. data/examples/AppDotNet/.gitignore +0 -13
  6. data/examples/AppDotNet/Gemfile +0 -4
  7. data/examples/AppDotNet/Gemfile.lock +0 -48
  8. data/examples/AppDotNet/Rakefile +0 -10
  9. data/examples/AppDotNet/app/app_delegate.rb +0 -28
  10. data/examples/AppDotNet/app/global_timeline_view_controller.rb +0 -84
  11. data/examples/AppDotNet/app/post.rb +0 -23
  12. data/examples/AppDotNet/app/post_table_view_cell.rb +0 -44
  13. data/examples/AppDotNet/app/user.rb +0 -9
  14. data/examples/AppDotNet/resources/profile-image-placeholder.png +0 -0
  15. data/examples/AppDotNet/resources/profile-image-placeholder@2x.png +0 -0
  16. data/examples/AppDotNet/spec/main_spec.rb +0 -9
  17. data/examples/AppDotNet/vendor/Podfile.lock +0 -11
  18. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking.podspec +0 -28
  19. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +0 -574
  20. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +0 -1187
  21. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +0 -133
  22. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +0 -341
  23. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +0 -108
  24. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +0 -237
  25. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +0 -71
  26. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +0 -136
  27. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  28. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +0 -131
  29. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +0 -44
  30. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  31. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +0 -145
  32. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +0 -295
  33. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +0 -652
  34. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +0 -89
  35. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +0 -169
  36. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +0 -78
  37. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +0 -180
  38. data/examples/AppDotNet/vendor/Pods/AFNetworking/LICENSE +0 -19
  39. data/examples/AppDotNet/vendor/Pods/AFNetworking/README.md +0 -179
  40. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +0 -574
  41. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +0 -133
  42. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +0 -108
  43. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +0 -71
  44. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  45. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +0 -44
  46. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  47. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +0 -295
  48. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +0 -89
  49. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +0 -78
  50. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +0 -574
  51. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +0 -133
  52. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +0 -108
  53. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +0 -71
  54. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  55. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworking.h +0 -44
  56. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  57. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +0 -295
  58. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +0 -89
  59. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +0 -78
  60. data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.markdown +0 -26
  61. data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.plist +0 -56
  62. data/examples/AppDotNet/vendor/Pods/Pods-prefix.pch +0 -12
  63. data/examples/AppDotNet/vendor/Pods/Pods-resources.sh +0 -19
  64. data/examples/AppDotNet/vendor/Pods/Pods.bridgesupport +0 -617
  65. data/examples/AppDotNet/vendor/Pods/Pods.xcconfig +0 -7
  66. data/examples/AppDotNet/vendor/Pods/Pods.xcodeproj/project.pbxproj +0 -998
  67. data/examples/AppDotNet/vendor/Pods/PodsDummy_Pods.m +0 -4
  68. data/pkg/afmotion-0.0.1.gem +0 -0
@@ -1,133 +0,0 @@
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 (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 (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
-
@@ -1,341 +0,0 @@
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
- NSSet * AFContentTypesFromHTTPHeader(NSString *string) {
34
- if (!string) {
35
- return nil;
36
- }
37
-
38
- NSArray *mediaRanges = [string componentsSeparatedByString:@","];
39
- NSMutableSet *mutableContentTypes = [NSMutableSet setWithCapacity:mediaRanges.count];
40
-
41
- [mediaRanges enumerateObjectsUsingBlock:^(NSString *mediaRange, NSUInteger idx, BOOL *stop) {
42
- NSRange parametersRange = [mediaRange rangeOfString:@";"];
43
- if (parametersRange.location != NSNotFound) {
44
- mediaRange = [mediaRange substringToIndex:parametersRange.location];
45
- }
46
-
47
- mediaRange = [mediaRange stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
48
-
49
- if (mediaRange.length > 0) {
50
- [mutableContentTypes addObject:mediaRange];
51
- }
52
- }];
53
-
54
- return [NSSet setWithSet:mutableContentTypes];
55
- }
56
-
57
- static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
58
- NSMutableString *string = [NSMutableString string];
59
-
60
- NSRange range = NSMakeRange([indexSet firstIndex], 1);
61
- while (range.location != NSNotFound) {
62
- NSUInteger nextIndex = [indexSet indexGreaterThanIndex:range.location];
63
- while (nextIndex == range.location + range.length) {
64
- range.length++;
65
- nextIndex = [indexSet indexGreaterThanIndex:nextIndex];
66
- }
67
-
68
- if (string.length) {
69
- [string appendString:@","];
70
- }
71
-
72
- if (range.length == 1) {
73
- [string appendFormat:@"%lu", (long)range.location];
74
- } else {
75
- NSUInteger firstIndex = range.location;
76
- NSUInteger lastIndex = firstIndex + range.length - 1;
77
- [string appendFormat:@"%lu-%lu", (long)firstIndex, (long)lastIndex];
78
- }
79
-
80
- range.location = nextIndex;
81
- range.length = 1;
82
- }
83
-
84
- return string;
85
- }
86
-
87
- static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, id block) {
88
- Method originalMethod = class_getClassMethod(klass, selector);
89
- IMP implementation = imp_implementationWithBlock((AF_CAST_TO_BLOCK)block);
90
- class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod));
91
- }
92
-
93
- #pragma mark -
94
-
95
- @interface AFHTTPRequestOperation ()
96
- @property (readwrite, nonatomic, strong) NSURLRequest *request;
97
- @property (readwrite, nonatomic, strong) NSHTTPURLResponse *response;
98
- @property (readwrite, nonatomic, strong) NSError *HTTPError;
99
- @property (assign) long long totalContentLength;
100
- @property (assign) long long offsetContentLength;
101
- @end
102
-
103
- @implementation AFHTTPRequestOperation
104
- @synthesize HTTPError = _HTTPError;
105
- @synthesize successCallbackQueue = _successCallbackQueue;
106
- @synthesize failureCallbackQueue = _failureCallbackQueue;
107
- @synthesize totalContentLength = _totalContentLength;
108
- @synthesize offsetContentLength = _offsetContentLength;
109
- @dynamic request;
110
- @dynamic response;
111
-
112
- - (void)dealloc {
113
- if (_successCallbackQueue) {
114
- #if !OS_OBJECT_USE_OBJC
115
- dispatch_release(_successCallbackQueue);
116
- #endif
117
- _successCallbackQueue = NULL;
118
- }
119
-
120
- if (_failureCallbackQueue) {
121
- #if !OS_OBJECT_USE_OBJC
122
- dispatch_release(_failureCallbackQueue);
123
- #endif
124
- _failureCallbackQueue = NULL;
125
- }
126
- }
127
-
128
- - (NSError *)error {
129
- if (self.response && !self.HTTPError) {
130
- if (![self hasAcceptableStatusCode] || ![self hasAcceptableContentType]) {
131
- NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
132
- [userInfo setValue:self.responseString forKey:NSLocalizedRecoverySuggestionErrorKey];
133
- [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
134
- [userInfo setValue:self.request forKey:AFNetworkingOperationFailingURLRequestErrorKey];
135
- [userInfo setValue:self.response forKey:AFNetworkingOperationFailingURLResponseErrorKey];
136
-
137
- if (![self hasAcceptableStatusCode]) {
138
- NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200;
139
- [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code in (%@), got %d", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), statusCode] forKey:NSLocalizedDescriptionKey];
140
- self.HTTPError = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo];
141
- } else if (![self hasAcceptableContentType]) {
142
- // Don't invalidate content type if there is no content
143
- if ([self.responseData length] > 0) {
144
- [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected content type %@, got %@", nil), [[self class] acceptableContentTypes], [self.response MIMEType]] forKey:NSLocalizedDescriptionKey];
145
- self.HTTPError = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo];
146
- }
147
- }
148
- }
149
- }
150
-
151
- if (self.HTTPError) {
152
- return self.HTTPError;
153
- } else {
154
- return [super error];
155
- }
156
- }
157
-
158
- - (void)pause {
159
- unsigned long long offset = 0;
160
- if ([self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey]) {
161
- offset = [[self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey] unsignedLongLongValue];
162
- } else {
163
- offset = [[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length];
164
- }
165
-
166
- NSMutableURLRequest *mutableURLRequest = [self.request mutableCopy];
167
- if ([[self.response allHeaderFields] valueForKey:@"ETag"]) {
168
- [mutableURLRequest setValue:[[self.response allHeaderFields] valueForKey:@"ETag"] forHTTPHeaderField:@"If-Range"];
169
- }
170
- [mutableURLRequest setValue:[NSString stringWithFormat:@"bytes=%llu-", offset] forHTTPHeaderField:@"Range"];
171
- self.request = mutableURLRequest;
172
-
173
- [super pause];
174
- }
175
-
176
- - (BOOL)hasAcceptableStatusCode {
177
- if (!self.response) {
178
- return NO;
179
- }
180
-
181
- NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200;
182
- return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:statusCode];
183
- }
184
-
185
- - (BOOL)hasAcceptableContentType {
186
- if (!self.response) {
187
- return NO;
188
- }
189
-
190
- // According to RFC 2616:
191
- // 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".
192
- // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html
193
- NSString *contentType = [self.response MIMEType];
194
- if (!contentType) {
195
- contentType = @"application/octet-stream";
196
- }
197
-
198
- return ![[self class] acceptableContentTypes] || [[[self class] acceptableContentTypes] containsObject:contentType];
199
- }
200
-
201
- - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue {
202
- if (successCallbackQueue != _successCallbackQueue) {
203
- if (_successCallbackQueue) {
204
- #if !OS_OBJECT_USE_OBJC
205
- dispatch_release(_successCallbackQueue);
206
- #endif
207
- _successCallbackQueue = NULL;
208
- }
209
-
210
- if (successCallbackQueue) {
211
- #if !OS_OBJECT_USE_OBJC
212
- dispatch_retain(successCallbackQueue);
213
- #endif
214
- _successCallbackQueue = successCallbackQueue;
215
- }
216
- }
217
- }
218
-
219
- - (void)setFailureCallbackQueue:(dispatch_queue_t)failureCallbackQueue {
220
- if (failureCallbackQueue != _failureCallbackQueue) {
221
- if (_failureCallbackQueue) {
222
- #if !OS_OBJECT_USE_OBJC
223
- dispatch_release(_failureCallbackQueue);
224
- #endif
225
- _failureCallbackQueue = NULL;
226
- }
227
-
228
- if (failureCallbackQueue) {
229
- #if !OS_OBJECT_USE_OBJC
230
- dispatch_retain(failureCallbackQueue);
231
- #endif
232
- _failureCallbackQueue = failureCallbackQueue;
233
- }
234
- }
235
- }
236
-
237
- - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
238
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
239
- {
240
- // completionBlock is manually nilled out in AFURLConnectionOperation to break the retain cycle.
241
- #pragma clang diagnostic push
242
- #pragma clang diagnostic ignored "-Warc-retain-cycles"
243
- self.completionBlock = ^{
244
- if ([self isCancelled]) {
245
- return;
246
- }
247
-
248
- if (self.error) {
249
- if (failure) {
250
- dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
251
- failure(self, self.error);
252
- });
253
- }
254
- } else {
255
- if (success) {
256
- dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
257
- success(self, self.responseData);
258
- });
259
- }
260
- }
261
- };
262
- #pragma clang diagnostic pop
263
- }
264
-
265
- #pragma mark - AFHTTPRequestOperation
266
-
267
- + (NSIndexSet *)acceptableStatusCodes {
268
- return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
269
- }
270
-
271
- + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes {
272
- NSMutableIndexSet *mutableStatusCodes = [[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]];
273
- [mutableStatusCodes addIndexes:statusCodes];
274
- AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), ^(id _self) {
275
- return mutableStatusCodes;
276
- });
277
- }
278
-
279
- + (NSSet *)acceptableContentTypes {
280
- return nil;
281
- }
282
-
283
- + (void)addAcceptableContentTypes:(NSSet *)contentTypes {
284
- NSMutableSet *mutableContentTypes = [[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES];
285
- [mutableContentTypes unionSet:contentTypes];
286
- AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), ^(id _self) {
287
- return mutableContentTypes;
288
- });
289
- }
290
-
291
- + (BOOL)canProcessRequest:(NSURLRequest *)request {
292
- if ([[self class] isEqual:[AFHTTPRequestOperation class]]) {
293
- return YES;
294
- }
295
-
296
- return [[self acceptableContentTypes] intersectsSet:AFContentTypesFromHTTPHeader([request valueForHTTPHeaderField:@"Accept"])];
297
- }
298
-
299
- #pragma mark - NSURLConnectionDelegate
300
-
301
- - (void)connection:(NSURLConnection *)connection
302
- didReceiveResponse:(NSURLResponse *)response
303
- {
304
- self.response = (NSHTTPURLResponse *)response;
305
-
306
- // Set Content-Range header if status code of response is 206 (Partial Content)
307
- // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.7
308
- long long totalContentLength = self.response.expectedContentLength;
309
- long long fileOffset = 0;
310
- NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200;
311
- if (statusCode == 206) {
312
- NSString *contentRange = [self.response.allHeaderFields valueForKey:@"Content-Range"];
313
- if ([contentRange hasPrefix:@"bytes"]) {
314
- NSArray *byteRanges = [contentRange componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" -/"]];
315
- if ([byteRanges count] == 4) {
316
- fileOffset = [[byteRanges objectAtIndex:1] longLongValue];
317
- totalContentLength = [[byteRanges objectAtIndex:2] longLongValue] ?: -1; // if this is "*", it's converted to 0, but -1 is default.
318
- }
319
- }
320
- } else {
321
- if ([self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey]) {
322
- [self.outputStream setProperty:[NSNumber numberWithInteger:0] forKey:NSStreamFileCurrentOffsetKey];
323
- } else {
324
- if ([[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length] > 0) {
325
- self.outputStream = [NSOutputStream outputStreamToMemory];
326
-
327
- NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
328
- for (NSString *runLoopMode in self.runLoopModes) {
329
- [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode];
330
- }
331
- }
332
- }
333
- }
334
-
335
- self.offsetContentLength = MAX(fileOffset, 0);
336
- self.totalContentLength = totalContentLength;
337
-
338
- [self.outputStream open];
339
- }
340
-
341
- @end