afmotion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/.gitignore +16 -0
  2. data/AFMotion.gemspec +19 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +53 -0
  5. data/README.md +135 -0
  6. data/Rakefile +14 -0
  7. data/app/app_delegate.rb +6 -0
  8. data/examples/AppDotNet/.gitignore +13 -0
  9. data/examples/AppDotNet/Gemfile +4 -0
  10. data/examples/AppDotNet/Gemfile.lock +48 -0
  11. data/examples/AppDotNet/Rakefile +10 -0
  12. data/examples/AppDotNet/app/app_delegate.rb +28 -0
  13. data/examples/AppDotNet/app/global_timeline_view_controller.rb +84 -0
  14. data/examples/AppDotNet/app/post.rb +23 -0
  15. data/examples/AppDotNet/app/post_table_view_cell.rb +44 -0
  16. data/examples/AppDotNet/app/user.rb +9 -0
  17. data/examples/AppDotNet/resources/profile-image-placeholder.png +0 -0
  18. data/examples/AppDotNet/resources/profile-image-placeholder@2x.png +0 -0
  19. data/examples/AppDotNet/spec/main_spec.rb +9 -0
  20. data/examples/AppDotNet/vendor/Podfile.lock +11 -0
  21. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +574 -0
  22. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1187 -0
  23. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
  24. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +341 -0
  25. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +108 -0
  26. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +237 -0
  27. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
  28. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +136 -0
  29. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  30. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +131 -0
  31. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +44 -0
  32. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  33. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +145 -0
  34. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +295 -0
  35. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +652 -0
  36. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
  37. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +169 -0
  38. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
  39. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +180 -0
  40. data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking.podspec +28 -0
  41. data/examples/AppDotNet/vendor/Pods/AFNetworking/LICENSE +19 -0
  42. data/examples/AppDotNet/vendor/Pods/AFNetworking/README.md +179 -0
  43. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +574 -0
  44. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
  45. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +108 -0
  46. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
  47. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  48. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +44 -0
  49. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  50. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +295 -0
  51. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
  52. data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
  53. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +574 -0
  54. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
  55. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +108 -0
  56. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
  57. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  58. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworking.h +44 -0
  59. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  60. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +295 -0
  61. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
  62. data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
  63. data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.markdown +26 -0
  64. data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.plist +56 -0
  65. data/examples/AppDotNet/vendor/Pods/Pods-prefix.pch +12 -0
  66. data/examples/AppDotNet/vendor/Pods/Pods-resources.sh +19 -0
  67. data/examples/AppDotNet/vendor/Pods/Pods.bridgesupport +617 -0
  68. data/examples/AppDotNet/vendor/Pods/Pods.xcconfig +7 -0
  69. data/examples/AppDotNet/vendor/Pods/Pods.xcodeproj/project.pbxproj +998 -0
  70. data/examples/AppDotNet/vendor/Pods/PodsDummy_Pods.m +4 -0
  71. data/lib/afmotion/http.rb +55 -0
  72. data/lib/afmotion/http_client.rb +121 -0
  73. data/lib/afmotion/http_result.rb +25 -0
  74. data/lib/afmotion/image.rb +10 -0
  75. data/lib/afmotion/operation.rb +65 -0
  76. data/lib/afmotion/patch/NSString_NSUrl.rb +11 -0
  77. data/lib/afmotion/version.rb +5 -0
  78. data/lib/afmotion.rb +16 -0
  79. data/pkg/afmotion-0.0.1.gem +0 -0
  80. data/spec/http_client_spec.rb +104 -0
  81. data/spec/http_spec.rb +26 -0
  82. data/spec/operation_spec.rb +41 -0
  83. data/vendor/Podfile.lock +11 -0
  84. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +574 -0
  85. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1187 -0
  86. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
  87. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +341 -0
  88. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +108 -0
  89. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +237 -0
  90. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
  91. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +136 -0
  92. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  93. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +131 -0
  94. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +44 -0
  95. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  96. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +145 -0
  97. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +295 -0
  98. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +652 -0
  99. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
  100. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +169 -0
  101. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
  102. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +180 -0
  103. data/vendor/Pods/AFNetworking/AFNetworking.podspec +28 -0
  104. data/vendor/Pods/AFNetworking/LICENSE +19 -0
  105. data/vendor/Pods/AFNetworking/README.md +179 -0
  106. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +574 -0
  107. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
  108. data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +108 -0
  109. data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
  110. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  111. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +44 -0
  112. data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  113. data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +295 -0
  114. data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
  115. data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
  116. data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +574 -0
  117. data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
  118. data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +108 -0
  119. data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
  120. data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  121. data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +44 -0
  122. data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  123. data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +295 -0
  124. data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
  125. data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
  126. data/vendor/Pods/Pods-Acknowledgements.markdown +26 -0
  127. data/vendor/Pods/Pods-Acknowledgements.plist +56 -0
  128. data/vendor/Pods/Pods-prefix.pch +12 -0
  129. data/vendor/Pods/Pods-resources.sh +19 -0
  130. data/vendor/Pods/Pods.bridgesupport +617 -0
  131. data/vendor/Pods/Pods.xcconfig +7 -0
  132. data/vendor/Pods/PodsDummy_Pods.m +4 -0
  133. metadata +218 -0
@@ -0,0 +1,89 @@
1
+ // AFXMLRequestOperation.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
+ /**
29
+ `AFXMLRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and working with XML response data.
30
+
31
+ ## Acceptable Content Types
32
+
33
+ By default, `AFXMLRequestOperation` accepts the following MIME types, which includes the official standard, `application/xml`, as well as other commonly-used types:
34
+
35
+ - `application/xml`
36
+ - `text/xml`
37
+
38
+ ## Use With AFHTTPClient
39
+
40
+ When `AFXMLRequestOperation` is registered with `AFHTTPClient`, the response object in the success callback of `HTTPRequestOperationWithRequest:success:failure:` will be an instance of `NSXMLParser`. On platforms that support `NSXMLDocument`, you have the option to ignore the response object, and simply use the `responseXMLDocument` property of the operation argument of the callback.
41
+ */
42
+ @interface AFXMLRequestOperation : AFHTTPRequestOperation
43
+
44
+ ///----------------------------
45
+ /// @name Getting Response Data
46
+ ///----------------------------
47
+
48
+ /**
49
+ An `NSXMLParser` object constructed from the response data.
50
+ */
51
+ @property (readonly, nonatomic, strong) NSXMLParser *responseXMLParser;
52
+
53
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
54
+ /**
55
+ An `NSXMLDocument` 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.
56
+ */
57
+ @property (readonly, nonatomic, strong) NSXMLDocument *responseXMLDocument;
58
+ #endif
59
+
60
+ /**
61
+ Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks.
62
+
63
+ @param urlRequest The request object to be loaded asynchronously during execution of the operation
64
+ @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 XML parser constructed with the response data of request.
65
+ @param failure A block object to be executed when the operation finishes unsuccessfully. 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 error that occurred.
66
+
67
+ @return A new XML request operation
68
+ */
69
+ + (AFXMLRequestOperation *)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest
70
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
71
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure;
72
+
73
+
74
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
75
+ /**
76
+ Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks.
77
+
78
+ @param urlRequest The request object to be loaded asynchronously during execution of the operation
79
+ @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 XML document created from the response data of request.
80
+ @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 XML. 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.
81
+
82
+ @return A new XML request operation
83
+ */
84
+ + (AFXMLRequestOperation *)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest
85
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success
86
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure;
87
+ #endif
88
+
89
+ @end
@@ -0,0 +1,169 @@
1
+ // AFXMLRequestOperation.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 "AFXMLRequestOperation.h"
24
+
25
+ #include <Availability.h>
26
+
27
+ static dispatch_queue_t af_xml_request_operation_processing_queue;
28
+ static dispatch_queue_t xml_request_operation_processing_queue() {
29
+ if (af_xml_request_operation_processing_queue == NULL) {
30
+ af_xml_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.xml-request.processing", 0);
31
+ }
32
+
33
+ return af_xml_request_operation_processing_queue;
34
+ }
35
+
36
+ @interface AFXMLRequestOperation ()
37
+ @property (readwrite, nonatomic, strong) NSXMLParser *responseXMLParser;
38
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
39
+ @property (readwrite, nonatomic, strong) NSXMLDocument *responseXMLDocument;
40
+ #endif
41
+ @property (readwrite, nonatomic, strong) NSError *XMLError;
42
+ @end
43
+
44
+ @implementation AFXMLRequestOperation
45
+ @synthesize responseXMLParser = _responseXMLParser;
46
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
47
+ @synthesize responseXMLDocument = _responseXMLDocument;
48
+ #endif
49
+ @synthesize XMLError = _XMLError;
50
+
51
+ + (AFXMLRequestOperation *)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest
52
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
53
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure
54
+ {
55
+ AFXMLRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
56
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
57
+ if (success) {
58
+ success(operation.request, operation.response, responseObject);
59
+ }
60
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
61
+ if (failure) {
62
+ failure(operation.request, operation.response, error, [(AFXMLRequestOperation *)operation responseXMLParser]);
63
+ }
64
+ }];
65
+
66
+ return requestOperation;
67
+ }
68
+
69
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
70
+ + (AFXMLRequestOperation *)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest
71
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success
72
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure
73
+ {
74
+ AFXMLRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
75
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, __unused id responseObject) {
76
+ if (success) {
77
+ NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument];
78
+ success(operation.request, operation.response, XMLDocument);
79
+ }
80
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
81
+ if (failure) {
82
+ NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument];
83
+ failure(operation.request, operation.response, error, XMLDocument);
84
+ }
85
+ }];
86
+
87
+ return requestOperation;
88
+ }
89
+ #endif
90
+
91
+
92
+ - (NSXMLParser *)responseXMLParser {
93
+ if (!_responseXMLParser && [self.responseData length] > 0 && [self isFinished]) {
94
+ self.responseXMLParser = [[NSXMLParser alloc] initWithData:self.responseData];
95
+ }
96
+
97
+ return _responseXMLParser;
98
+ }
99
+
100
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
101
+ - (NSXMLDocument *)responseXMLDocument {
102
+ if (!_responseXMLDocument && [self.responseData length] > 0 && [self isFinished]) {
103
+ NSError *error = nil;
104
+ self.responseXMLDocument = [[NSXMLDocument alloc] initWithData:self.responseData options:0 error:&error];
105
+ self.XMLError = error;
106
+ }
107
+
108
+ return _responseXMLDocument;
109
+ }
110
+ #endif
111
+
112
+ - (NSError *)error {
113
+ if (_XMLError) {
114
+ return _XMLError;
115
+ } else {
116
+ return [super error];
117
+ }
118
+ }
119
+
120
+ #pragma mark - NSOperation
121
+
122
+ - (void)cancel {
123
+ [super cancel];
124
+
125
+ self.responseXMLParser.delegate = nil;
126
+ }
127
+
128
+ #pragma mark - AFHTTPRequestOperation
129
+
130
+ + (NSSet *)acceptableContentTypes {
131
+ return [NSSet setWithObjects:@"application/xml", @"text/xml", nil];
132
+ }
133
+
134
+ + (BOOL)canProcessRequest:(NSURLRequest *)request {
135
+ return [[[request URL] pathExtension] isEqualToString:@"xml"] || [super canProcessRequest:request];
136
+ }
137
+
138
+ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
139
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
140
+ {
141
+ #pragma clang diagnostic push
142
+ #pragma clang diagnostic ignored "-Warc-retain-cycles"
143
+ self.completionBlock = ^ {
144
+ if ([self isCancelled]) {
145
+ return;
146
+ }
147
+
148
+ dispatch_async(xml_request_operation_processing_queue(), ^(void) {
149
+ NSXMLParser *XMLParser = self.responseXMLParser;
150
+
151
+ if (self.error) {
152
+ if (failure) {
153
+ dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
154
+ failure(self, self.error);
155
+ });
156
+ }
157
+ } else {
158
+ if (success) {
159
+ dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
160
+ success(self, XMLParser);
161
+ });
162
+ }
163
+ }
164
+ });
165
+ };
166
+ #pragma clang diagnostic pop
167
+ }
168
+
169
+ @end
@@ -0,0 +1,78 @@
1
+ // UIImageView+AFNetworking.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 "AFImageRequestOperation.h"
25
+
26
+ #import <Availability.h>
27
+
28
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED
29
+ #import <UIKit/UIKit.h>
30
+
31
+ /**
32
+ This category adds methods to the UIKit framework's `UIImageView` class. The methods in this category provide support for loading remote images asynchronously from a URL.
33
+ */
34
+ @interface UIImageView (AFNetworking)
35
+
36
+ /**
37
+ Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL, and sets it the request is finished. Any previous image request for the receiver will be cancelled. If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
38
+
39
+ @discussion By default, URL requests have a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:`
40
+
41
+ @param url The URL used for the image request.
42
+ */
43
+ - (void)setImageWithURL:(NSURL *)url;
44
+
45
+ /**
46
+ Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL. Any previous image request for the receiver will be cancelled. If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
47
+
48
+ @param url The URL used for the image request.
49
+ @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
50
+
51
+ @discussion By default, URL requests have a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:`
52
+ */
53
+ - (void)setImageWithURL:(NSURL *)url
54
+ placeholderImage:(UIImage *)placeholderImage;
55
+
56
+ /**
57
+ Creates and enqueues an image request operation, which asynchronously downloads the image with the specified URL request object. Any previous image request for the receiver will be cancelled. If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
58
+
59
+ @param urlRequest The URL request used for the image request.
60
+ @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
61
+ @param success A block to be executed when the image request operation 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 sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the request and response parameters will be `nil`.
62
+ @param failure A block object to be executed when the image request operation finishes unsuccessfully, or that 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 error object describing the network or parsing error that occurred.
63
+
64
+ @discussion If a success block is specified, it is the responsibility of the block to set the image of the image view before returning. If no success block is specified, the default behavior of setting the image with `self.image = image` is executed.
65
+ */
66
+ - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
67
+ placeholderImage:(UIImage *)placeholderImage
68
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
69
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
70
+
71
+ /**
72
+ Cancels any executing image request operation for the receiver, if one exists.
73
+ */
74
+ - (void)cancelImageRequestOperation;
75
+
76
+ @end
77
+
78
+ #endif
@@ -0,0 +1,180 @@
1
+ // UIImageView+AFNetworking.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 <Foundation/Foundation.h>
24
+ #import <objc/runtime.h>
25
+
26
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED
27
+ #import "UIImageView+AFNetworking.h"
28
+
29
+ @interface AFImageCache : NSCache
30
+ - (UIImage *)cachedImageForRequest:(NSURLRequest *)request;
31
+ - (void)cacheImage:(UIImage *)image
32
+ forRequest:(NSURLRequest *)request;
33
+ @end
34
+
35
+ #pragma mark -
36
+
37
+ static char kAFImageRequestOperationObjectKey;
38
+
39
+ @interface UIImageView (_AFNetworking)
40
+ @property (readwrite, nonatomic, strong, setter = af_setImageRequestOperation:) AFImageRequestOperation *af_imageRequestOperation;
41
+ @end
42
+
43
+ @implementation UIImageView (_AFNetworking)
44
+ @dynamic af_imageRequestOperation;
45
+ @end
46
+
47
+ #pragma mark -
48
+
49
+ @implementation UIImageView (AFNetworking)
50
+
51
+ - (AFHTTPRequestOperation *)af_imageRequestOperation {
52
+ return (AFHTTPRequestOperation *)objc_getAssociatedObject(self, &kAFImageRequestOperationObjectKey);
53
+ }
54
+
55
+ - (void)af_setImageRequestOperation:(AFImageRequestOperation *)imageRequestOperation {
56
+ objc_setAssociatedObject(self, &kAFImageRequestOperationObjectKey, imageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
57
+ }
58
+
59
+ + (NSOperationQueue *)af_sharedImageRequestOperationQueue {
60
+ static NSOperationQueue *_af_imageRequestOperationQueue = nil;
61
+ static dispatch_once_t onceToken;
62
+ dispatch_once(&onceToken, ^{
63
+ _af_imageRequestOperationQueue = [[NSOperationQueue alloc] init];
64
+ [_af_imageRequestOperationQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];
65
+ });
66
+
67
+ return _af_imageRequestOperationQueue;
68
+ }
69
+
70
+ + (AFImageCache *)af_sharedImageCache {
71
+ static AFImageCache *_af_imageCache = nil;
72
+ static dispatch_once_t oncePredicate;
73
+ dispatch_once(&oncePredicate, ^{
74
+ _af_imageCache = [[AFImageCache alloc] init];
75
+ });
76
+
77
+ return _af_imageCache;
78
+ }
79
+
80
+ #pragma mark -
81
+
82
+ - (void)setImageWithURL:(NSURL *)url {
83
+ [self setImageWithURL:url placeholderImage:nil];
84
+ }
85
+
86
+ - (void)setImageWithURL:(NSURL *)url
87
+ placeholderImage:(UIImage *)placeholderImage
88
+ {
89
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
90
+ [request setHTTPShouldHandleCookies:NO];
91
+ [request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
92
+
93
+ [self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil];
94
+ }
95
+
96
+ - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
97
+ placeholderImage:(UIImage *)placeholderImage
98
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
99
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
100
+ {
101
+ [self cancelImageRequestOperation];
102
+
103
+ UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
104
+ if (cachedImage) {
105
+ self.image = cachedImage;
106
+ self.af_imageRequestOperation = nil;
107
+
108
+ if (success) {
109
+ success(nil, nil, cachedImage);
110
+ }
111
+ } else {
112
+ self.image = placeholderImage;
113
+
114
+ AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
115
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
116
+ if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
117
+ if (success) {
118
+ success(operation.request, operation.response, responseObject);
119
+ } else {
120
+ self.image = responseObject;
121
+ }
122
+
123
+ self.af_imageRequestOperation = nil;
124
+ }
125
+
126
+ [[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
127
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
128
+ if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
129
+ if (failure) {
130
+ failure(operation.request, operation.response, error);
131
+ }
132
+
133
+ self.af_imageRequestOperation = nil;
134
+ }
135
+ }];
136
+
137
+ self.af_imageRequestOperation = requestOperation;
138
+
139
+ [[[self class] af_sharedImageRequestOperationQueue] addOperation:self.af_imageRequestOperation];
140
+ }
141
+ }
142
+
143
+ - (void)cancelImageRequestOperation {
144
+ [self.af_imageRequestOperation cancel];
145
+ self.af_imageRequestOperation = nil;
146
+ }
147
+
148
+ @end
149
+
150
+ #pragma mark -
151
+
152
+ static inline NSString * AFImageCacheKeyFromURLRequest(NSURLRequest *request) {
153
+ return [[request URL] absoluteString];
154
+ }
155
+
156
+ @implementation AFImageCache
157
+
158
+ - (UIImage *)cachedImageForRequest:(NSURLRequest *)request {
159
+ switch ([request cachePolicy]) {
160
+ case NSURLRequestReloadIgnoringCacheData:
161
+ case NSURLRequestReloadIgnoringLocalAndRemoteCacheData:
162
+ return nil;
163
+ default:
164
+ break;
165
+ }
166
+
167
+ return [self objectForKey:AFImageCacheKeyFromURLRequest(request)];
168
+ }
169
+
170
+ - (void)cacheImage:(UIImage *)image
171
+ forRequest:(NSURLRequest *)request
172
+ {
173
+ if (image && request) {
174
+ [self setObject:image forKey:AFImageCacheKeyFromURLRequest(request)];
175
+ }
176
+ }
177
+
178
+ @end
179
+
180
+ #endif
@@ -0,0 +1,28 @@
1
+ Pod::Spec.new do |s|
2
+ s.name = 'AFNetworking'
3
+ s.version = '1.0'
4
+ s.license = 'MIT'
5
+ s.summary = 'A delightful iOS and OS X networking framework.'
6
+ s.homepage = 'https://github.com/AFNetworking/AFNetworking'
7
+ s.authors = { 'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@gowalla.com' }
8
+ s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '1.0' }
9
+ s.source_files = 'AFNetworking'
10
+ s.requires_arc = true
11
+
12
+ s.ios.deployment_target = '5.0'
13
+ s.ios.frameworks = 'MobileCoreServices', 'SystemConfiguration'
14
+
15
+ s.osx.deployment_target = '10.7'
16
+ s.osx.frameworks = 'CoreServices', 'SystemConfiguration'
17
+
18
+ s.prefix_header_contents = <<-EOS
19
+ #import <Availability.h>
20
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED
21
+ #import <SystemConfiguration/SystemConfiguration.h>
22
+ #import <MobileCoreServices/MobileCoreServices.h>
23
+ #else
24
+ #import <SystemConfiguration/SystemConfiguration.h>
25
+ #import <CoreServices/CoreServices.h>
26
+ #endif
27
+ EOS
28
+ end
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Gowalla (http://gowalla.com/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.