afmotion 0.9.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,47 +1,52 @@
1
1
  describe "AFMotion::ClientDSL" do
2
2
  before do
3
- @client = AFHTTPClient.clientWithBaseURL("http://url".to_url)
3
+ @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://url".to_url)
4
4
  @dsl = AFMotion::ClientDSL.new(@client)
5
5
  end
6
6
 
7
7
  describe "#header" do
8
8
  it "should set header" do
9
9
  @dsl.header "Accept", "application/json"
10
- @client.defaultValueForHeader("Accept").should == "application/json"
10
+ @client.requestSerializer.HTTPRequestHeaders["Accept"].should == "application/json"
11
11
  end
12
12
  end
13
13
 
14
14
  describe "#authorization" do
15
15
  it "should set authorization" do
16
16
  @dsl.authorization username: "clay", password: "test"
17
- @client.defaultValueForHeader("Authorization").nil?.should == false
17
+ @client.requestSerializer.HTTPRequestHeaders["Authorization"].nil?.should == false
18
18
  end
19
19
  end
20
20
 
21
- describe "#operation" do
22
- it "should set operation if provided type" do
23
- @dsl.operation AFJSONRequestOperation
24
- @client.registeredHTTPOperationClassNames.member?("AFJSONRequestOperation").should == true
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
25
  end
26
26
 
27
- it "should set operation if provided string" do
28
- [["json", "AFJSONRequestOperation"], ["xml", "AFXMLRequestOperation"], ["plist", "AFPropertyListRequestOperation"]].each do |op, op_class|
29
- @dsl.operation op
30
- @client.registeredHTTPOperationClassNames.member?(op_class).should == true
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
31
  end
32
32
  end
33
33
  end
34
34
 
35
- describe "#parameter_encoding" do
36
- it "should set encoding if provided type" do
37
- @dsl.parameter_encoding AFJSONParameterEncoding
38
- @client.parameterEncoding.should == AFJSONParameterEncoding
39
- end
40
-
41
- it "should set encoding if provided string" do
42
- [["json", AFJSONParameterEncoding], ["form", AFFormURLParameterEncoding], ["plist", AFPropertyListParameterEncoding]].each do |enc, enc_class|
43
- @dsl.parameter_encoding enc
44
- @client.parameterEncoding.should == enc_class
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
45
50
  end
46
51
  end
47
52
  end
@@ -49,9 +54,9 @@ end
49
54
 
50
55
  describe "AFMotion::Client" do
51
56
  describe ".build" do
52
- it "should return an AFHTTPClient" do
57
+ it "should return an AFHTTPRequestOperationManager" do
53
58
  client = AFMotion::Client.build("http://url")
54
- client.is_a?(AFHTTPClient).should == true
59
+ client.is_a?(AFHTTPRequestOperationManager).should == true
55
60
  end
56
61
  end
57
62
 
@@ -65,7 +70,7 @@ end
65
70
 
66
71
  describe "AFHTTPClient" do
67
72
  before do
68
- @client = AFHTTPClient.clientWithBaseURL("http://google.com/".to_url)
73
+ @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://google.com/".to_url)
69
74
  end
70
75
 
71
76
  describe "URL Helpers" do
@@ -91,21 +96,21 @@ describe "AFHTTPClient" do
91
96
  describe "#authorization=" do
92
97
  it "should set basic auth" do
93
98
  @client.authorization = {username: "clay", password: "pass"}
94
- @client.defaultValueForHeader("Authorization").split[0].should == "Basic"
99
+ @client.requestSerializer.HTTPRequestHeaders["Authorization"].split[0].should == "Basic"
95
100
  end
96
101
  end
97
102
 
98
103
  describe "#build_shared" do
99
104
  it "should set AFMotion::Client.shared" do
100
105
  @client.authorization = {token: "clay"}
101
- @client.defaultValueForHeader("Authorization").split[0].should == "Token"
106
+ @client.requestSerializer.HTTPRequestHeaders["Authorization"].split[0].should == "Token"
102
107
  end
103
108
  end
104
109
 
105
110
  describe "#headers" do
106
111
  describe "#[]" do
107
112
  it "should return a header" do
108
- @client.setDefaultHeader("test", value: "test_value")
113
+ @client.requestSerializer.setValue("test_value", forHTTPHeaderField: "test")
109
114
  @client.headers["test"].should == "test_value"
110
115
  end
111
116
  end
@@ -113,29 +118,24 @@ describe "AFHTTPClient" do
113
118
  describe "#[]=" do
114
119
  it "should set a header" do
115
120
  @client.headers["test"] = "test_set_value"
116
- @client.defaultValueForHeader("test").should == "test_set_value"
121
+ @client.requestSerializer.HTTPRequestHeaders["test"].should == "test_set_value"
117
122
  end
118
123
  end
119
124
 
120
125
  describe "#delete" do
121
126
  it "should remove a header" do
122
- @client.setDefaultHeader("test", value: "test_value")
127
+ @client.requestSerializer.setValue("test_value", forHTTPHeaderField: "test")
123
128
  @client.headers.delete("test").should == "test_value"
124
- @client.defaultValueForHeader("test").should == nil
129
+ @client.requestSerializer.HTTPRequestHeaders["test"].should == nil
125
130
  end
126
131
  end
127
132
  end
128
133
 
129
- describe "#multipart" do
130
- it "should trigger multipart logic" do
131
- @client.multipart!.should == @client
132
- @client.instance_variable_get("@multipart").should == true
133
- end
134
-
134
+ describe "#multipart_post" do
135
135
  it "should trigger multipart request" do
136
- @client.multipart!.post("", test: "Herp") do |result|
136
+ @client.multipart_post("", test: "Herp") do |result, form_data|
137
137
  @result = result
138
- resume
138
+ resume if result
139
139
  end
140
140
 
141
141
  wait_max(10) do
@@ -145,7 +145,7 @@ describe "AFHTTPClient" do
145
145
  end
146
146
 
147
147
  it "should work with form data" do
148
- @client.multipart!.post("", test: "Herp") do |result, form_data|
148
+ @client.multipart_post("", test: "Herp") do |result, form_data|
149
149
  if result
150
150
  resume
151
151
  else
@@ -161,8 +161,8 @@ describe "AFHTTPClient" do
161
161
  it "should have upload callback with raw progress" do
162
162
  image = UIImage.imageNamed("test")
163
163
  @data = UIImagePNGRepresentation(image)
164
- @client = AFHTTPClient.clientWithBaseURL("http://bing.com/".to_url)
165
- @client.multipart!.post("", test: "Herp") do |result, form_data, progress|
164
+ @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://bing.com/".to_url)
165
+ @client.multipart_post("", test: "Herp") do |result, form_data, progress|
166
166
  if form_data
167
167
  form_data.appendPartWithFileData(@data, name: "test", fileName:"test.png", mimeType: "image/png")
168
168
  elsif progress
data/spec/http_spec.rb CHANGED
@@ -24,17 +24,6 @@ describe "AFMotion" do
24
24
  @result.nil?.should == false
25
25
  end
26
26
  end
27
-
28
- it "should work with request" do
29
- request = NSURLRequest.requestWithURL(NSURL.URLWithString("http://google.com"))
30
- _module.get(request) do |result|
31
- @result = result
32
- resume
33
- end
34
- wait_max(10) do
35
- @result.nil?.should == false
36
- end
37
- end
38
27
  end
39
28
  end
40
29
  end
@@ -0,0 +1,217 @@
1
+ describe "AFMotion::SessionClientDSL" do
2
+ before do
3
+ @dsl = AFMotion::SessionClientDSL.new("http://url")
4
+ end
5
+
6
+ describe "#header" do
7
+ it "should set header" do
8
+ @dsl.header "Accept", "application/json"
9
+ @dsl.to_session_manager.requestSerializer.HTTPRequestHeaders["Accept"].should == "application/json"
10
+ end
11
+ end
12
+
13
+ describe "#authorization" do
14
+ it "should set authorization" do
15
+ @dsl.authorization username: "clay", password: "test"
16
+ @dsl.to_session_manager.requestSerializer.HTTPRequestHeaders["Authorization"].nil?.should == false
17
+ end
18
+ end
19
+
20
+ describe "#request_serializer" do
21
+ it "should set request_serializer if provided type" do
22
+ @dsl.request_serializer AFJSONRequestSerializer
23
+ @dsl.to_session_manager.requestSerializer.is_a?(AFJSONRequestSerializer).should == true
24
+ end
25
+
26
+ it "should set request_serializer if provided string" do
27
+ [["json", AFJSONRequestSerializer], ["plist", AFPropertyListRequestSerializer]].each do |op, op_class|
28
+ @dsl.request_serializer op
29
+ @dsl.to_session_manager.requestSerializer.is_a?(op_class).should == true
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#response_serializer" do
35
+ it "should set response_serializer if provided type" do
36
+ @dsl.response_serializer AFJSONResponseSerializer
37
+ @dsl.to_session_manager.responseSerializer.is_a?(AFJSONResponseSerializer).should == true
38
+ end
39
+
40
+ it "should set response_serializer if provided string" do
41
+ [["json", AFJSONResponseSerializer],
42
+ ["form", AFHTTPResponseSerializer],
43
+ ["http", AFHTTPResponseSerializer],
44
+ ["xml", AFXMLParserResponseSerializer],
45
+ ["plist", AFPropertyListResponseSerializer],
46
+ ["image", AFImageResponseSerializer]].each do |enc, enc_class|
47
+ @dsl.response_serializer enc
48
+ @dsl.to_session_manager.responseSerializer.is_a?(enc_class).should == true
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#session_configuration" do
54
+ describe "for default" do
55
+ it "should work" do
56
+ @dsl.session_configuration :default
57
+ @dsl.to_session_manager.sessionConfiguration.URLCache.diskCapacity.should > 0
58
+ end
59
+ end
60
+
61
+ describe "for ephemeral" do
62
+ it "should work" do
63
+ @dsl.session_configuration :ephemeral
64
+ @dsl.to_session_manager.sessionConfiguration.URLCache.diskCapacity.should == 0
65
+ end
66
+ end
67
+
68
+ describe "for background" do
69
+ it "should work" do
70
+ @dsl.session_configuration :background, "com.usepropeller.afmotion.test"
71
+ manager = @dsl.to_session_manager
72
+ manager.sessionConfiguration.sessionSendsLaunchEvents.should == true
73
+ manager.sessionConfiguration.identifier.should == "com.usepropeller.afmotion.test"
74
+ end
75
+ end
76
+
77
+ describe "for instances" do
78
+ it "should work" do
79
+ session_config = NSURLSessionConfiguration.defaultSessionConfiguration
80
+ session_config.identifier = "test"
81
+ @dsl.session_configuration session_config
82
+ @dsl.to_session_manager.sessionConfiguration.should == session_config
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "AFMotion::SessionClient" do
89
+ describe ".build" do
90
+ it "should return an AFHTTPSessionManager" do
91
+ client = AFMotion::SessionClient.build("http://url") do
92
+ end
93
+ client.is_a?(AFHTTPSessionManager).should == true
94
+ end
95
+ end
96
+
97
+ describe ".build_shared" do
98
+ it "should set AFMotion::SessionClient.shared" do
99
+ client = AFMotion::SessionClient.build_shared("http://url") do
100
+ end
101
+ AFMotion::SessionClient.shared.should == client
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "AFHTTPSessionManager" do
107
+ before do
108
+ @client = AFHTTPSessionManager.alloc.initWithBaseURL("http://google.com/".to_url,
109
+ sessionConfiguration: NSURLSessionConfiguration.defaultSessionConfiguration)
110
+ end
111
+
112
+ describe "URL Helpers" do
113
+ it "should exist" do
114
+ AFMotion::HTTP_METHODS.each do |method|
115
+ @client.respond_to?(method).should == true
116
+ end
117
+ end
118
+ end
119
+
120
+ # Pretty basic test
121
+ it "should work" do
122
+ @result = nil
123
+ @client.get("") do |result|
124
+ @result = result
125
+ resume
126
+ end
127
+ wait_max(10) do
128
+ @result.nil?.should == false
129
+ end
130
+ end
131
+
132
+ describe "#authorization=" do
133
+ it "should set basic auth" do
134
+ @client.authorization = {username: "clay", password: "pass"}
135
+ @client.requestSerializer.HTTPRequestHeaders["Authorization"].split[0].should == "Basic"
136
+ end
137
+ end
138
+
139
+ describe "#build_shared" do
140
+ it "should set AFMotion::Client.shared" do
141
+ @client.authorization = {token: "clay"}
142
+ @client.requestSerializer.HTTPRequestHeaders["Authorization"].split[0].should == "Token"
143
+ end
144
+ end
145
+
146
+ describe "#headers" do
147
+ describe "#[]" do
148
+ it "should return a header" do
149
+ @client.requestSerializer.setValue("test_value", forHTTPHeaderField: "test")
150
+ @client.headers["test"].should == "test_value"
151
+ end
152
+ end
153
+
154
+ describe "#[]=" do
155
+ it "should set a header" do
156
+ @client.headers["test"] = "test_set_value"
157
+ @client.requestSerializer.HTTPRequestHeaders["test"].should == "test_set_value"
158
+ end
159
+ end
160
+
161
+ describe "#delete" do
162
+ it "should remove a header" do
163
+ @client.requestSerializer.setValue("test_value", forHTTPHeaderField: "test")
164
+ @client.headers.delete("test").should == "test_value"
165
+ @client.requestSerializer.HTTPRequestHeaders["test"].should == nil
166
+ end
167
+ end
168
+ end
169
+
170
+ describe "#multipart_post" do
171
+ it "should trigger multipart request" do
172
+ @client.multipart_post("", test: "Herp") do |result, form_data|
173
+ @result = result
174
+ resume if result
175
+ end
176
+
177
+ wait_max(10) do
178
+ @result.should.not == nil
179
+ @result.task.currentRequest.valueForHTTPHeaderField("Content-Type").include?("multipart/form-data").should == true
180
+ end
181
+ end
182
+
183
+ it "should work with form data" do
184
+ @client.multipart_post("", test: "Herp") do |result, form_data|
185
+ if result
186
+ resume
187
+ else
188
+ @form_data = form_data
189
+ end
190
+ end
191
+
192
+ wait_max(10) do
193
+ @form_data.should.not == nil
194
+ end
195
+ end
196
+
197
+ it "should have upload callback with raw progress" do
198
+ image = UIImage.imageNamed("test")
199
+ @data = UIImagePNGRepresentation(image)
200
+ @client = AFHTTPRequestOperationManager.alloc.initWithBaseURL("http://bing.com/".to_url)
201
+ @client.multipart_post("", test: "Herp") do |result, form_data, progress|
202
+ if form_data
203
+ form_data.appendPartWithFileData(@data, name: "test", fileName:"test.png", mimeType: "image/png")
204
+ elsif progress
205
+ @progress ||= progress
206
+ elsif result
207
+ resume
208
+ end
209
+ end
210
+
211
+ wait_max(20) do
212
+ @progress.should <= 1.0
213
+ @progress.should.not == nil
214
+ end
215
+ end
216
+ end
217
+ end
data/vendor/Podfile.lock CHANGED
@@ -1,10 +1,29 @@
1
1
  PODS:
2
- - AFNetworking (1.0.1)
2
+ - AFNetworking (2.0.1):
3
+ - AFNetworking/NSURLConnection
4
+ - AFNetworking/NSURLSession
5
+ - AFNetworking/Reachability
6
+ - AFNetworking/Security
7
+ - AFNetworking/Serialization
8
+ - AFNetworking/UIKit
9
+ - AFNetworking/NSURLConnection (2.0.1):
10
+ - AFNetworking/Reachability
11
+ - AFNetworking/Security
12
+ - AFNetworking/Serialization
13
+ - AFNetworking/NSURLSession (2.0.1):
14
+ - AFNetworking/Reachability
15
+ - AFNetworking/Security
16
+ - AFNetworking/Serialization
17
+ - AFNetworking/Reachability (2.0.1)
18
+ - AFNetworking/Security (2.0.1)
19
+ - AFNetworking/Serialization (2.0.1)
20
+ - AFNetworking/UIKit (2.0.1):
21
+ - AFNetworking/NSURLConnection
3
22
 
4
23
  DEPENDENCIES:
5
- - AFNetworking
24
+ - AFNetworking (~> 2.0.0)
6
25
 
7
26
  SPEC CHECKSUMS:
8
- AFNetworking: 0bce3ae41023e080e96b8a2e0d07c94709f72a81
27
+ AFNetworking: a6f11ac4ac087303e6ff87adc1ba57b0dac20ef8
9
28
 
10
- COCOAPODS: 0.23.0
29
+ COCOAPODS: 0.26.2
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.9.0
4
+ version: 2.0.0.rc1
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-17 00:00:00.000000000 Z
11
+ date: 2013-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: motion-cocoapods
@@ -16,26 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.6
19
+ version: 1.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.6
26
+ version: 1.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: motion-require
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.7
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ! '>='
45
+ - - '>='
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ! '>='
52
+ - - '>='
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  description: A RubyMotion Wrapper for AFNetworking
@@ -54,19 +68,20 @@ files:
54
68
  - Rakefile
55
69
  - app/app_delegate.rb
56
70
  - lib/afmotion.rb
71
+ - lib/afmotion/client_shared.rb
57
72
  - lib/afmotion/http.rb
58
73
  - lib/afmotion/http_client.rb
59
74
  - lib/afmotion/http_result.rb
60
- - lib/afmotion/image.rb
61
75
  - lib/afmotion/operation.rb
62
76
  - lib/afmotion/patch/NSString_NSUrl.rb
63
- - lib/afmotion/patch/NSURLRequest_params.rb
77
+ - lib/afmotion/patch/UIImageView_url.rb
78
+ - lib/afmotion/serializer.rb
79
+ - lib/afmotion/session_client.rb
64
80
  - lib/afmotion/version.rb
65
81
  - resources/test.png
66
82
  - spec/http_client_spec.rb
67
83
  - spec/http_spec.rb
68
- - spec/ns_url_request_spec.rb
69
- - spec/operation_spec.rb
84
+ - spec/session_client_spec.rb
70
85
  - vendor/Podfile.lock
71
86
  homepage: https://github.com/clayallsopp/AFMotion
72
87
  licenses:
@@ -78,14 +93,14 @@ require_paths:
78
93
  - lib
79
94
  required_ruby_version: !ruby/object:Gem::Requirement
80
95
  requirements:
81
- - - ! '>='
96
+ - - '>='
82
97
  - !ruby/object:Gem::Version
83
98
  version: '0'
84
99
  required_rubygems_version: !ruby/object:Gem::Requirement
85
100
  requirements:
86
- - - ! '>='
101
+ - - '>'
87
102
  - !ruby/object:Gem::Version
88
- version: '0'
103
+ version: 1.3.1
89
104
  requirements: []
90
105
  rubyforge_project:
91
106
  rubygems_version: 2.0.3
@@ -95,5 +110,4 @@ summary: A RubyMotion Wrapper for AFNetworking
95
110
  test_files:
96
111
  - spec/http_client_spec.rb
97
112
  - spec/http_spec.rb
98
- - spec/ns_url_request_spec.rb
99
- - spec/operation_spec.rb
113
+ - spec/session_client_spec.rb
@@ -1,49 +0,0 @@
1
- class NSMutableURLRequest
2
- alias_method :url, :URL
3
-
4
- def url=(url)
5
- self.setURL(url.to_url)
6
- end
7
-
8
- def content_type=(content_type)
9
- self.setValue(content_type, forHTTPHeaderField: "Content-Type")
10
- end
11
-
12
- def parameters=(params = {})
13
- method = self.HTTPMethod
14
-
15
- af_encoding = params[:__encoding__] || AFFormURLParameterEncoding
16
- string_encoding = params[:__string_encoding__] || NSUTF8StringEncoding
17
-
18
- params.delete :__encoding__
19
- params.delete :__string_encoding__
20
-
21
- use_url_based_params = ["GET", "HEAD", "DELETE", "PUT"].member?(method)
22
-
23
- if use_url_based_params && !params.empty?
24
- url_string = String.new(self.url.absoluteString)
25
- has_query = url_string.rangeOfString("?").location == NSNotFound
26
- format = has_query ? "?" : "&"
27
- encoded = AFQueryStringFromParametersWithEncoding(params, string_encoding)
28
- self.url = (url_string << format) << encoded
29
- elsif !use_url_based_params
30
- charset = CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(string_encoding))
31
- error = Pointer.new(:object)
32
- case af_encoding
33
- when AFFormURLParameterEncoding
34
- self.content_type = "application/x-www-form-urlencoded; charset=%@" << charset
35
- self.HTTPBody = AFQueryStringFromParametersWithEncoding(params, string_encoding).dataUsingEncoding(string_encoding)
36
- when AFJSONParameterEncoding
37
- self.content_type = "application/json; charset=%@" << charset
38
- self.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: 0, error: error)
39
- when AFPropertyListParameterEncoding
40
- self.content_type = "application/x-plist; charset=%@" << charset
41
- self.HTTPBody = NSPropertyListSerialization.dataWithPropertyList(params, format: NSPropertyListXMLFormat_v1_0, options: 0, error: error)
42
- end
43
-
44
- if error[0]
45
- p "NSURLRequest #{self.inspect}#parameters=#{params.inspect} ERROR: #{error.localizedDescription}"
46
- end
47
- end
48
- end
49
- end
@@ -1,41 +0,0 @@
1
- describe "NSMutableURLRequest" do
2
- describe "parameters=" do
3
- before do
4
- @base_url = "http://google.com"
5
- end
6
-
7
- ["GET", "HEAD", "DELETE", "PUT"].each do |method|
8
- it "should work with #{method} requests" do
9
- @request = NSMutableURLRequest.requestWithURL(NSURL.URLWithString(@base_url))
10
-
11
- @request.HTTPMethod = method
12
-
13
- @request.parameters = {herp: "derp", "another" => 3}
14
- @request.url.absoluteString.should == "http://google.com?herp=derp&another=3"
15
- end
16
- end
17
-
18
- [:default, :URL, :JSON, :XML].each do |encoding|
19
- it "POST should work with #{encoding} encoding" do
20
- @request = NSMutableURLRequest.requestWithURL(NSURL.URLWithString(@base_url))
21
- @request.HTTPMethod = "POST"
22
-
23
- parameters = {herp: "derp", "another" => 3}
24
- case encoding
25
- when :URL
26
- @request.parameters = parameters.merge({__encoding__: AFFormURLParameterEncoding})
27
- String.new(@request.HTTPBody).should == "herp=derp&another=3"
28
- when :JSON
29
- @request.parameters = parameters.merge({__encoding__: AFJSONParameterEncoding})
30
- String.new(@request.HTTPBody).should == "{\"herp\":\"derp\",\"another\":3}"
31
- when :XML
32
- @request.parameters = parameters.merge({__encoding__: AFPropertyListParameterEncoding})
33
- String.new(@request.HTTPBody).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>another</key>\n\t<integer>3</integer>\n\t<key>herp</key>\n\t<string>derp</string>\n</dict>\n</plist>\n"
34
- else
35
- @request.parameters = parameters
36
- String.new(@request.HTTPBody).should == "herp=derp&another=3"
37
- end
38
- end
39
- end
40
- end
41
- end