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,108 @@
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 defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
29
+ #import <UIKit/UIKit.h>
30
+ #elif defined(__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 defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
58
+ @property (readonly, nonatomic, strong) UIImage *responseImage;
59
+ #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
60
+ @property (readonly, nonatomic, strong) NSImage *responseImage;
61
+ #endif
62
+
63
+ #if defined(__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 defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
79
+ + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
80
+ success:(void (^)(UIImage *image))success;
81
+ #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
82
+ + (instancetype)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 defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
97
+ + (instancetype)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 defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
102
+ + (instancetype)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
@@ -0,0 +1,234 @@
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 image_request_operation_processing_queue() {
26
+ static dispatch_queue_t af_image_request_operation_processing_queue;
27
+ static dispatch_once_t onceToken;
28
+ dispatch_once(&onceToken, ^{
29
+ af_image_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.image-request.processing", DISPATCH_QUEUE_CONCURRENT);
30
+ });
31
+
32
+ return af_image_request_operation_processing_queue;
33
+ }
34
+
35
+ @interface AFImageRequestOperation ()
36
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
37
+ @property (readwrite, nonatomic, strong) UIImage *responseImage;
38
+ #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
39
+ @property (readwrite, nonatomic, strong) NSImage *responseImage;
40
+ #endif
41
+ @end
42
+
43
+ @implementation AFImageRequestOperation
44
+ @synthesize responseImage = _responseImage;
45
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
46
+ @synthesize imageScale = _imageScale;
47
+ #endif
48
+
49
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
50
+ + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
51
+ success:(void (^)(UIImage *image))success
52
+ {
53
+ return [self imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, UIImage *image) {
54
+ if (success) {
55
+ success(image);
56
+ }
57
+ } failure:nil];
58
+ }
59
+ #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
60
+ + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
61
+ success:(void (^)(NSImage *image))success
62
+ {
63
+ return [self imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, NSImage *image) {
64
+ if (success) {
65
+ success(image);
66
+ }
67
+ } failure:nil];
68
+ }
69
+ #endif
70
+
71
+
72
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
73
+ + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
74
+ imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock
75
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
76
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
77
+ {
78
+ AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
79
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
80
+ if (success) {
81
+ UIImage *image = responseObject;
82
+ if (imageProcessingBlock) {
83
+ dispatch_async(image_request_operation_processing_queue(), ^(void) {
84
+ UIImage *processedImage = imageProcessingBlock(image);
85
+
86
+ dispatch_async(operation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
87
+ success(operation.request, operation.response, processedImage);
88
+ });
89
+ });
90
+ } else {
91
+ success(operation.request, operation.response, image);
92
+ }
93
+ }
94
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
95
+ if (failure) {
96
+ failure(operation.request, operation.response, error);
97
+ }
98
+ }];
99
+
100
+
101
+ return requestOperation;
102
+ }
103
+ #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
104
+ + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
105
+ imageProcessingBlock:(NSImage *(^)(NSImage *))imageProcessingBlock
106
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success
107
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
108
+ {
109
+ AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
110
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
111
+ if (success) {
112
+ NSImage *image = responseObject;
113
+ if (imageProcessingBlock) {
114
+ dispatch_async(image_request_operation_processing_queue(), ^(void) {
115
+ NSImage *processedImage = imageProcessingBlock(image);
116
+
117
+ dispatch_async(operation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
118
+ success(operation.request, operation.response, processedImage);
119
+ });
120
+ });
121
+ } else {
122
+ success(operation.request, operation.response, image);
123
+ }
124
+ }
125
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
126
+ if (failure) {
127
+ failure(operation.request, operation.response, error);
128
+ }
129
+ }];
130
+
131
+ return requestOperation;
132
+ }
133
+ #endif
134
+
135
+ - (id)initWithRequest:(NSURLRequest *)urlRequest {
136
+ self = [super initWithRequest:urlRequest];
137
+ if (!self) {
138
+ return nil;
139
+ }
140
+
141
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
142
+ self.imageScale = [[UIScreen mainScreen] scale];
143
+ #endif
144
+
145
+ return self;
146
+ }
147
+
148
+
149
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
150
+ - (UIImage *)responseImage {
151
+ if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) {
152
+ UIImage *image = [UIImage imageWithData:self.responseData];
153
+
154
+ self.responseImage = [UIImage imageWithCGImage:[image CGImage] scale:self.imageScale orientation:image.imageOrientation];
155
+ }
156
+
157
+ return _responseImage;
158
+ }
159
+
160
+ - (void)setImageScale:(CGFloat)imageScale {
161
+ #pragma clang diagnostic push
162
+ #pragma clang diagnostic ignored "-Wfloat-equal"
163
+ if (imageScale == _imageScale) {
164
+ return;
165
+ }
166
+ #pragma clang diagnostic pop
167
+
168
+ _imageScale = imageScale;
169
+
170
+ self.responseImage = nil;
171
+ }
172
+ #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
173
+ - (NSImage *)responseImage {
174
+ if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) {
175
+ // Ensure that the image is set to it's correct pixel width and height
176
+ NSBitmapImageRep *bitimage = [[NSBitmapImageRep alloc] initWithData:self.responseData];
177
+ self.responseImage = [[NSImage alloc] initWithSize:NSMakeSize([bitimage pixelsWide], [bitimage pixelsHigh])];
178
+ [self.responseImage addRepresentation:bitimage];
179
+ }
180
+
181
+ return _responseImage;
182
+ }
183
+ #endif
184
+
185
+ #pragma mark - AFHTTPRequestOperation
186
+
187
+ + (NSSet *)acceptableContentTypes {
188
+ 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];
189
+ }
190
+
191
+ + (BOOL)canProcessRequest:(NSURLRequest *)request {
192
+ static NSSet * _acceptablePathExtension = nil;
193
+ static dispatch_once_t onceToken;
194
+ dispatch_once(&onceToken, ^{
195
+ _acceptablePathExtension = [[NSSet alloc] initWithObjects:@"tif", @"tiff", @"jpg", @"jpeg", @"gif", @"png", @"ico", @"bmp", @"cur", nil];
196
+ });
197
+
198
+ return [_acceptablePathExtension containsObject:[[request URL] pathExtension]] || [super canProcessRequest:request];
199
+ }
200
+
201
+ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
202
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
203
+ {
204
+ #pragma clang diagnostic push
205
+ #pragma clang diagnostic ignored "-Warc-retain-cycles"
206
+ self.completionBlock = ^ {
207
+ dispatch_async(image_request_operation_processing_queue(), ^(void) {
208
+ if (self.error) {
209
+ if (failure) {
210
+ dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
211
+ failure(self, self.error);
212
+ });
213
+ }
214
+ } else {
215
+ if (success) {
216
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
217
+ UIImage *image = nil;
218
+ #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
219
+ NSImage *image = nil;
220
+ #endif
221
+
222
+ image = self.responseImage;
223
+
224
+ dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
225
+ success(self, image);
226
+ });
227
+ }
228
+ }
229
+ });
230
+ };
231
+ #pragma clang diagnostic pop
232
+ }
233
+
234
+ @end
@@ -0,0 +1,71 @@
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
+ + (instancetype)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
@@ -0,0 +1,142 @@
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 json_request_operation_processing_queue() {
26
+ static dispatch_queue_t af_json_request_operation_processing_queue;
27
+ static dispatch_once_t onceToken;
28
+ dispatch_once(&onceToken, ^{
29
+ af_json_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.json-request.processing", DISPATCH_QUEUE_CONCURRENT);
30
+ });
31
+
32
+ return af_json_request_operation_processing_queue;
33
+ }
34
+
35
+ @interface AFJSONRequestOperation ()
36
+ @property (readwrite, nonatomic, strong) id responseJSON;
37
+ @property (readwrite, nonatomic, strong) NSError *JSONError;
38
+ @property (readwrite, nonatomic, strong) NSRecursiveLock *lock;
39
+ @end
40
+
41
+ @implementation AFJSONRequestOperation
42
+ @synthesize responseJSON = _responseJSON;
43
+ @synthesize JSONReadingOptions = _JSONReadingOptions;
44
+ @synthesize JSONError = _JSONError;
45
+ @dynamic lock;
46
+
47
+ + (instancetype)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest
48
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
49
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON))failure
50
+ {
51
+ AFJSONRequestOperation *requestOperation = [(AFJSONRequestOperation *)[self alloc] initWithRequest:urlRequest];
52
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
53
+ if (success) {
54
+ success(operation.request, operation.response, responseObject);
55
+ }
56
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
57
+ if (failure) {
58
+ failure(operation.request, operation.response, error, [(AFJSONRequestOperation *)operation responseJSON]);
59
+ }
60
+ }];
61
+
62
+ return requestOperation;
63
+ }
64
+
65
+
66
+ - (id)responseJSON {
67
+ [self.lock lock];
68
+ if (!_responseJSON && [self.responseData length] > 0 && [self isFinished] && !self.JSONError) {
69
+ NSError *error = nil;
70
+
71
+ // Workaround for behavior of Rails to return a single space for `head :ok` (a workaround for a bug in Safari), which is not interpreted as valid input by NSJSONSerialization.
72
+ // See https://github.com/rails/rails/issues/1742
73
+ if ([self.responseData length] == 0 || [self.responseString isEqualToString:@" "]) {
74
+ self.responseJSON = nil;
75
+ } else {
76
+ // Workaround for a bug in NSJSONSerialization when Unicode character escape codes are used instead of the actual character
77
+ // See http://stackoverflow.com/a/12843465/157142
78
+ NSData *JSONData = [self.responseString dataUsingEncoding:self.responseStringEncoding];
79
+ self.responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:self.JSONReadingOptions error:&error];
80
+ }
81
+
82
+ self.JSONError = error;
83
+ }
84
+ [self.lock unlock];
85
+
86
+ return _responseJSON;
87
+ }
88
+
89
+ - (NSError *)error {
90
+ if (_JSONError) {
91
+ return _JSONError;
92
+ } else {
93
+ return [super error];
94
+ }
95
+ }
96
+
97
+ #pragma mark - AFHTTPRequestOperation
98
+
99
+ + (NSSet *)acceptableContentTypes {
100
+ return [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
101
+ }
102
+
103
+ + (BOOL)canProcessRequest:(NSURLRequest *)request {
104
+ return [[[request URL] pathExtension] isEqualToString:@"json"] || [super canProcessRequest:request];
105
+ }
106
+
107
+ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
108
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
109
+ {
110
+ #pragma clang diagnostic push
111
+ #pragma clang diagnostic ignored "-Warc-retain-cycles"
112
+ self.completionBlock = ^ {
113
+ if (self.error) {
114
+ if (failure) {
115
+ dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
116
+ failure(self, self.error);
117
+ });
118
+ }
119
+ } else {
120
+ dispatch_async(json_request_operation_processing_queue(), ^{
121
+ id JSON = self.responseJSON;
122
+
123
+ if (self.JSONError) {
124
+ if (failure) {
125
+ dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
126
+ failure(self, self.error);
127
+ });
128
+ }
129
+ } else {
130
+ if (success) {
131
+ dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
132
+ success(self, JSON);
133
+ });
134
+ }
135
+ }
136
+ });
137
+ }
138
+ };
139
+ #pragma clang diagnostic pop
140
+ }
141
+
142
+ @end