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,44 @@
1
+ // 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 <Availability.h>
25
+
26
+ #ifndef _AFNETWORKING_
27
+ #define _AFNETWORKING_
28
+
29
+ #import "AFURLConnectionOperation.h"
30
+
31
+ #import "AFHTTPRequestOperation.h"
32
+ #import "AFJSONRequestOperation.h"
33
+ #import "AFXMLRequestOperation.h"
34
+ #import "AFPropertyListRequestOperation.h"
35
+ #import "AFHTTPClient.h"
36
+
37
+ #import "AFImageRequestOperation.h"
38
+
39
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED
40
+ #import "AFNetworkActivityIndicatorManager.h"
41
+ #import "UIImageView+AFNetworking.h"
42
+ #endif
43
+
44
+ #endif /* _AFNETWORKING_ */
@@ -0,0 +1,68 @@
1
+ // AFPropertyListRequestOperation.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
+ `AFPropertyListRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and deserializing objects with property list (plist) response data.
28
+
29
+ ## Acceptable Content Types
30
+
31
+ By default, `AFPropertyListRequestOperation` accepts the following MIME types:
32
+
33
+ - `application/x-plist`
34
+ */
35
+ @interface AFPropertyListRequestOperation : AFHTTPRequestOperation
36
+
37
+ ///----------------------------
38
+ /// @name Getting Response Data
39
+ ///----------------------------
40
+
41
+ /**
42
+ An object deserialized from a plist constructed using the response data.
43
+ */
44
+ @property (readonly, nonatomic) id responsePropertyList;
45
+
46
+ ///--------------------------------------
47
+ /// @name Managing Property List Behavior
48
+ ///--------------------------------------
49
+
50
+ /**
51
+ One of the `NSPropertyListMutabilityOptions` options, specifying the mutability of objects deserialized from the property list. By default, this is `NSPropertyListImmutable`.
52
+ */
53
+ @property (nonatomic, assign) NSPropertyListReadOptions propertyListReadOptions;
54
+
55
+ /**
56
+ Creates and returns an `AFPropertyListRequestOperation` object and sets the specified success and failure callbacks.
57
+
58
+ @param urlRequest The request object to be loaded asynchronously during execution of the operation
59
+ @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 object deserialized from a plist constructed using the response data.
60
+ @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while deserializing the object from a property list. 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.
61
+
62
+ @return A new property list request operation
63
+ */
64
+ + (AFPropertyListRequestOperation *)propertyListRequestOperationWithRequest:(NSURLRequest *)urlRequest
65
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList))success
66
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id propertyList))failure;
67
+
68
+ @end
@@ -0,0 +1,145 @@
1
+ // AFPropertyListRequestOperation.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 "AFPropertyListRequestOperation.h"
24
+
25
+ static dispatch_queue_t af_property_list_request_operation_processing_queue;
26
+ static dispatch_queue_t property_list_request_operation_processing_queue() {
27
+ if (af_property_list_request_operation_processing_queue == NULL) {
28
+ af_property_list_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.property-list-request.processing", 0);
29
+ }
30
+
31
+ return af_property_list_request_operation_processing_queue;
32
+ }
33
+
34
+ @interface AFPropertyListRequestOperation ()
35
+ @property (readwrite, nonatomic) id responsePropertyList;
36
+ @property (readwrite, nonatomic, assign) NSPropertyListFormat propertyListFormat;
37
+ @property (readwrite, nonatomic) NSError *propertyListError;
38
+ @end
39
+
40
+ @implementation AFPropertyListRequestOperation
41
+ @synthesize responsePropertyList = _responsePropertyList;
42
+ @synthesize propertyListReadOptions = _propertyListReadOptions;
43
+ @synthesize propertyListFormat = _propertyListFormat;
44
+ @synthesize propertyListError = _propertyListError;
45
+
46
+ + (AFPropertyListRequestOperation *)propertyListRequestOperationWithRequest:(NSURLRequest *)request
47
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList))success
48
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id propertyList))failure
49
+ {
50
+ AFPropertyListRequestOperation *requestOperation = [[self alloc] initWithRequest:request];
51
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
52
+ if (success) {
53
+ success(operation.request, operation.response, responseObject);
54
+ }
55
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
56
+ if (failure) {
57
+ failure(operation.request, operation.response, error, [(AFPropertyListRequestOperation *)operation responsePropertyList]);
58
+ }
59
+ }];
60
+
61
+ return requestOperation;
62
+ }
63
+
64
+ - (id)initWithRequest:(NSURLRequest *)urlRequest {
65
+ self = [super initWithRequest:urlRequest];
66
+ if (!self) {
67
+ return nil;
68
+ }
69
+
70
+ self.propertyListReadOptions = NSPropertyListImmutable;
71
+
72
+ return self;
73
+ }
74
+
75
+
76
+ - (id)responsePropertyList {
77
+ if (!_responsePropertyList && [self.responseData length] > 0 && [self isFinished]) {
78
+ NSPropertyListFormat format;
79
+ NSError *error = nil;
80
+ self.responsePropertyList = [NSPropertyListSerialization propertyListWithData:self.responseData options:self.propertyListReadOptions format:&format error:&error];
81
+ self.propertyListFormat = format;
82
+ self.propertyListError = error;
83
+ }
84
+
85
+ return _responsePropertyList;
86
+ }
87
+
88
+ - (NSError *)error {
89
+ if (_propertyListError) {
90
+ return _propertyListError;
91
+ } else {
92
+ return [super error];
93
+ }
94
+ }
95
+
96
+ #pragma mark - AFHTTPRequestOperation
97
+
98
+ + (NSSet *)acceptableContentTypes {
99
+ return [NSSet setWithObjects:@"application/x-plist", nil];
100
+ }
101
+
102
+ + (BOOL)canProcessRequest:(NSURLRequest *)request {
103
+ return [[[request URL] pathExtension] isEqualToString:@"plist"] || [super canProcessRequest:request];
104
+ }
105
+
106
+ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
107
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
108
+ {
109
+ #pragma clang diagnostic push
110
+ #pragma clang diagnostic ignored "-Warc-retain-cycles"
111
+ self.completionBlock = ^ {
112
+ if ([self isCancelled]) {
113
+ return;
114
+ }
115
+
116
+ if (self.error) {
117
+ if (failure) {
118
+ dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
119
+ failure(self, self.error);
120
+ });
121
+ }
122
+ } else {
123
+ dispatch_async(property_list_request_operation_processing_queue(), ^(void) {
124
+ id propertyList = self.responsePropertyList;
125
+
126
+ if (self.propertyListError) {
127
+ if (failure) {
128
+ dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
129
+ failure(self, self.error);
130
+ });
131
+ }
132
+ } else {
133
+ if (success) {
134
+ dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
135
+ success(self, propertyList);
136
+ });
137
+ }
138
+ }
139
+ });
140
+ }
141
+ };
142
+ #pragma clang diagnostic pop
143
+ }
144
+
145
+ @end
@@ -0,0 +1,295 @@
1
+ // AFURLConnectionOperation.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
+
25
+ #import <Availability.h>
26
+
27
+ /**
28
+ `AFURLConnectionOperation` is a subclass of `NSOperation` that implements `NSURLConnection` delegate methods.
29
+
30
+ ## Subclassing Notes
31
+
32
+ This is the base class of all network request operations. You may wish to create your own subclass in order to implement additional `NSURLConnection` delegate methods (see "`NSURLConnection` Delegate Methods" below), or to provide additional properties and/or class constructors.
33
+
34
+ If you are creating a subclass that communicates over the HTTP or HTTPS protocols, you may want to consider subclassing `AFHTTPRequestOperation` instead, as it supports specifying acceptable content types or status codes.
35
+
36
+ ## NSURLConnection Delegate Methods
37
+
38
+ `AFURLConnectionOperation` implements the following `NSURLConnection` delegate methods:
39
+
40
+ - `connection:didReceiveResponse:`
41
+ - `connection:didReceiveData:`
42
+ - `connectionDidFinishLoading:`
43
+ - `connection:didFailWithError:`
44
+ - `connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:`
45
+ - `connection:willCacheResponse:`
46
+ - `connection:canAuthenticateAgainstProtectionSpace:`
47
+ - `connection:didReceiveAuthenticationChallenge:`
48
+
49
+ If any of these methods are overridden in a subclass, they _must_ call the `super` implementation first.
50
+
51
+ ## Class Constructors
52
+
53
+ Class constructors, or methods that return an unowned instance, are the preferred way for subclasses to encapsulate any particular logic for handling the setup or parsing of response data. For instance, `AFJSONRequestOperation` provides `JSONRequestOperationWithRequest:success:failure:`, which takes block arguments, whose parameter on for a successful request is the JSON object initialized from the `response data`.
54
+
55
+ ## Callbacks and Completion Blocks
56
+
57
+ The built-in `completionBlock` provided by `NSOperation` allows for custom behavior to be executed after the request finishes. It is a common pattern for class constructors in subclasses to take callback block parameters, and execute them conditionally in the body of its `completionBlock`. Make sure to handle cancelled operations appropriately when setting a `completionBlock` (i.e. returning early before parsing response data). See the implementation of any of the `AFHTTPRequestOperation` subclasses for an example of this.
58
+
59
+ Subclasses are strongly discouraged from overriding `setCompletionBlock:`, as `AFURLConnectionOperation`'s implementation includes a workaround to mitigate retain cycles, and what Apple rather ominously refers to as ["The Deallocation Problem"](http://developer.apple.com/library/ios/#technotes/tn2109/).
60
+
61
+ ## NSCoding & NSCopying Conformance
62
+
63
+ `AFURLConnectionOperation` conforms to the `NSCoding` and `NSCopying` protocols, allowing operations to be archived to disk, and copied in memory, respectively. However, because of the intrinsic limitations of capturing the exact state of an operation at a particular moment, there are some important caveats to keep in mind:
64
+
65
+ ### NSCoding Caveats
66
+
67
+ - Encoded operations do not include any block or stream properties. Be sure to set `completionBlock`, `outputStream`, and any callback blocks as necessary when using `-initWithCoder:` or `NSKeyedUnarchiver`.
68
+ - Operations are paused on `encodeWithCoder:`. If the operation was encoded while paused or still executing, its archived state will return `YES` for `isReady`. Otherwise, the state of an operation when encoding will remain unchanged.
69
+
70
+ ### NSCopying Caveats
71
+
72
+ - `-copy` and `-copyWithZone:` return a new operation with the `NSURLRequest` of the original. So rather than an exact copy of the operation at that particular instant, the copying mechanism returns a completely new instance, which can be useful for retrying operations.
73
+ - A copy of an operation will not include the `outputStream` of the original.
74
+ - Operation copies do not include `completionBlock`. `completionBlock` often strongly captures a reference to `self`, which would otherwise have the unintuitive side-effect of pointing to the _original_ operation when copied.
75
+ */
76
+ @interface AFURLConnectionOperation : NSOperation <NSURLConnectionDelegate, NSURLConnectionDataDelegate, NSCoding, NSCopying>
77
+
78
+ ///-------------------------------
79
+ /// @name Accessing Run Loop Modes
80
+ ///-------------------------------
81
+
82
+ /**
83
+ The run loop modes in which the operation will run on the network thread. By default, this is a single-member set containing `NSRunLoopCommonModes`.
84
+ */
85
+ @property (nonatomic, strong) NSSet *runLoopModes;
86
+
87
+ ///-----------------------------------------
88
+ /// @name Getting URL Connection Information
89
+ ///-----------------------------------------
90
+
91
+ /**
92
+ The request used by the operation's connection.
93
+ */
94
+ @property (readonly, nonatomic, strong) NSURLRequest *request;
95
+
96
+ /**
97
+ The last response received by the operation's connection.
98
+ */
99
+ @property (readonly, nonatomic, strong) NSURLResponse *response;
100
+
101
+ /**
102
+ The error, if any, that occurred in the lifecycle of the request.
103
+ */
104
+ @property (readonly, nonatomic, strong) NSError *error;
105
+
106
+ ///----------------------------
107
+ /// @name Getting Response Data
108
+ ///----------------------------
109
+
110
+ /**
111
+ The data received during the request.
112
+ */
113
+ @property (readonly, nonatomic, strong) NSData *responseData;
114
+
115
+ /**
116
+ The string representation of the response data.
117
+
118
+ @discussion This method uses the string encoding of the response, or if UTF-8 if not specified, to construct a string from the response data.
119
+ */
120
+ @property (readonly, nonatomic, copy) NSString *responseString;
121
+
122
+ ///------------------------
123
+ /// @name Accessing Streams
124
+ ///------------------------
125
+
126
+ /**
127
+ The input stream used to read data to be sent during the request.
128
+
129
+ @discussion This property acts as a proxy to the `HTTPBodyStream` property of `request`.
130
+ */
131
+ @property (nonatomic, strong) NSInputStream *inputStream;
132
+
133
+ /**
134
+ The output stream that is used to write data received until the request is finished.
135
+
136
+ @discussion By default, data is accumulated into a buffer that is stored into `responseData` upon completion of the request. When `outputStream` is set, the data will not be accumulated into an internal buffer, and as a result, the `responseData` property of the completed request will be `nil`. The output stream will be scheduled in the network thread runloop upon being set.
137
+ */
138
+ @property (nonatomic, strong) NSOutputStream *outputStream;
139
+
140
+ ///------------------------------------------------------
141
+ /// @name Initializing an AFURLConnectionOperation Object
142
+ ///------------------------------------------------------
143
+
144
+ /**
145
+ Initializes and returns a newly allocated operation object with a url connection configured with the specified url request.
146
+
147
+ @param urlRequest The request object to be used by the operation connection.
148
+
149
+ @discussion This is the designated initializer.
150
+ */
151
+ - (id)initWithRequest:(NSURLRequest *)urlRequest;
152
+
153
+ ///----------------------------------
154
+ /// @name Pausing / Resuming Requests
155
+ ///----------------------------------
156
+
157
+ /**
158
+ Pauses the execution of the request operation.
159
+
160
+ @discussion A paused operation returns `NO` for `-isReady`, `-isExecuting`, and `-isFinished`. As such, it will remain in an `NSOperationQueue` until it is either cancelled or resumed. Pausing a finished, cancelled, or paused operation has no effect.
161
+ */
162
+ - (void)pause;
163
+
164
+ /**
165
+ Whether the request operation is currently paused.
166
+
167
+ @return `YES` if the operation is currently paused, otherwise `NO`.
168
+ */
169
+ - (BOOL)isPaused;
170
+
171
+ /**
172
+ Resumes the execution of the paused request operation.
173
+
174
+ @discussion Pause/Resume behavior varies depending on the underlying implementation for the operation class. In its base implementation, resuming a paused requests restarts the original request. However, since HTTP defines a specification for how to request a specific content range, `AFHTTPRequestOperation` will resume downloading the request from where it left off, instead of restarting the original request.
175
+ */
176
+ - (void)resume;
177
+
178
+ ///----------------------------------------------
179
+ /// @name Configuring Backgrounding Task Behavior
180
+ ///----------------------------------------------
181
+
182
+ /**
183
+ Specifies that the operation should continue execution after the app has entered the background, and the expiration handler for that background task.
184
+
185
+ @param handler A handler to be called shortly before the application’s remaining background time reaches 0. The handler is wrapped in a block that cancels the operation, and cleans up and marks the end of execution, unlike the `handler` parameter in `UIApplication -beginBackgroundTaskWithExpirationHandler:`, which expects this to be done in the handler itself. The handler is called synchronously on the main thread, thus blocking the application’s suspension momentarily while the application is notified.
186
+ */
187
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED
188
+ - (void)setShouldExecuteAsBackgroundTaskWithExpirationHandler:(void (^)(void))handler;
189
+ #endif
190
+
191
+ ///---------------------------------
192
+ /// @name Setting Progress Callbacks
193
+ ///---------------------------------
194
+
195
+ /**
196
+ Sets a callback to be called when an undetermined number of bytes have been uploaded to the server.
197
+
198
+ @param block A block object to be called when an undetermined number of bytes have been uploaded to the server. This block has no return value and takes three arguments: the number of bytes written since the last time the upload progress block was called, the total bytes written, and the total bytes expected to be written during the request, as initially determined by the length of the HTTP body. This block may be called multiple times, and will execute on the main thread.
199
+ */
200
+ - (void)setUploadProgressBlock:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block;
201
+
202
+ /**
203
+ Sets a callback to be called when an undetermined number of bytes have been downloaded from the server.
204
+
205
+ @param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes three arguments: the number of bytes read since the last time the download progress block was called, the total bytes read, and the total bytes expected to be read during the request, as initially determined by the expected content size of the `NSHTTPURLResponse` object. This block may be called multiple times, and will execute on the main thread.
206
+ */
207
+ - (void)setDownloadProgressBlock:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block;
208
+
209
+ ///-------------------------------------------------
210
+ /// @name Setting NSURLConnection Delegate Callbacks
211
+ ///-------------------------------------------------
212
+
213
+ /**
214
+ Sets a block to be executed to determine whether the connection should be able to respond to a protection space's form of authentication, as handled by the `NSURLConnectionDelegate` method `connection:canAuthenticateAgainstProtectionSpace:`.
215
+
216
+ @param block A block object to be executed to determine whether the connection should be able to respond to a protection space's form of authentication. The block has a `BOOL` return type and takes two arguments: the URL connection object, and the protection space to authenticate against.
217
+
218
+ @discussion If `_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_` is defined, `connection:canAuthenticateAgainstProtectionSpace:` will accept invalid SSL certificates, returning `YES` if the protection space authentication method is `NSURLAuthenticationMethodServerTrust`.
219
+ */
220
+ - (void)setAuthenticationAgainstProtectionSpaceBlock:(BOOL (^)(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace))block;
221
+
222
+ /**
223
+ Sets a block to be executed when the connection must authenticate a challenge in order to download its request, as handled by the `NSURLConnectionDelegate` method `connection:didReceiveAuthenticationChallenge:`.
224
+
225
+ @param block A block object to be executed when the connection must authenticate a challenge in order to download its request. The block has no return type and takes two arguments: the URL connection object, and the challenge that must be authenticated.
226
+
227
+ @discussion If `_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_` is defined, `connection:didReceiveAuthenticationChallenge:` will attempt to have the challenge sender use credentials with invalid SSL certificates.
228
+ */
229
+ - (void)setAuthenticationChallengeBlock:(void (^)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge))block;
230
+
231
+ /**
232
+ Sets a block to be executed when the server redirects the request from one URL to another URL, or when the request URL changed by the `NSURLProtocol` subclass handling the request in order to standardize its format, as handled by the `NSURLConnectionDelegate` method `connection:willSendRequest:redirectResponse:`.
233
+
234
+ @param block A block object to be executed when the request URL was changed. The block returns an `NSURLRequest` object, the URL request to redirect, and takes three arguments: the URL connection object, the the proposed redirected request, and the URL response that caused the redirect.
235
+ */
236
+ - (void)setRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse))block;
237
+
238
+
239
+ /**
240
+ Sets a block to be executed to modify the response a connection will cache, if any, as handled by the `NSURLConnectionDelegate` method `connection:willCacheResponse:`.
241
+
242
+ @param block A block object to be executed to determine what response a connection will cache, if any. The block returns an `NSCachedURLResponse` object, the cached response to store in memory or `nil` to prevent the response from being cached, and takes two arguments: the URL connection object, and the cached response provided for the request.
243
+ */
244
+ - (void)setCacheResponseBlock:(NSCachedURLResponse * (^)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse))block;
245
+
246
+ @end
247
+
248
+ ///----------------
249
+ /// @name Constants
250
+ ///----------------
251
+
252
+ /**
253
+ ## User info dictionary keys
254
+
255
+ These keys may exist in the user info dictionary, in addition to those defined for NSError.
256
+
257
+ - `NSString * const AFNetworkingOperationFailingURLRequestErrorKey`
258
+ - `NSString * const AFNetworkingOperationFailingURLResponseErrorKey`
259
+
260
+ ### Constants
261
+
262
+ `AFNetworkingOperationFailingURLRequestErrorKey`
263
+ The corresponding value is an `NSURLRequest` containing the request of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`.
264
+
265
+ `AFNetworkingOperationFailingURLResponseErrorKey`
266
+ The corresponding value is an `NSURLResponse` containing the response of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`.
267
+
268
+ ## Error Domains
269
+
270
+ The following error domain is predefined.
271
+
272
+ - `NSString * const AFNetworkingErrorDomain`
273
+
274
+ ### Constants
275
+
276
+ `AFNetworkingErrorDomain`
277
+ AFNetworking errors. Error codes for `AFNetworkingErrorDomain` correspond to codes in `NSURLErrorDomain`.
278
+ */
279
+ extern NSString * const AFNetworkingErrorDomain;
280
+ extern NSString * const AFNetworkingOperationFailingURLRequestErrorKey;
281
+ extern NSString * const AFNetworkingOperationFailingURLResponseErrorKey;
282
+
283
+ ///--------------------
284
+ /// @name Notifications
285
+ ///--------------------
286
+
287
+ /**
288
+ Posted when an operation begins executing.
289
+ */
290
+ extern NSString * const AFNetworkingOperationDidStartNotification;
291
+
292
+ /**
293
+ Posted when an operation finishes.
294
+ */
295
+ extern NSString * const AFNetworkingOperationDidFinishNotification;