afmotion 2.6 → 3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,74 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- afmotion (2.5)
5
- motion-cocoapods (>= 1.4.1)
6
- motion-require (>= 0.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (4.2.1)
12
- i18n (~> 0.7)
13
- json (~> 1.7, >= 1.7.7)
14
- minitest (~> 5.1)
15
- thread_safe (~> 0.3, >= 0.3.4)
16
- tzinfo (~> 1.1)
17
- claide (0.8.1)
18
- cocoapods (0.36.0)
19
- activesupport (>= 3.2.15)
20
- claide (~> 0.8.1)
21
- cocoapods-core (= 0.36.0)
22
- cocoapods-downloader (~> 0.8.1)
23
- cocoapods-plugins (~> 0.4.1)
24
- cocoapods-trunk (~> 0.6.0)
25
- cocoapods-try (~> 0.4.3)
26
- colored (~> 1.2)
27
- escape (~> 0.0.4)
28
- molinillo (~> 0.2.1)
29
- nap (~> 0.8)
30
- open4 (~> 1.3)
31
- xcodeproj (~> 0.23.0)
32
- cocoapods-core (0.36.0)
33
- activesupport (>= 3.2.15)
34
- fuzzy_match (~> 2.0.4)
35
- nap (~> 0.8.0)
36
- cocoapods-downloader (0.8.1)
37
- cocoapods-plugins (0.4.1)
38
- nap
39
- cocoapods-trunk (0.6.0)
40
- nap (>= 0.8)
41
- netrc (= 0.7.8)
42
- cocoapods-try (0.4.3)
43
- colored (1.2)
44
- escape (0.0.4)
45
- fuzzy_match (2.0.4)
46
- i18n (0.7.0)
47
- json (1.8.2)
48
- minitest (5.5.1)
49
- molinillo (0.2.1)
50
- motion-cocoapods (1.7.0)
51
- cocoapods (>= 0.34)
52
- motion-require (0.2.0)
53
- nap (0.8.0)
54
- netrc (0.7.8)
55
- open4 (1.3.4)
56
- rake (10.4.2)
57
- thread_safe (0.3.5)
58
- tzinfo (1.2.2)
59
- thread_safe (~> 0.1)
60
- webstub (1.1.2)
61
- xcodeproj (0.23.0)
62
- activesupport (>= 3)
63
- colored (~> 1.2)
64
-
65
- PLATFORMS
66
- ruby
67
-
68
- DEPENDENCIES
69
- afmotion!
70
- rake
71
- webstub (~> 1.1)
72
-
73
- BUNDLED WITH
74
- 1.10.4
@@ -1,136 +0,0 @@
1
- motion_require 'version'
2
- motion_require 'client_shared'
3
-
4
- module AFMotion
5
- class Client
6
- class << self
7
- attr_accessor :shared
8
-
9
- # Returns an instance of AFHTTPRequestOperationManager
10
- def build(base_url, &block)
11
- operation_manager = AFHTTPRequestOperationManager.alloc.initWithBaseURL(base_url.to_url)
12
- if block
13
- dsl = AFMotion::ClientDSL.new(operation_manager)
14
- case block.arity
15
- when 0
16
- dsl.instance_eval(&block)
17
- when 1
18
- block.call(dsl)
19
- end
20
- end
21
- if !operation_manager.operationQueue
22
- operation_manager.operationQueue = NSOperationQueue.mainQueue
23
- end
24
- operation_manager
25
- end
26
-
27
- # Sets AFMotion::Client.shared as the built client
28
- def build_shared(base_url, &block)
29
- self.shared = self.build(base_url, &block)
30
- end
31
- end
32
- end
33
- end
34
-
35
- module AFMotion
36
- class ClientDSL
37
- def initialize(operation_manager)
38
- @operation_manager = WeakRef.new(operation_manager)
39
- end
40
-
41
- def header(header, value)
42
- @headers ||= {}
43
- @headers[header] = value
44
- apply_header(header, value)
45
- end
46
-
47
- def authorization(options = {})
48
- @authorization = options
49
- apply_authorization(options)
50
- end
51
-
52
- def operation_queue(operation_queue)
53
- @operation_manager.operationQueue = operation_queue
54
- end
55
-
56
- OPERATION_TO_REQUEST_SERIALIZER = {
57
- json: AFJSONRequestSerializer,
58
- plist: AFPropertyListRequestSerializer
59
- }
60
- def request_serializer(serializer)
61
- if serializer.is_a?(Symbol) || serializer.is_a?(String)
62
- @operation_manager.requestSerializer = OPERATION_TO_REQUEST_SERIALIZER[serializer.to_sym].serializer
63
- elsif serializer.is_a?(Class)
64
- @operation_manager.requestSerializer = serializer.serializer
65
- else
66
- @operation_manager.requestSerializer = serializer
67
- end
68
- reapply_options
69
- end
70
-
71
- OPERATION_TO_RESPONSE_SERIALIZER = {
72
- json: AFJSONResponseSerializer,
73
- xml: AFXMLParserResponseSerializer,
74
- plist: AFPropertyListResponseSerializer,
75
- image: AFImageResponseSerializer,
76
- http: AFHTTPResponseSerializer,
77
- form: AFHTTPResponseSerializer
78
- }
79
- def response_serializer(serializer)
80
- write_json_options = true
81
- if serializer.is_a?(Symbol) || serializer.is_a?(String)
82
- @operation_manager.responseSerializer = OPERATION_TO_RESPONSE_SERIALIZER[serializer.to_sym].serializer
83
- elsif serializer.is_a?(Class)
84
- @operation_manager.responseSerializer = serializer.serializer
85
- else
86
- @operation_manager.responseSerializer = serializer
87
- write_json_options = false
88
- end
89
- af_serializer = @operation_manager.responseSerializer
90
- if af_serializer.is_a?(AFJSONResponseSerializer) && write_json_options
91
- af_serializer.readingOptions = NSJSONReadingMutableContainers
92
- end
93
- af_serializer
94
- end
95
-
96
- private
97
-
98
- def reapply_options
99
- @headers.each{ |h,v| apply_header(h, v) } unless @headers.nil?
100
- apply_authorization(@authorization) unless @authorization.nil?
101
- end
102
-
103
- def apply_header(header, value)
104
- @operation_manager.headers[header] = value
105
- end
106
-
107
- def apply_authorization(options)
108
- @operation_manager.requestSerializer.authorization = options
109
- end
110
-
111
- end
112
- end
113
-
114
- class AFHTTPRequestOperationManager
115
- include AFMotion::ClientShared
116
-
117
- AFMotion::HTTP_METHODS.each do |method|
118
- # EX client.get('my/resource.json')
119
- define_method "#{method}", -> (path, parameters = nil, &callback) do
120
- create_operation(method, path, parameters, &callback)
121
- end
122
- end
123
-
124
- # options = {parameters: , constructingBodyWithBlock: , success:, failure:}
125
- def PUT(url_string, options = {})
126
- parameters = options[:parameters]
127
- block = options[:constructingBodyWithBlock]
128
- success = options[:success]
129
- failure = options[:failure]
130
- request = self.requestSerializer.multipartFormRequestWithMethod("PUT", URLString: NSURL.URLWithString(url_string, relativeToURL:self.baseURL).absoluteString, parameters: parameters, constructingBodyWithBlock:block)
131
- operation = self.HTTPRequestOperationWithRequest(request, success:success, failure:failure)
132
- self.operationQueue.addOperation(operation)
133
-
134
- operation
135
- end
136
- end
@@ -1,225 +0,0 @@
1
- describe "AFMotion::ClientDSL" do
2
- before do
3
- @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://url".to_url)
4
- @dsl = AFMotion::ClientDSL.new(@client)
5
- end
6
-
7
- describe "#header" do
8
- it "should set header" do
9
- @dsl.header "Accept", "application/json"
10
- @client.requestSerializer.HTTPRequestHeaders["Accept"].should == "application/json"
11
- end
12
- end
13
-
14
- describe "#authorization" do
15
- it "should set authorization" do
16
- @dsl.authorization username: "clay", password: "test"
17
- @client.requestSerializer.HTTPRequestHeaders["Authorization"].nil?.should == false
18
- end
19
- end
20
-
21
- describe "#request_serializer" do
22
- it "should set request_serializer if provided type" do
23
- @dsl.request_serializer AFJSONRequestSerializer
24
- @client.requestSerializer.is_a?(AFJSONRequestSerializer).should == true
25
- end
26
-
27
- it "should set request_serializer if provided string" do
28
- [["json", AFJSONRequestSerializer], ["plist", AFPropertyListRequestSerializer]].each do |op, op_class|
29
- @dsl.request_serializer op
30
- @client.requestSerializer.is_a?(op_class).should == true
31
- end
32
- end
33
-
34
- it "should retain header configuration" do
35
- @dsl.header "X-Order", "agnostic"
36
- @dsl.request_serializer :json
37
- @client.requestSerializer.HTTPRequestHeaders["X-Order"].should == "agnostic"
38
- end
39
-
40
- it "should retain authorization" do
41
- @dsl.authorization username: "clay", password: "test"
42
- @dsl.request_serializer :json
43
- @client.requestSerializer.HTTPRequestHeaders["Authorization"].nil?.should == false
44
- end
45
- end
46
-
47
- describe "#response_serializer" do
48
- it "should set response_serializer if provided type" do
49
- @dsl.response_serializer AFJSONResponseSerializer
50
- @client.responseSerializer.is_a?(AFJSONResponseSerializer).should == true
51
- end
52
-
53
- it "should set response_serializer if provided string" do
54
- [["json", AFJSONResponseSerializer],
55
- ["form", AFHTTPResponseSerializer],
56
- ["http", AFHTTPResponseSerializer],
57
- ["xml", AFXMLParserResponseSerializer],
58
- ["plist", AFPropertyListResponseSerializer],
59
- ["image", AFImageResponseSerializer]].each do |enc, enc_class|
60
- @dsl.response_serializer enc
61
- @client.responseSerializer.is_a?(enc_class).should == true
62
- end
63
- end
64
-
65
- it "should set mutable reading options for JSON serializer" do
66
- @dsl.response_serializer :json
67
- @client.responseSerializer.readingOptions.should == NSJSONReadingMutableContainers
68
- end
69
-
70
- it "should not set reading options for JSON serializer if raw one supplied" do
71
- @dsl.response_serializer AFJSONResponseSerializer.serializer
72
- @client.responseSerializer.readingOptions.should.not == NSJSONReadingMutableContainers
73
- end
74
- end
75
- end
76
-
77
- describe "AFMotion::Client" do
78
- describe ".build" do
79
- it "should return an AFHTTPRequestOperationManager" do
80
- client = AFMotion::Client.build("http://url")
81
- client.is_a?(AFHTTPRequestOperationManager).should == true
82
- end
83
- end
84
-
85
- describe ".build_shared" do
86
- it "should set AFMotion::Client.shared" do
87
- client = AFMotion::Client.build_shared("http://url")
88
- AFMotion::Client.shared.should == client
89
- end
90
-
91
- it "should call progress when given to a chared client" do
92
- image_path = "images/srpr/logo3w.png"
93
- client = AFMotion::Client.build_shared("https://www.google.com/")
94
- @progression = []
95
- progress_block = Proc.new do |bytesRead, totalBytesRead, totalBytesExpectedToRead|
96
- @progression << [bytesRead, totalBytesRead, totalBytesExpectedToRead]
97
- end
98
-
99
- client.get(image_path, {progress_block: progress_block}) do |result|
100
- @result = result
101
- resume
102
- end
103
- wait_max(10) do
104
- @progression.empty?.should == false
105
- end
106
- end
107
- end
108
- end
109
-
110
- describe "AFHTTPClient" do
111
- before do
112
- @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://google.com/".to_url)
113
- end
114
-
115
- describe "URL Helpers" do
116
- it "should exist" do
117
- AFMotion::HTTP_METHODS.each do |method|
118
- @client.respond_to?(method).should == true
119
- end
120
- end
121
- end
122
-
123
- # Pretty basic test
124
- it "should work" do
125
- @result = nil
126
- @client.get("") do |result|
127
- @result = result
128
- resume
129
- end
130
- wait_max(10) do
131
- @result.nil?.should == false
132
- end
133
- end
134
-
135
- describe "#authorization=" do
136
- it "should set basic auth" do
137
- @client.authorization = {username: "clay", password: "pass"}
138
- @client.requestSerializer.HTTPRequestHeaders["Authorization"].split[0].should == "Basic"
139
- end
140
- end
141
-
142
- describe "#build_shared" do
143
- it "should set AFMotion::Client.shared" do
144
- @client.authorization = {token: "clay"}
145
- @client.requestSerializer.HTTPRequestHeaders["Authorization"].split[0].should == "Token"
146
- end
147
- end
148
-
149
- describe "#headers" do
150
- describe "#[]" do
151
- it "should return a header" do
152
- @client.requestSerializer.setValue("test_value", forHTTPHeaderField: "test")
153
- @client.headers["test"].should == "test_value"
154
- end
155
- end
156
-
157
- describe "#[]=" do
158
- it "should set a header" do
159
- @client.headers["test"] = "test_set_value"
160
- @client.requestSerializer.HTTPRequestHeaders["test"].should == "test_set_value"
161
- end
162
- end
163
-
164
- describe "#delete" do
165
- it "should remove a header" do
166
- @client.requestSerializer.setValue("test_value", forHTTPHeaderField: "test")
167
- @client.headers.delete("test").should == "test_value"
168
- @client.requestSerializer.HTTPRequestHeaders["test"].should == nil
169
- end
170
- end
171
- end
172
-
173
- ["multipart_post", "multipart_put"].each do |multipart_method|
174
- describe "##{multipart_method}" do
175
- it "should trigger multipart request" do
176
- @client.send(multipart_method, "", test: "Herp") do |result, form_data|
177
- @result = result
178
- resume if result
179
- end
180
-
181
- wait_max(10) do
182
- @result.should.not == nil
183
- @result.operation.request.valueForHTTPHeaderField("Content-Type").include?("multipart/form-data").should == true
184
- end
185
- end
186
-
187
- it "should work with form data" do
188
- @client.send(multipart_method, "", test: "Herp") do |result, form_data|
189
- if result
190
- resume
191
- else
192
- @form_data = form_data
193
- end
194
- end
195
-
196
- wait_max(10) do
197
- @form_data.should.not == nil
198
- end
199
- end
200
-
201
- it "should have upload callback with raw progress" do
202
- image = UIImage.imageNamed("test")
203
- @data = UIImagePNGRepresentation(image)
204
- @file_added = false
205
- @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://bing.com/".to_url)
206
- @client.send(multipart_method, "", test: "Herp") do |result, form_data, progress|
207
- if form_data
208
- @file_added = true
209
- form_data.appendPartWithFileData(@data, name: "test", fileName:"test.png", mimeType: "image/png")
210
- elsif progress
211
- @progress ||= progress
212
- elsif result
213
- resume
214
- end
215
- end
216
-
217
- wait_max(20) do
218
- @file_added.should == true
219
- @progress.should <= 1.0
220
- @progress.should.not == nil
221
- end
222
- end
223
- end
224
- end
225
- end