afmotion 0.6 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +1 -1
- data/Gemfile.lock +21 -28
- data/lib/afmotion/patch/NSURLRequest_params.rb +4 -2
- data/lib/afmotion/version.rb +1 -1
- metadata +2 -53
- data/vendor/Pods/AFNetworking/AFNetworking.podspec +0 -28
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +0 -574
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +0 -1187
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +0 -133
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +0 -341
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +0 -108
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +0 -237
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +0 -71
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +0 -136
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +0 -131
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +0 -44
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +0 -68
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +0 -145
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +0 -295
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +0 -652
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +0 -89
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +0 -169
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +0 -78
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +0 -180
- data/vendor/Pods/AFNetworking/LICENSE +0 -19
- data/vendor/Pods/AFNetworking/README.md +0 -179
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +0 -574
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +0 -133
- data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +0 -108
- data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +0 -71
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +0 -44
- data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +0 -68
- data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +0 -295
- data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +0 -89
- data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +0 -78
- data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +0 -574
- data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +0 -133
- data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +0 -108
- data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +0 -71
- data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
- data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +0 -44
- data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +0 -68
- data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +0 -295
- data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +0 -89
- data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +0 -78
- data/vendor/Pods/Pods-Acknowledgements.markdown +0 -26
- data/vendor/Pods/Pods-Acknowledgements.plist +0 -56
- data/vendor/Pods/Pods-prefix.pch +0 -14
- data/vendor/Pods/Pods-resources.sh +0 -19
- data/vendor/Pods/Pods.bridgesupport +0 -617
- data/vendor/Pods/Pods.xcconfig +0 -7
- data/vendor/Pods/PodsDummy_Pods.m +0 -4
@@ -1,108 +0,0 @@
|
|
1
|
-
// AFImageRequestOperation.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 "AFHTTPRequestOperation.h"
|
25
|
-
|
26
|
-
#import <Availability.h>
|
27
|
-
|
28
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
29
|
-
#import <UIKit/UIKit.h>
|
30
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
31
|
-
#import <Cocoa/Cocoa.h>
|
32
|
-
#endif
|
33
|
-
|
34
|
-
/**
|
35
|
-
`AFImageRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading an processing images.
|
36
|
-
|
37
|
-
## Acceptable Content Types
|
38
|
-
|
39
|
-
By default, `AFImageRequestOperation` accepts the following MIME types, which correspond to the image formats supported by UIImage or NSImage:
|
40
|
-
|
41
|
-
- `image/tiff`
|
42
|
-
- `image/jpeg`
|
43
|
-
- `image/gif`
|
44
|
-
- `image/png`
|
45
|
-
- `image/ico`
|
46
|
-
- `image/x-icon`
|
47
|
-
- `image/bmp`
|
48
|
-
- `image/x-bmp`
|
49
|
-
- `image/x-xbitmap`
|
50
|
-
- `image/x-win-bitmap`
|
51
|
-
*/
|
52
|
-
@interface AFImageRequestOperation : AFHTTPRequestOperation
|
53
|
-
|
54
|
-
/**
|
55
|
-
An image constructed from the response data. If an error occurs during the request, `nil` will be returned, and the `error` property will be set to the error.
|
56
|
-
*/
|
57
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
58
|
-
@property (readonly, nonatomic, strong) UIImage *responseImage;
|
59
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
60
|
-
@property (readonly, nonatomic, strong) NSImage *responseImage;
|
61
|
-
#endif
|
62
|
-
|
63
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
64
|
-
/**
|
65
|
-
The scale factor used when interpreting the image data to construct `responseImage`. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of scale of the main screen by default, which automatically scales images for retina displays, for instance.
|
66
|
-
*/
|
67
|
-
@property (nonatomic, assign) CGFloat imageScale;
|
68
|
-
#endif
|
69
|
-
|
70
|
-
/**
|
71
|
-
Creates and returns an `AFImageRequestOperation` object and sets the specified success callback.
|
72
|
-
|
73
|
-
@param urlRequest The request object to be loaded asynchronously during execution of the operation.
|
74
|
-
@param success A block object to be executed when the request finishes successfully. This block has no return value and takes a single arguments, the image created from the response data of the request.
|
75
|
-
|
76
|
-
@return A new image request operation
|
77
|
-
*/
|
78
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
79
|
-
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
80
|
-
success:(void (^)(UIImage *image))success;
|
81
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
82
|
-
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
83
|
-
success:(void (^)(NSImage *image))success;
|
84
|
-
#endif
|
85
|
-
|
86
|
-
/**
|
87
|
-
Creates and returns an `AFImageRequestOperation` object and sets the specified success callback.
|
88
|
-
|
89
|
-
@param urlRequest The request object to be loaded asynchronously during execution of the operation.
|
90
|
-
@param imageProcessingBlock A block object to be executed after the image request finishes successfully, but before the image is returned in the `success` block. This block takes a single argument, the image loaded from the response body, and returns the processed image.
|
91
|
-
@param success A block object to be executed when the request finishes successfully, with a status code in the 2xx range, and with an acceptable content type (e.g. `image/png`). This block has no return value and takes three arguments: the request object of the operation, the response for the request, and the image created from the response data.
|
92
|
-
@param failure A block object to be executed when the request finishes unsuccessfully. This block has no return value and takes three arguments: the request object of the operation, the response for the request, and the error associated with the cause for the unsuccessful operation.
|
93
|
-
|
94
|
-
@return A new image request operation
|
95
|
-
*/
|
96
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
97
|
-
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
98
|
-
imageProcessingBlock:(UIImage *(^)(UIImage *image))imageProcessingBlock
|
99
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
|
100
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
|
101
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
102
|
-
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
103
|
-
imageProcessingBlock:(NSImage *(^)(NSImage *image))imageProcessingBlock
|
104
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success
|
105
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
|
106
|
-
#endif
|
107
|
-
|
108
|
-
@end
|
@@ -1,237 +0,0 @@
|
|
1
|
-
// AFImageRequestOperation.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 "AFImageRequestOperation.h"
|
24
|
-
|
25
|
-
static dispatch_queue_t af_image_request_operation_processing_queue;
|
26
|
-
static dispatch_queue_t image_request_operation_processing_queue() {
|
27
|
-
if (af_image_request_operation_processing_queue == NULL) {
|
28
|
-
af_image_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.image-request.processing", 0);
|
29
|
-
}
|
30
|
-
|
31
|
-
return af_image_request_operation_processing_queue;
|
32
|
-
}
|
33
|
-
|
34
|
-
@interface AFImageRequestOperation ()
|
35
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
36
|
-
@property (readwrite, nonatomic, strong) UIImage *responseImage;
|
37
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
38
|
-
@property (readwrite, nonatomic, strong) NSImage *responseImage;
|
39
|
-
#endif
|
40
|
-
@end
|
41
|
-
|
42
|
-
@implementation AFImageRequestOperation
|
43
|
-
@synthesize responseImage = _responseImage;
|
44
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
45
|
-
@synthesize imageScale = _imageScale;
|
46
|
-
#endif
|
47
|
-
|
48
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
49
|
-
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
50
|
-
success:(void (^)(UIImage *image))success
|
51
|
-
{
|
52
|
-
return [self imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, UIImage *image) {
|
53
|
-
if (success) {
|
54
|
-
success(image);
|
55
|
-
}
|
56
|
-
} failure:nil];
|
57
|
-
}
|
58
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
59
|
-
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
60
|
-
success:(void (^)(NSImage *image))success
|
61
|
-
{
|
62
|
-
return [self imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, NSImage *image) {
|
63
|
-
if (success) {
|
64
|
-
success(image);
|
65
|
-
}
|
66
|
-
} failure:nil];
|
67
|
-
}
|
68
|
-
#endif
|
69
|
-
|
70
|
-
|
71
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
72
|
-
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
73
|
-
imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock
|
74
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
|
75
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
|
76
|
-
{
|
77
|
-
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
78
|
-
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
79
|
-
if (success) {
|
80
|
-
UIImage *image = responseObject;
|
81
|
-
if (imageProcessingBlock) {
|
82
|
-
dispatch_async(image_request_operation_processing_queue(), ^(void) {
|
83
|
-
UIImage *processedImage = imageProcessingBlock(image);
|
84
|
-
|
85
|
-
dispatch_async(requestOperation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
|
86
|
-
success(operation.request, operation.response, processedImage);
|
87
|
-
});
|
88
|
-
});
|
89
|
-
} else {
|
90
|
-
success(operation.request, operation.response, image);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
94
|
-
if (failure) {
|
95
|
-
failure(operation.request, operation.response, error);
|
96
|
-
}
|
97
|
-
}];
|
98
|
-
|
99
|
-
|
100
|
-
return requestOperation;
|
101
|
-
}
|
102
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
103
|
-
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
104
|
-
imageProcessingBlock:(NSImage *(^)(NSImage *))imageProcessingBlock
|
105
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success
|
106
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
|
107
|
-
{
|
108
|
-
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
109
|
-
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
110
|
-
if (success) {
|
111
|
-
NSImage *image = responseObject;
|
112
|
-
if (imageProcessingBlock) {
|
113
|
-
dispatch_async(image_request_operation_processing_queue(), ^(void) {
|
114
|
-
NSImage *processedImage = imageProcessingBlock(image);
|
115
|
-
|
116
|
-
dispatch_async(requestOperation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
|
117
|
-
success(operation.request, operation.response, processedImage);
|
118
|
-
});
|
119
|
-
});
|
120
|
-
} else {
|
121
|
-
success(operation.request, operation.response, image);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
125
|
-
if (failure) {
|
126
|
-
failure(operation.request, operation.response, error);
|
127
|
-
}
|
128
|
-
}];
|
129
|
-
|
130
|
-
return requestOperation;
|
131
|
-
}
|
132
|
-
#endif
|
133
|
-
|
134
|
-
- (id)initWithRequest:(NSURLRequest *)urlRequest {
|
135
|
-
self = [super initWithRequest:urlRequest];
|
136
|
-
if (!self) {
|
137
|
-
return nil;
|
138
|
-
}
|
139
|
-
|
140
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
141
|
-
self.imageScale = [[UIScreen mainScreen] scale];
|
142
|
-
#endif
|
143
|
-
|
144
|
-
return self;
|
145
|
-
}
|
146
|
-
|
147
|
-
|
148
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
149
|
-
- (UIImage *)responseImage {
|
150
|
-
if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) {
|
151
|
-
UIImage *image = [UIImage imageWithData:self.responseData];
|
152
|
-
|
153
|
-
self.responseImage = [UIImage imageWithCGImage:[image CGImage] scale:self.imageScale orientation:image.imageOrientation];
|
154
|
-
}
|
155
|
-
|
156
|
-
return _responseImage;
|
157
|
-
}
|
158
|
-
|
159
|
-
- (void)setImageScale:(CGFloat)imageScale {
|
160
|
-
#pragma clang diagnostic push
|
161
|
-
#pragma clang diagnostic ignored "-Wfloat-equal"
|
162
|
-
if (imageScale == _imageScale) {
|
163
|
-
return;
|
164
|
-
}
|
165
|
-
#pragma clang diagnostic pop
|
166
|
-
|
167
|
-
_imageScale = imageScale;
|
168
|
-
|
169
|
-
self.responseImage = nil;
|
170
|
-
}
|
171
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
172
|
-
- (NSImage *)responseImage {
|
173
|
-
if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) {
|
174
|
-
// Ensure that the image is set to it's correct pixel width and height
|
175
|
-
NSBitmapImageRep *bitimage = [[NSBitmapImageRep alloc] initWithData:self.responseData];
|
176
|
-
self.responseImage = [[NSImage alloc] initWithSize:NSMakeSize([bitimage pixelsWide], [bitimage pixelsHigh])];
|
177
|
-
[self.responseImage addRepresentation:bitimage];
|
178
|
-
}
|
179
|
-
|
180
|
-
return _responseImage;
|
181
|
-
}
|
182
|
-
#endif
|
183
|
-
|
184
|
-
#pragma mark - AFHTTPRequestOperation
|
185
|
-
|
186
|
-
+ (NSSet *)acceptableContentTypes {
|
187
|
-
return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil];
|
188
|
-
}
|
189
|
-
|
190
|
-
+ (BOOL)canProcessRequest:(NSURLRequest *)request {
|
191
|
-
static NSSet * _acceptablePathExtension = nil;
|
192
|
-
static dispatch_once_t onceToken;
|
193
|
-
dispatch_once(&onceToken, ^{
|
194
|
-
_acceptablePathExtension = [[NSSet alloc] initWithObjects:@"tif", @"tiff", @"jpg", @"jpeg", @"gif", @"png", @"ico", @"bmp", @"cur", nil];
|
195
|
-
});
|
196
|
-
|
197
|
-
return [_acceptablePathExtension containsObject:[[request URL] pathExtension]] || [super canProcessRequest:request];
|
198
|
-
}
|
199
|
-
|
200
|
-
- (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
201
|
-
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
202
|
-
{
|
203
|
-
#pragma clang diagnostic push
|
204
|
-
#pragma clang diagnostic ignored "-Warc-retain-cycles"
|
205
|
-
self.completionBlock = ^ {
|
206
|
-
if ([self isCancelled]) {
|
207
|
-
return;
|
208
|
-
}
|
209
|
-
|
210
|
-
dispatch_async(image_request_operation_processing_queue(), ^(void) {
|
211
|
-
if (self.error) {
|
212
|
-
if (failure) {
|
213
|
-
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
|
214
|
-
failure(self, self.error);
|
215
|
-
});
|
216
|
-
}
|
217
|
-
} else {
|
218
|
-
if (success) {
|
219
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
220
|
-
UIImage *image = nil;
|
221
|
-
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
222
|
-
NSImage *image = nil;
|
223
|
-
#endif
|
224
|
-
|
225
|
-
image = self.responseImage;
|
226
|
-
|
227
|
-
dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
|
228
|
-
success(self, image);
|
229
|
-
});
|
230
|
-
}
|
231
|
-
}
|
232
|
-
});
|
233
|
-
};
|
234
|
-
#pragma clang diagnostic pop
|
235
|
-
}
|
236
|
-
|
237
|
-
@end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
// AFJSONRequestOperation.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 "AFHTTPRequestOperation.h"
|
25
|
-
|
26
|
-
/**
|
27
|
-
`AFJSONRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and working with JSON response data.
|
28
|
-
|
29
|
-
## Acceptable Content Types
|
30
|
-
|
31
|
-
By default, `AFJSONRequestOperation` accepts the following MIME types, which includes the official standard, `application/json`, as well as other commonly-used types:
|
32
|
-
|
33
|
-
- `application/json`
|
34
|
-
- `text/json`
|
35
|
-
|
36
|
-
@warning JSON parsing will use the built-in `NSJSONSerialization` class.
|
37
|
-
*/
|
38
|
-
@interface AFJSONRequestOperation : AFHTTPRequestOperation
|
39
|
-
|
40
|
-
///----------------------------
|
41
|
-
/// @name Getting Response Data
|
42
|
-
///----------------------------
|
43
|
-
|
44
|
-
/**
|
45
|
-
A JSON object constructed from the response data. If an error occurs while parsing, `nil` will be returned, and the `error` property will be set to the error.
|
46
|
-
*/
|
47
|
-
@property (readonly, nonatomic, strong) id responseJSON;
|
48
|
-
|
49
|
-
/**
|
50
|
-
Options for reading the response JSON data and creating the Foundation objects. For possible values, see the `NSJSONSerialization` documentation section "NSJSONReadingOptions".
|
51
|
-
*/
|
52
|
-
@property (nonatomic, assign) NSJSONReadingOptions JSONReadingOptions;
|
53
|
-
|
54
|
-
///----------------------------------
|
55
|
-
/// @name Creating Request Operations
|
56
|
-
///----------------------------------
|
57
|
-
|
58
|
-
/**
|
59
|
-
Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks.
|
60
|
-
|
61
|
-
@param urlRequest The request object to be loaded asynchronously during execution of the operation
|
62
|
-
@param success A block object to be executed when the operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the JSON object created from the response data of request.
|
63
|
-
@param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data as JSON. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred.
|
64
|
-
|
65
|
-
@return A new JSON request operation
|
66
|
-
*/
|
67
|
-
+ (AFJSONRequestOperation *)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
68
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
|
69
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON))failure;
|
70
|
-
|
71
|
-
@end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
// AFJSONRequestOperation.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 "AFJSONRequestOperation.h"
|
24
|
-
|
25
|
-
static dispatch_queue_t af_json_request_operation_processing_queue;
|
26
|
-
static dispatch_queue_t json_request_operation_processing_queue() {
|
27
|
-
if (af_json_request_operation_processing_queue == NULL) {
|
28
|
-
af_json_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.json-request.processing", 0);
|
29
|
-
}
|
30
|
-
|
31
|
-
return af_json_request_operation_processing_queue;
|
32
|
-
}
|
33
|
-
|
34
|
-
@interface AFJSONRequestOperation ()
|
35
|
-
@property (readwrite, nonatomic, strong) id responseJSON;
|
36
|
-
@property (readwrite, nonatomic, strong) NSError *JSONError;
|
37
|
-
@end
|
38
|
-
|
39
|
-
@implementation AFJSONRequestOperation
|
40
|
-
@synthesize responseJSON = _responseJSON;
|
41
|
-
@synthesize JSONReadingOptions = _JSONReadingOptions;
|
42
|
-
@synthesize JSONError = _JSONError;
|
43
|
-
|
44
|
-
+ (AFJSONRequestOperation *)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
45
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
|
46
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON))failure
|
47
|
-
{
|
48
|
-
AFJSONRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
|
49
|
-
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
50
|
-
if (success) {
|
51
|
-
success(operation.request, operation.response, responseObject);
|
52
|
-
}
|
53
|
-
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
54
|
-
if (failure) {
|
55
|
-
failure(operation.request, operation.response, error, [(AFJSONRequestOperation *)operation responseJSON]);
|
56
|
-
}
|
57
|
-
}];
|
58
|
-
|
59
|
-
return requestOperation;
|
60
|
-
}
|
61
|
-
|
62
|
-
|
63
|
-
- (id)responseJSON {
|
64
|
-
if (!_responseJSON && [self.responseData length] > 0 && [self isFinished] && !self.JSONError) {
|
65
|
-
NSError *error = nil;
|
66
|
-
|
67
|
-
if ([self.responseData length] == 0) {
|
68
|
-
self.responseJSON = nil;
|
69
|
-
} else {
|
70
|
-
self.responseJSON = [NSJSONSerialization JSONObjectWithData:self.responseData options:self.JSONReadingOptions error:&error];
|
71
|
-
}
|
72
|
-
|
73
|
-
self.JSONError = error;
|
74
|
-
}
|
75
|
-
|
76
|
-
return _responseJSON;
|
77
|
-
}
|
78
|
-
|
79
|
-
- (NSError *)error {
|
80
|
-
if (_JSONError) {
|
81
|
-
return _JSONError;
|
82
|
-
} else {
|
83
|
-
return [super error];
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
#pragma mark - AFHTTPRequestOperation
|
88
|
-
|
89
|
-
+ (NSSet *)acceptableContentTypes {
|
90
|
-
return [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
|
91
|
-
}
|
92
|
-
|
93
|
-
+ (BOOL)canProcessRequest:(NSURLRequest *)request {
|
94
|
-
return [[[request URL] pathExtension] isEqualToString:@"json"] || [super canProcessRequest:request];
|
95
|
-
}
|
96
|
-
|
97
|
-
- (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
98
|
-
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
99
|
-
{
|
100
|
-
#pragma clang diagnostic push
|
101
|
-
#pragma clang diagnostic ignored "-Warc-retain-cycles"
|
102
|
-
self.completionBlock = ^ {
|
103
|
-
if ([self isCancelled]) {
|
104
|
-
return;
|
105
|
-
}
|
106
|
-
|
107
|
-
if (self.error) {
|
108
|
-
if (failure) {
|
109
|
-
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
|
110
|
-
failure(self, self.error);
|
111
|
-
});
|
112
|
-
}
|
113
|
-
} else {
|
114
|
-
dispatch_async(json_request_operation_processing_queue(), ^{
|
115
|
-
id JSON = self.responseJSON;
|
116
|
-
|
117
|
-
if (self.JSONError) {
|
118
|
-
if (failure) {
|
119
|
-
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
|
120
|
-
failure(self, self.error);
|
121
|
-
});
|
122
|
-
}
|
123
|
-
} else {
|
124
|
-
if (success) {
|
125
|
-
dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
|
126
|
-
success(self, JSON);
|
127
|
-
});
|
128
|
-
}
|
129
|
-
}
|
130
|
-
});
|
131
|
-
}
|
132
|
-
};
|
133
|
-
#pragma clang diagnostic pop
|
134
|
-
}
|
135
|
-
|
136
|
-
@end
|