afmotion 0.8.1 → 0.9.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTY1ZjcyN2NlMjAzOGU2OTRlNzk5NDEwMzAyOGI3ODg4YWM5ZWE4NA==
4
+ NWRhODIzZDU2NDU2NTgyODMyYmFlNTBhMWM4N2ZkODg1YzQ0NzI1Nw==
5
5
  data.tar.gz: !binary |-
6
- YWVkMzVkY2FjYzc3NDY1ODY2OTE3MzRkZGM3NGVlMjcyYTg4NzdjYg==
6
+ NTg1ZGUwYjNkZmViM2EyZWNlYTJiNmFjM2E0ZDc2YzUxNGJmMGQ5OQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTMxZjJmNjUyMTFiYTUwZjBjMDFlMThmNjUyM2M0MGU1MjBmYmQ3NGYyZTMw
10
- YjcwYTcyMTI2ZDljODhjOTI4NGM4MzE0MzNmOGQzN2UzNTM1NTM5NTI0OWYx
11
- MDU0NTJjNWM2MGRjYzJjZDYyMmY0NGRlNmEzNTA2MTQwNzE3ZWE=
9
+ ZTBhZDVmZjVhYmM5ZjU0OTIyMWUwMzEzZjQ0N2JkOGIzYWE1NmNiNzkzZDZh
10
+ ZjM1N2M5ZDQxYjVkYTllODU4MzJkYmU4MTM2NzAwMjM3OTQ2ODU4MTdkNzI3
11
+ N2U2N2YwMjczN2MxZjk2Mzg2ZjAzODUzYmRkMjFkOTkzZjYyNDI=
12
12
  data.tar.gz: !binary |-
13
- ZjFjMDBlZWUxOTQxZWM4MTQ3ODExZDRmOGRmY2ExODYzN2Y2NzBhN2JlZmIw
14
- MzE3ZTdiZmQxODA1ZDdhYTVhZjY4NzYyMDU4Mzg4MDcyNDNlNDE0MzZhNWZm
15
- Njc5M2RjOGFjYjViOTU5NjE4YTVjYjhhZDRhOTlhNDZkNWFlOWE=
13
+ ZGIwZGFhYjI0NzYxNGIxZWI3MDQ0NzlmZjZkODNmMTQ3NzUxNjdhNTA4NGM5
14
+ M2U1NTgyZTdhMWQwZjhiZjczMjFiMWRhYWQ3MjA5MmMzNzJmNTZmMWY0NGM1
15
+ MjllNTE5Mzc2YmUxZmY1MGI0ZjlkZGI3ZTkyNzM5ZTFlNmNjOTQ=
data/AFMotion.gemspec CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.homepage = "https://github.com/clayallsopp/AFMotion"
10
10
  s.summary = "A RubyMotion Wrapper for AFNetworking"
11
11
  s.description = "A RubyMotion Wrapper for AFNetworking"
12
+ s.license = 'MIT'
12
13
 
13
14
  s.files = `git ls-files`.split($\).delete_if {|x| x.include? "example"}
14
15
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- afmotion (0.8.1)
4
+ afmotion (0.9.0)
5
5
  motion-cocoapods (~> 1.3.6)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -176,14 +176,14 @@ end
176
176
 
177
177
  #### Multipart Requests
178
178
 
179
- `AFHTTPClient` supports multipart form requests (i.e. for image uploading). Simply prepend `multipart` to any other request method and it'll convert your parameters into properly encoded multipart data:
179
+ `AFHTTPClient` supports multipart form requests (i.e. for image uploading). Simply prepend `multipart!` to any other request method and it'll convert your parameters into properly encoded multipart data:
180
180
 
181
181
  ```ruby
182
182
  # an instance of UIImage
183
183
  image = my_function.get_image
184
184
  data = UIImagePNGRepresentation(image)
185
185
 
186
- client.multipart.post("avatars") do |result, form_data|
186
+ client.multipart!.post("avatars") do |result, form_data|
187
187
  if form_data
188
188
  # Called before request runs
189
189
  # see: https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ
@@ -199,7 +199,7 @@ end
199
199
  If you want to track upload progress, you can add a third callback argument which returns the upload percentage between 0.0 and 1.0:
200
200
 
201
201
  ```ruby
202
- client.multipart.post("avatars") do |result, form_data, progress|
202
+ client.multipart!.post("avatars") do |result, form_data, progress|
203
203
  if form_data
204
204
  # Called before request runs
205
205
  # see: https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ
@@ -211,6 +211,21 @@ client.multipart.post("avatars") do |result, form_data, progress|
211
211
  end
212
212
  ```
213
213
 
214
+ #### Headers
215
+
216
+ You can set default HTTP headers using `client.headers`, which is sort of like a `Hash`:
217
+
218
+ ```ruby
219
+ client.headers["Accept"]
220
+ #=> "application/json"
221
+
222
+ client.headers["Accept"] = "something_else"
223
+ #=> "application/something_else"
224
+
225
+ client.headers.delete "Accept"
226
+ #=> "application/something_else"
227
+ ```
228
+
214
229
  #### Client Operations
215
230
 
216
231
  If you want to grab an `AFURLConnectionOperation` from your client instance, use `create_operation` or `create_multipart_operation`:
@@ -149,7 +149,7 @@ class AFHTTPClient
149
149
  })
150
150
  end
151
151
 
152
- def multipart
152
+ def multipart!
153
153
  @multipart = true
154
154
  self
155
155
  end
@@ -174,6 +174,30 @@ class AFHTTPClient
174
174
  end
175
175
  end
176
176
 
177
+ class HeaderWrapper
178
+ def initialize(client)
179
+ @client = WeakRef.new(client)
180
+ end
181
+
182
+ def [](header)
183
+ @client.defaultValueForHeader(header)
184
+ end
185
+
186
+ def []=(header, value)
187
+ @client.setDefaultHeader(header, value: value)
188
+ end
189
+
190
+ def delete(header)
191
+ value = self[header]
192
+ @client.setDefaultHeader(header, value: nil)
193
+ value
194
+ end
195
+ end
196
+
197
+ def headers
198
+ @header_wrapper ||= HeaderWrapper.new(self)
199
+ end
200
+
177
201
  private
178
202
  # To force RubyMotion pre-compilation of these methods
179
203
  def dummy
@@ -1,5 +1,5 @@
1
1
  module AFMotion
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
 
4
4
  HTTP_METHODS = [:get, :post, :put, :delete, :patch, :head]
5
5
  end
@@ -102,14 +102,38 @@ describe "AFHTTPClient" do
102
102
  end
103
103
  end
104
104
 
105
+ describe "#headers" do
106
+ describe "#[]" do
107
+ it "should return a header" do
108
+ @client.setDefaultHeader("test", value: "test_value")
109
+ @client.headers["test"].should == "test_value"
110
+ end
111
+ end
112
+
113
+ describe "#[]=" do
114
+ it "should set a header" do
115
+ @client.headers["test"] = "test_set_value"
116
+ @client.defaultValueForHeader("test").should == "test_set_value"
117
+ end
118
+ end
119
+
120
+ describe "#delete" do
121
+ it "should remove a header" do
122
+ @client.setDefaultHeader("test", value: "test_value")
123
+ @client.headers.delete("test").should == "test_value"
124
+ @client.defaultValueForHeader("test").should == nil
125
+ end
126
+ end
127
+ end
128
+
105
129
  describe "#multipart" do
106
130
  it "should trigger multipart logic" do
107
- @client.multipart.should == @client
131
+ @client.multipart!.should == @client
108
132
  @client.instance_variable_get("@multipart").should == true
109
133
  end
110
134
 
111
135
  it "should trigger multipart request" do
112
- @client.multipart.post("", test: "Herp") do |result|
136
+ @client.multipart!.post("", test: "Herp") do |result|
113
137
  @result = result
114
138
  resume
115
139
  end
@@ -121,7 +145,7 @@ describe "AFHTTPClient" do
121
145
  end
122
146
 
123
147
  it "should work with form data" do
124
- @client.multipart.post("", test: "Herp") do |result, form_data|
148
+ @client.multipart!.post("", test: "Herp") do |result, form_data|
125
149
  if result
126
150
  resume
127
151
  else
@@ -138,7 +162,7 @@ describe "AFHTTPClient" do
138
162
  image = UIImage.imageNamed("test")
139
163
  @data = UIImagePNGRepresentation(image)
140
164
  @client = AFHTTPClient.clientWithBaseURL("http://bing.com/".to_url)
141
- @client.multipart.post("", test: "Herp") do |result, form_data, progress|
165
+ @client.multipart!.post("", test: "Herp") do |result, form_data, progress|
142
166
  if form_data
143
167
  form_data.appendPartWithFileData(@data, name: "test", fileName:"test.png", mimeType: "image/png")
144
168
  elsif progress
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: afmotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clay Allsopp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-15 00:00:00.000000000 Z
11
+ date: 2013-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: motion-cocoapods
@@ -69,7 +69,8 @@ files:
69
69
  - spec/operation_spec.rb
70
70
  - vendor/Podfile.lock
71
71
  homepage: https://github.com/clayallsopp/AFMotion
72
- licenses: []
72
+ licenses:
73
+ - MIT
73
74
  metadata: {}
74
75
  post_install_message:
75
76
  rdoc_options: []