afmotion 2.2.0 → 3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- afmotion (2.2.0)
5
- motion-cocoapods (>= 1.4.1)
6
- motion-require (>= 0.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (3.2.18)
12
- i18n (~> 0.6, >= 0.6.4)
13
- multi_json (~> 1.0)
14
- claide (0.6.1)
15
- cocoapods (0.33.1)
16
- activesupport (>= 3.2.15, < 4)
17
- claide (~> 0.6.1)
18
- cocoapods-core (= 0.33.1)
19
- cocoapods-downloader (~> 0.6.1)
20
- cocoapods-plugins (~> 0.2.0)
21
- cocoapods-trunk (~> 0.1.1)
22
- cocoapods-try (~> 0.3.0)
23
- colored (~> 1.2)
24
- escape (~> 0.0.4)
25
- json_pure (~> 1.8)
26
- nap (~> 0.7)
27
- open4 (~> 1.3)
28
- xcodeproj (~> 0.17.0)
29
- cocoapods-core (0.33.1)
30
- activesupport (>= 3.2.15)
31
- fuzzy_match (~> 2.0.4)
32
- json_pure (~> 1.8)
33
- nap (~> 0.5)
34
- cocoapods-downloader (0.6.1)
35
- cocoapods-plugins (0.2.0)
36
- nap
37
- cocoapods-trunk (0.1.3)
38
- json_pure (~> 1.8)
39
- nap (>= 0.6)
40
- netrc
41
- cocoapods-try (0.3.0)
42
- colored (1.2)
43
- escape (0.0.4)
44
- fuzzy_match (2.0.4)
45
- i18n (0.6.9)
46
- json_pure (1.8.1)
47
- motion-cocoapods (1.5.0)
48
- cocoapods (>= 0.32.1)
49
- motion-require (0.2.0)
50
- multi_json (1.10.1)
51
- nap (0.7.0)
52
- netrc (0.7.7)
53
- open4 (1.3.4)
54
- rake (10.1.0)
55
- xcodeproj (0.17.0)
56
- activesupport (~> 3.0)
57
- colored (~> 1.2)
58
-
59
- PLATFORMS
60
- ruby
61
-
62
- DEPENDENCIES
63
- afmotion!
64
- rake
@@ -1,109 +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
- @operation_manager.headers[header] = value
43
- end
44
-
45
- def authorization(options = {})
46
- @operation_manager.requestSerializer.authorization = options
47
- end
48
-
49
- def operation_queue(operation_queue)
50
- @operation_manager.operationQueue = operation_queue
51
- end
52
-
53
- OPERATION_TO_REQUEST_SERIALIZER = {
54
- json: AFJSONRequestSerializer,
55
- plist: AFPropertyListRequestSerializer
56
- }
57
- def request_serializer(serializer)
58
- if serializer.is_a?(Symbol) || serializer.is_a?(String)
59
- @operation_manager.requestSerializer = OPERATION_TO_REQUEST_SERIALIZER[serializer.to_sym].serializer
60
- elsif serializer.is_a?(Class)
61
- @operation_manager.requestSerializer = serializer.serializer
62
- else
63
- @operation_manager.requestSerializer = serializer
64
- end
65
- end
66
-
67
- OPERATION_TO_RESPONSE_SERIALIZER = {
68
- json: AFJSONResponseSerializer,
69
- xml: AFXMLParserResponseSerializer,
70
- plist: AFPropertyListResponseSerializer,
71
- image: AFImageResponseSerializer,
72
- http: AFHTTPResponseSerializer,
73
- form: AFHTTPResponseSerializer
74
- }
75
- def response_serializer(serializer)
76
- if serializer.is_a?(Symbol) || serializer.is_a?(String)
77
- @operation_manager.responseSerializer = OPERATION_TO_RESPONSE_SERIALIZER[serializer.to_sym].serializer
78
- elsif serializer.is_a?(Class)
79
- @operation_manager.responseSerializer = serializer.serializer
80
- else
81
- @operation_manager.responseSerializer = serializer
82
- end
83
- end
84
- end
85
- end
86
-
87
- class AFHTTPRequestOperationManager
88
- include AFMotion::ClientShared
89
-
90
- AFMotion::HTTP_METHODS.each do |method|
91
- # EX client.get('my/resource.json')
92
- define_method "#{method}", -> (path, parameters = {}, &callback) do
93
- create_operation(method, path, parameters, &callback)
94
- end
95
- end
96
-
97
- # options = {parameters: , constructingBodyWithBlock: , success:, failure:}
98
- def PUT(url_string, options = {})
99
- parameters = options[:parameters]
100
- block = options[:constructingBodyWithBlock]
101
- success = options[:success]
102
- failure = options[:failure]
103
- request = self.requestSerializer.multipartFormRequestWithMethod("PUT", URLString: NSURL.URLWithString(url_string, relativeToURL:self.baseURL).absoluteString, parameters: parameters, constructingBodyWithBlock:block)
104
- operation = self.HTTPRequestOperationWithRequest(request, success:success, failure:failure)
105
- self.operationQueue.addOperation(operation)
106
-
107
- operation
108
- end
109
- end
@@ -1,186 +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
- end
34
-
35
- describe "#response_serializer" do
36
- it "should set response_serializer if provided type" do
37
- @dsl.response_serializer AFJSONResponseSerializer
38
- @client.responseSerializer.is_a?(AFJSONResponseSerializer).should == true
39
- end
40
-
41
- it "should set response_serializer if provided string" do
42
- [["json", AFJSONResponseSerializer],
43
- ["form", AFHTTPResponseSerializer],
44
- ["http", AFHTTPResponseSerializer],
45
- ["xml", AFXMLParserResponseSerializer],
46
- ["plist", AFPropertyListResponseSerializer],
47
- ["image", AFImageResponseSerializer]].each do |enc, enc_class|
48
- @dsl.response_serializer enc
49
- @client.responseSerializer.is_a?(enc_class).should == true
50
- end
51
- end
52
- end
53
- end
54
-
55
- describe "AFMotion::Client" do
56
- describe ".build" do
57
- it "should return an AFHTTPRequestOperationManager" do
58
- client = AFMotion::Client.build("http://url")
59
- client.is_a?(AFHTTPRequestOperationManager).should == true
60
- end
61
- end
62
-
63
- describe ".build_shared" do
64
- it "should set AFMotion::Client.shared" do
65
- client = AFMotion::Client.build_shared("http://url")
66
- AFMotion::Client.shared.should == client
67
- end
68
- end
69
- end
70
-
71
- describe "AFHTTPClient" do
72
- before do
73
- @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://google.com/".to_url)
74
- end
75
-
76
- describe "URL Helpers" do
77
- it "should exist" do
78
- AFMotion::HTTP_METHODS.each do |method|
79
- @client.respond_to?(method).should == true
80
- end
81
- end
82
- end
83
-
84
- # Pretty basic test
85
- it "should work" do
86
- @result = nil
87
- @client.get("") do |result|
88
- @result = result
89
- resume
90
- end
91
- wait_max(10) do
92
- @result.nil?.should == false
93
- end
94
- end
95
-
96
- describe "#authorization=" do
97
- it "should set basic auth" do
98
- @client.authorization = {username: "clay", password: "pass"}
99
- @client.requestSerializer.HTTPRequestHeaders["Authorization"].split[0].should == "Basic"
100
- end
101
- end
102
-
103
- describe "#build_shared" do
104
- it "should set AFMotion::Client.shared" do
105
- @client.authorization = {token: "clay"}
106
- @client.requestSerializer.HTTPRequestHeaders["Authorization"].split[0].should == "Token"
107
- end
108
- end
109
-
110
- describe "#headers" do
111
- describe "#[]" do
112
- it "should return a header" do
113
- @client.requestSerializer.setValue("test_value", forHTTPHeaderField: "test")
114
- @client.headers["test"].should == "test_value"
115
- end
116
- end
117
-
118
- describe "#[]=" do
119
- it "should set a header" do
120
- @client.headers["test"] = "test_set_value"
121
- @client.requestSerializer.HTTPRequestHeaders["test"].should == "test_set_value"
122
- end
123
- end
124
-
125
- describe "#delete" do
126
- it "should remove a header" do
127
- @client.requestSerializer.setValue("test_value", forHTTPHeaderField: "test")
128
- @client.headers.delete("test").should == "test_value"
129
- @client.requestSerializer.HTTPRequestHeaders["test"].should == nil
130
- end
131
- end
132
- end
133
-
134
- ["multipart_post", "multipart_put"].each do |multipart_method|
135
- describe "##{multipart_method}" do
136
- it "should trigger multipart request" do
137
- @client.send(multipart_method, "", test: "Herp") do |result, form_data|
138
- @result = result
139
- resume if result
140
- end
141
-
142
- wait_max(10) do
143
- @result.should.not == nil
144
- @result.operation.request.valueForHTTPHeaderField("Content-Type").include?("multipart/form-data").should == true
145
- end
146
- end
147
-
148
- it "should work with form data" do
149
- @client.send(multipart_method, "", test: "Herp") do |result, form_data|
150
- if result
151
- resume
152
- else
153
- @form_data = form_data
154
- end
155
- end
156
-
157
- wait_max(10) do
158
- @form_data.should.not == nil
159
- end
160
- end
161
-
162
- it "should have upload callback with raw progress" do
163
- image = UIImage.imageNamed("test")
164
- @data = UIImagePNGRepresentation(image)
165
- @file_added = false
166
- @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://bing.com/".to_url)
167
- @client.send(multipart_method, "", test: "Herp") do |result, form_data, progress|
168
- if form_data
169
- @file_added = true
170
- form_data.appendPartWithFileData(@data, name: "test", fileName:"test.png", mimeType: "image/png")
171
- elsif progress
172
- @progress ||= progress
173
- elsif result
174
- resume
175
- end
176
- end
177
-
178
- wait_max(20) do
179
- @file_added.should == true
180
- @progress.should <= 1.0
181
- @progress.should.not == nil
182
- end
183
- end
184
- end
185
- end
186
- end