bubble-wrap 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/bubble-wrap/version.rb +1 -1
- data/motion/core.rb +2 -4
- data/motion/core/kvo.rb +7 -7
- data/motion/core/persistence.rb +3 -3
- data/motion/http.rb +41 -16
- data/motion/rss_parser.rb +22 -9
- data/spec/motion/core/kvo_spec.rb +5 -6
- data/spec/motion/core/string_spec.rb +1 -3
- data/spec/motion/core/time_spec.rb +12 -12
- data/spec/motion/http_spec.rb +68 -27
- metadata +10 -10
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 1.1.1
|
2
|
+
|
3
|
+
* Fixed a bug with the way JSON payloads were handled in the HTTP
|
4
|
+
wrapper.
|
5
|
+
* Improved the RSSParser by providing a delegate to handle errors.
|
6
|
+
* Added support for symbols as selectors to the KVO module.
|
7
|
+
* Fixed a bug with the way the headers and content types were handled in
|
8
|
+
the HTTP wrapper.
|
9
|
+
|
1
10
|
## 1.1.0
|
2
11
|
|
3
12
|
[Commit history](https://github.com/rubymotion/BubbleWrap/compare/1.0...1.1])
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -291,13 +291,13 @@ class ExampleViewController < UIViewController
|
|
291
291
|
@label.text = ""
|
292
292
|
view.addSubview @label
|
293
293
|
|
294
|
-
observe(@label,
|
294
|
+
observe(@label, :text) do |old_value, new_value|
|
295
295
|
puts "Hello from viewDidLoad!"
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
299
299
|
def viewDidAppear(animated)
|
300
|
-
observe(@label,
|
300
|
+
observe(@label, :text) do |old_value, new_value|
|
301
301
|
puts "Hello from viewDidAppear!"
|
302
302
|
end
|
303
303
|
end
|
data/lib/bubble-wrap/version.rb
CHANGED
data/motion/core.rb
CHANGED
data/motion/core/kvo.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Usage example:
|
2
2
|
#
|
3
3
|
# class ExampleViewController < UIViewController
|
4
|
-
# include
|
4
|
+
# include BubbleWrap::KVO
|
5
5
|
#
|
6
6
|
# def viewDidLoad
|
7
7
|
# @label = UILabel.alloc.initWithFrame [[20,20],[280,44]]
|
8
8
|
# @label.text = ""
|
9
9
|
# view.addSubview @label
|
10
10
|
#
|
11
|
-
# observe(@label,
|
11
|
+
# observe(@label, :text) do |old_value, new_value|
|
12
12
|
# puts "Changed #{old_value} to #{new_value}"
|
13
13
|
# end
|
14
14
|
# end
|
@@ -48,7 +48,7 @@ module BubbleWrap
|
|
48
48
|
|
49
49
|
private
|
50
50
|
def registered?(target, key_path)
|
51
|
-
!@targets.nil? && !@targets[target].nil? && @targets[target].has_key?(key_path)
|
51
|
+
!@targets.nil? && !@targets[target].nil? && @targets[target].has_key?(key_path.to_s)
|
52
52
|
end
|
53
53
|
|
54
54
|
def add_observer_block(target, key_path, &block)
|
@@ -56,16 +56,16 @@ module BubbleWrap
|
|
56
56
|
|
57
57
|
@targets ||= {}
|
58
58
|
@targets[target] ||= {}
|
59
|
-
@targets[target][key_path] ||= []
|
60
|
-
@targets[target][key_path] << block
|
59
|
+
@targets[target][key_path.to_s] ||= []
|
60
|
+
@targets[target][key_path.to_s] << block
|
61
61
|
end
|
62
62
|
|
63
63
|
def remove_observer_block(target, key_path)
|
64
64
|
return if @targets.nil? || target.nil? || key_path.nil?
|
65
65
|
|
66
66
|
key_paths = @targets[target]
|
67
|
-
if !key_paths.nil? && key_paths.has_key?(key_path)
|
68
|
-
key_paths.delete(key_path)
|
67
|
+
if !key_paths.nil? && key_paths.has_key?(key_path.to_s)
|
68
|
+
key_paths.delete(key_path.to_s)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
data/motion/core/persistence.rb
CHANGED
@@ -8,17 +8,17 @@ module BubbleWrap
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def []=(key, value)
|
11
|
-
storage.setObject(value, forKey: storage_key(key
|
11
|
+
storage.setObject(value, forKey: storage_key(key))
|
12
12
|
storage.synchronize
|
13
13
|
end
|
14
14
|
|
15
15
|
def [](key)
|
16
|
-
storage.objectForKey storage_key(key
|
16
|
+
storage.objectForKey storage_key(key)
|
17
17
|
end
|
18
18
|
|
19
19
|
def merge(values)
|
20
20
|
values.each do |key, value|
|
21
|
-
storage.setObject(value, forKey: storage_key(key
|
21
|
+
storage.setObject(value, forKey: storage_key(key))
|
22
22
|
end
|
23
23
|
storage.synchronize
|
24
24
|
end
|
data/motion/http.rb
CHANGED
@@ -22,19 +22,19 @@ module BubbleWrap
|
|
22
22
|
options[:action] = block if block_given?
|
23
23
|
HTTP::Query.new(url, :get, options)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# Make a POST request
|
27
27
|
def self.post(url, options={}, &block)
|
28
28
|
options[:action] = block if block_given?
|
29
29
|
HTTP::Query.new(url, :post, options)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# Make a PUT request
|
33
33
|
def self.put(url, options={}, &block)
|
34
34
|
options[:action] = block if block_given?
|
35
35
|
HTTP::Query.new(url, :put, options)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# Make a DELETE request
|
39
39
|
def self.delete(url, options={}, &block)
|
40
40
|
options[:action] = block if block_given?
|
@@ -155,7 +155,9 @@ Cache policy: #{@cache_policy}, response: #{@response.inspect} >"
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def connection(connection, willSendRequest:request, redirectResponse:redirect_response)
|
158
|
-
|
158
|
+
@redirection ||= 0
|
159
|
+
@redirection += 1
|
160
|
+
log "##{@redirection} HTTP redirection: #{request} - #{self.description}"
|
159
161
|
new_request = request.mutableCopy
|
160
162
|
# new_request.setValue(@credentials.inspect, forHTTPHeaderField:'Authorization') # disabled while we figure this one out
|
161
163
|
new_request.setAllHTTPHeaderFields(@headers) if @headers
|
@@ -218,14 +220,23 @@ Cache policy: #{@cache_policy}, response: #{@response.inspect} >"
|
|
218
220
|
def create_request_body
|
219
221
|
return nil if (@method == "GET" || @method == "HEAD")
|
220
222
|
return nil unless (@payload || @files)
|
221
|
-
|
223
|
+
|
224
|
+
# if no headers provided, set content-type automatically
|
225
|
+
if @headers.nil?
|
226
|
+
@headers = {"Content-Type" => "multipart/form-data; boundary=#{@boundary}"}
|
227
|
+
# else set content type unless it is specified
|
228
|
+
# if content-type is specified, you should probably also specify
|
229
|
+
# the :boundary key
|
230
|
+
else
|
231
|
+
@headers['Content-Type'] = "multipart/form-data; boundary=#{@boundary}" unless @headers.keys.find {|k| k.downcase == 'content-type'}
|
232
|
+
end
|
222
233
|
|
223
234
|
body = NSMutableData.data
|
224
235
|
|
225
236
|
append_payload(body) if @payload
|
226
237
|
append_files(body) if @files
|
227
|
-
body
|
228
|
-
|
238
|
+
append_body_boundary(body) if @set_body_to_close_boundary
|
239
|
+
|
229
240
|
log "Built HTTP body: \n #{body.to_str}"
|
230
241
|
body
|
231
242
|
end
|
@@ -236,17 +247,25 @@ Cache policy: #{@cache_policy}, response: #{@response.inspect} >"
|
|
236
247
|
else
|
237
248
|
append_form_params(body)
|
238
249
|
end
|
250
|
+
body
|
239
251
|
end
|
240
252
|
|
241
253
|
def append_form_params(body)
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
254
|
+
# puts "*** append_form #{@payload}"
|
255
|
+
if @payload.is_a?(String)
|
256
|
+
body.appendData(@payload.dataUsingEncoding NSUTF8StringEncoding)
|
257
|
+
else
|
258
|
+
@payload.each do |key, value|
|
259
|
+
form_data = NSMutableData.new
|
260
|
+
s = "\r\n--#{@boundary}\r\n"
|
261
|
+
s += "Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n"
|
262
|
+
s += value.to_s
|
263
|
+
form_data.appendData(s.dataUsingEncoding NSUTF8StringEncoding)
|
264
|
+
body.appendData(form_data)
|
265
|
+
end
|
266
|
+
@set_body_to_close_boundary = true
|
249
267
|
end
|
268
|
+
body
|
250
269
|
end
|
251
270
|
|
252
271
|
def append_files(body)
|
@@ -259,6 +278,12 @@ Cache policy: #{@cache_policy}, response: #{@response.inspect} >"
|
|
259
278
|
file_data.appendData(value)
|
260
279
|
body.appendData(file_data)
|
261
280
|
end
|
281
|
+
@set_body_to_close_boundary = true
|
282
|
+
body
|
283
|
+
end
|
284
|
+
|
285
|
+
def append_body_boundary(body)
|
286
|
+
body.appendData("\r\n--#{@boundary}--\r\n".dataUsingEncoding NSUTF8StringEncoding)
|
262
287
|
end
|
263
288
|
|
264
289
|
def create_url(url_string)
|
@@ -301,14 +326,14 @@ Cache policy: #{@cache_policy}, response: #{@response.inspect} >"
|
|
301
326
|
def escape_line_feeds(hash)
|
302
327
|
return nil if hash.nil?
|
303
328
|
escaped_hash = {}
|
304
|
-
|
329
|
+
|
305
330
|
hash.each{|k,v| escaped_hash[k] = v.gsub("\n", '\\n') }
|
306
331
|
escaped_hash
|
307
332
|
end
|
308
333
|
|
309
334
|
def patch_nsurl_request(request)
|
310
335
|
request.instance_variable_set("@done_loading", false)
|
311
|
-
|
336
|
+
|
312
337
|
def request.done_loading; @done_loading; end
|
313
338
|
def request.done_loading!; @done_loading = true; end
|
314
339
|
end
|
data/motion/rss_parser.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
# def when_parser_initializes; end
|
6
6
|
# def when_parser_parses; end
|
7
7
|
# def when_parser_is_done; end
|
8
|
+
# def when_parser_errors; end
|
8
9
|
#
|
9
10
|
# @see https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html
|
10
11
|
#
|
@@ -21,7 +22,7 @@
|
|
21
22
|
module BubbleWrap
|
22
23
|
class RSSParser
|
23
24
|
|
24
|
-
attr_accessor :parser, :source, :doc, :debug, :delegate
|
25
|
+
attr_accessor :parser, :source, :doc, :debug, :delegate, :parser_error
|
25
26
|
attr_reader :state
|
26
27
|
|
27
28
|
# RSSItem is a simple class that holds all of RSS items.
|
@@ -84,8 +85,8 @@ module BubbleWrap
|
|
84
85
|
|
85
86
|
# Delegate getting called when parsing starts
|
86
87
|
def parserDidStartDocument(parser)
|
87
|
-
self.state = :parses
|
88
88
|
puts "starting parsing.." if debug
|
89
|
+
self.state = :parses
|
89
90
|
end
|
90
91
|
|
91
92
|
# Delegate being called when an element starts being processed
|
@@ -97,33 +98,45 @@ module BubbleWrap
|
|
97
98
|
end
|
98
99
|
@current_element = element
|
99
100
|
end
|
100
|
-
|
101
|
+
|
101
102
|
# as the parser finds characters, this method is being called
|
102
103
|
def parser(parser, foundCharacters:string)
|
103
104
|
if @current_element && @current_item && @current_item.respond_to?(@current_element)
|
104
|
-
el = @current_item.send(@current_element)
|
105
|
+
el = @current_item.send(@current_element)
|
105
106
|
el << string if el.respond_to?(:<<)
|
106
107
|
end
|
107
108
|
end
|
108
|
-
|
109
|
+
|
109
110
|
# method called when an element is done being parsed
|
110
111
|
def parser(parser, didEndElement:element, namespaceURI:uri, qualifiedName:name)
|
111
112
|
if element == 'item'
|
112
113
|
@block.call(@current_item) if @block
|
113
|
-
else
|
114
|
+
else
|
114
115
|
@current_element = nil
|
115
116
|
end
|
116
117
|
end
|
117
|
-
|
118
|
+
|
119
|
+
# method called when the parser encounters an error
|
120
|
+
# error can be retrieved with parserError
|
121
|
+
def parser(parser, parseErrorOccurred:parse_error)
|
122
|
+
puts "parseErrorOccurred" if debug
|
123
|
+
@parse_error = parse_error
|
124
|
+
|
125
|
+
self.state = :errors
|
126
|
+
end
|
127
|
+
|
118
128
|
# delegate getting called when the parsing is done
|
119
129
|
# If a block was set, it will be called on each parsed items
|
120
130
|
def parserDidEndDocument(parser)
|
121
|
-
self.state = :is_done
|
122
131
|
puts "done parsing" if debug
|
132
|
+
self.state = :is_done
|
133
|
+
end
|
134
|
+
|
135
|
+
def parserError
|
136
|
+
@parser_error || @parser.parserError
|
123
137
|
end
|
124
138
|
|
125
139
|
# TODO: implement
|
126
|
-
# parser:parseErrorOccurred:
|
127
140
|
# parser:validationErrorOccurred:
|
128
141
|
# parser:foundCDATA:
|
129
142
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
describe
|
1
|
+
describe BubbleWrap::KVO do
|
2
2
|
|
3
3
|
class KvoExample
|
4
|
-
include
|
4
|
+
include BubbleWrap::KVO
|
5
5
|
|
6
6
|
attr_accessor :label
|
7
7
|
attr_accessor :items
|
@@ -16,15 +16,15 @@ describe "KVOHelper" do
|
|
16
16
|
# Test helper
|
17
17
|
|
18
18
|
def observe_label(&block)
|
19
|
-
observe(@label,
|
19
|
+
observe(@label, :text, &block)
|
20
20
|
end
|
21
21
|
|
22
22
|
def observe_collection(&block)
|
23
|
-
observe(self,
|
23
|
+
observe(self, :items, &block)
|
24
24
|
end
|
25
25
|
|
26
26
|
def unobserve_label
|
27
|
-
unobserve(@label,
|
27
|
+
unobserve(@label, :text)
|
28
28
|
end
|
29
29
|
|
30
30
|
# def unobserve_all
|
@@ -34,7 +34,6 @@ describe "KVOHelper" do
|
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
37
|
describe "Callbacks" do
|
39
38
|
before do
|
40
39
|
@example = KvoExample.new
|
@@ -104,8 +104,7 @@ describe BubbleWrap::String do
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
describe "A UIColor should not be created from an invalid String
|
108
|
-
|
107
|
+
describe "A UIColor should not be created from an invalid String" do
|
109
108
|
|
110
109
|
it "an invalid hex color" do
|
111
110
|
should.raise( ArgumentError ) {
|
@@ -118,7 +117,6 @@ describe BubbleWrap::String do
|
|
118
117
|
'FFFF'.to_color
|
119
118
|
}
|
120
119
|
end
|
121
|
-
|
122
120
|
|
123
121
|
end
|
124
122
|
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
describe "Time" do
|
2
2
|
|
3
|
-
|
3
|
+
describe "Caching the date formatter" do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
100.times do
|
9
|
-
Time.iso8601("2011-04-11T13:22:21Z")
|
10
|
-
end
|
11
|
-
Thread.current[:date_formatters].count.should.equal 1
|
12
|
-
Thread.current[:date_formatters]["yyyy-MM-dd'T'HH:mm:ss'Z'"].should.not.equal nil
|
5
|
+
it "should reuse the created formatter" do
|
6
|
+
100.times do
|
7
|
+
Time.iso8601("2011-04-11T13:22:21Z")
|
13
8
|
end
|
14
9
|
|
10
|
+
Thread.current[:date_formatters].count.should.equal 1
|
11
|
+
Thread.current[:date_formatters]["yyyy-MM-dd'T'HH:mm:ss'Z'"].should.not.equal nil
|
12
|
+
end
|
13
|
+
|
15
14
|
end
|
16
15
|
|
17
16
|
|
@@ -24,9 +23,10 @@ describe "Time" do
|
|
24
23
|
@time.instance_of?(Time).should == true
|
25
24
|
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
# # Crashes Buggy RubyMotion 1.18
|
27
|
+
# it "should be converted to the local timezone automatically" do
|
28
|
+
# @time.zone.should == Time.now.zone
|
29
|
+
# end
|
30
30
|
|
31
31
|
it "should have a valid year" do
|
32
32
|
@time.utc.year.should == 2012
|
data/spec/motion/http_spec.rb
CHANGED
@@ -22,13 +22,13 @@ describe "HTTP" do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it ".get .post .put .delete .head .patch should properly generate the HTTP::Query" do
|
25
|
-
[:get, :post, :put, :delete, :head, :patch].each do |method|
|
25
|
+
[:get, :post, :put, :delete, :head, :patch].each do |method|
|
26
26
|
test_http_method method
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
it "uses the block instead of action passed in " do
|
31
|
-
[:get, :post, :put, :delete, :head, :patch].each do |method|
|
31
|
+
[:get, :post, :put, :delete, :head, :patch].each do |method|
|
32
32
|
called = false
|
33
33
|
expected_delegator = Proc.new {|response| called = true }
|
34
34
|
|
@@ -36,7 +36,7 @@ describe "HTTP" do
|
|
36
36
|
query.instance_variable_get(:@delegator).should.equal expected_delegator
|
37
37
|
query.connectionDidFinishLoading(query.connection)
|
38
38
|
called.should.equal true
|
39
|
-
end
|
39
|
+
end
|
40
40
|
end
|
41
41
|
|
42
42
|
# [:get, :post, :put, :delete, :head, :patch].each do |verb|
|
@@ -100,8 +100,8 @@ describe "HTTP" do
|
|
100
100
|
|
101
101
|
before do
|
102
102
|
@credentials = { username: 'mneorr', password: '123456xx!@crazy' }
|
103
|
-
@payload = {
|
104
|
-
user: { name: 'marin', surname: 'usalj' },
|
103
|
+
@payload = {
|
104
|
+
user: { name: 'marin', surname: 'usalj' },
|
105
105
|
twitter: '@mneorr',
|
106
106
|
website: 'mneorr.com',
|
107
107
|
values: ['apple', 'orange', 'peach'],
|
@@ -112,15 +112,15 @@ describe "HTTP" do
|
|
112
112
|
@leftover_option = 'trololo'
|
113
113
|
@headers = { 'User-Agent' => "Mozilla/5.0 (X11; Linux x86_64; rv:12.0) \n Gecko/20100101 Firefox/12.0" }
|
114
114
|
@files = {
|
115
|
-
fake_file: NSJSONSerialization.dataWithJSONObject({ fake: 'json' }, options:0, error:nil),
|
115
|
+
fake_file: NSJSONSerialization.dataWithJSONObject({ fake: 'json' }, options:0, error:nil),
|
116
116
|
empty_file: NSMutableData.data
|
117
117
|
}
|
118
|
-
@options = {
|
119
|
-
action: @action,
|
118
|
+
@options = {
|
119
|
+
action: @action,
|
120
120
|
files: @files,
|
121
|
-
payload: @payload,
|
122
|
-
credentials: @credentials,
|
123
|
-
headers: @headers,
|
121
|
+
payload: @payload,
|
122
|
+
credentials: @credentials,
|
123
|
+
headers: @headers,
|
124
124
|
cache_policy: @cache_policy,
|
125
125
|
leftover_option: @leftover_option
|
126
126
|
}
|
@@ -152,7 +152,7 @@ describe "HTTP" do
|
|
152
152
|
@query.instance_variable_get(:@delegator).should.equal @action
|
153
153
|
@options.should.not.has_key? :action
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
it "sets the files to instance variable" do
|
157
157
|
@query.instance_variable_get(:@files).should.equal @files
|
158
158
|
@options.should.not.has_key? :files
|
@@ -190,36 +190,38 @@ describe "HTTP" do
|
|
190
190
|
@query.instance_variable_get(:@payload).should.equal payload
|
191
191
|
@options.should.not.has_key? :payload
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
it "should check if @payload is a hash before generating GET params" do
|
195
195
|
query_string_payload = BubbleWrap::HTTP::Query.new( 'nil' , :get, { payload: "name=apple&model=macbook"} )
|
196
196
|
query_string_payload.instance_variable_get(:@payload).should.equal 'name=apple&model=macbook'
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should check if payload is nil" do
|
200
|
-
lambda{
|
201
|
-
BubbleWrap::HTTP::Query.new( 'nil' , :post, {} )
|
202
|
-
}.should.not.raise NoMethodError
|
203
|
-
end
|
200
|
+
lambda{
|
201
|
+
BubbleWrap::HTTP::Query.new( 'nil' , :post, {} )
|
202
|
+
}.should.not.raise NoMethodError
|
203
|
+
end
|
204
204
|
|
205
205
|
it "should set the payload in URL only for GET and HEAD requests" do
|
206
206
|
[:post, :put, :delete, :patch].each do |method|
|
207
207
|
query = BubbleWrap::HTTP::Query.new( @localhost_url , method, { payload: @payload } )
|
208
208
|
query.instance_variable_get(:@url).description.should.equal @localhost_url
|
209
|
-
end
|
209
|
+
end
|
210
210
|
|
211
211
|
payload = {name: 'marin'}
|
212
212
|
[:get, :head].each do |method|
|
213
213
|
query = BubbleWrap::HTTP::Query.new( @localhost_url , method, { payload: payload } )
|
214
214
|
query.instance_variable_get(:@url).description.should.equal "#{@localhost_url}?name=marin"
|
215
|
-
end
|
215
|
+
end
|
216
216
|
end
|
217
217
|
|
218
218
|
it "sets the HTTPBody DATA to @request for all methods except GET and HEAD" do
|
219
219
|
payload = { name: 'apple', model: 'macbook'}
|
220
220
|
files = { twitter: sample_data, site: "mneorr.com".dataUsingEncoding(NSUTF8StringEncoding) }
|
221
221
|
|
222
|
+
puts "\n"
|
222
223
|
[:post, :put, :delete, :patch].each do |method|
|
224
|
+
puts " - #{method}\n"
|
223
225
|
query = BubbleWrap::HTTP::Query.new( 'nil' , method, { payload: payload, files: files } )
|
224
226
|
uuid = query.instance_variable_get(:@boundary)
|
225
227
|
real_payload = NSString.alloc.initWithData(query.request.HTTPBody, encoding:NSUTF8StringEncoding)
|
@@ -227,6 +229,7 @@ describe "HTTP" do
|
|
227
229
|
end
|
228
230
|
|
229
231
|
[:get, :head].each do |method|
|
232
|
+
puts " - #{method}\n"
|
230
233
|
query = BubbleWrap::HTTP::Query.new( 'nil' , method, { payload: payload } )
|
231
234
|
real_payload = NSString.alloc.initWithData(query.request.HTTPBody, encoding:NSUTF8StringEncoding)
|
232
235
|
real_payload.should.be.empty
|
@@ -238,6 +241,17 @@ describe "HTTP" do
|
|
238
241
|
lambda { query = create_query(data, nil) }.should.not.raise NoMethodError
|
239
242
|
end
|
240
243
|
|
244
|
+
it "sets the payload as a string if JSON" do
|
245
|
+
json = BW::JSON.generate({foo:42, bar:'BubbleWrap'})
|
246
|
+
puts "\n"
|
247
|
+
[:put, :post, :delete, :patch].each do |method|
|
248
|
+
puts " - #{method}\n"
|
249
|
+
query = BubbleWrap::HTTP::Query.new( 'nil' , method, { payload: json } )
|
250
|
+
set_payload = NSString.alloc.initWithData(query.request.HTTPBody, encoding:NSUTF8StringEncoding)
|
251
|
+
set_payload.should.equal json
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
241
255
|
end
|
242
256
|
|
243
257
|
it "should set default timeout to 30s or the one from hash" do
|
@@ -287,7 +301,7 @@ describe "HTTP" do
|
|
287
301
|
|
288
302
|
it "should turn on the network indicator" do
|
289
303
|
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should.equal true
|
290
|
-
end
|
304
|
+
end
|
291
305
|
|
292
306
|
end
|
293
307
|
|
@@ -310,7 +324,7 @@ describe "HTTP" do
|
|
310
324
|
|
311
325
|
it "should patch the NSURLRequest with done_loading and done_loading!" do
|
312
326
|
@query.request.done_loading.should.equal @query.request.instance_variable_get(:@done_loading)
|
313
|
-
|
327
|
+
|
314
328
|
@query.request.instance_variable_set(:@done_loading, false)
|
315
329
|
@query.request.done_loading.should.equal false
|
316
330
|
@query.request.done_loading!
|
@@ -324,18 +338,45 @@ describe "HTTP" do
|
|
324
338
|
|
325
339
|
end
|
326
340
|
|
341
|
+
describe "create POST request" do
|
342
|
+
|
343
|
+
before do
|
344
|
+
@url_string = 'http://initiated-request.dev/post'
|
345
|
+
@headers = { fake: 'headers' }
|
346
|
+
@payload = { key:'abc1234' }
|
347
|
+
@post_query = BubbleWrap::HTTP::Query.new(@url_string, :post, {headers: @headers, payload: @payload})
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should automatically provide Content-Type if a payload is provided" do
|
351
|
+
@post_query.request.allHTTPHeaderFields.should.include?('Content-Type')
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should not add Content-Type if you provide one yourself" do
|
355
|
+
# also ensures check is case insenstive
|
356
|
+
@headers = { fake: 'headers', 'CONTENT-TYPE' => 'x-banana' }
|
357
|
+
@post_query = BubbleWrap::HTTP::Query.new(@url_string, :post, {headers: @headers, payload: @payload})
|
358
|
+
@post_query.request.allHTTPHeaderFields['CONTENT-TYPE'].should.equal @headers['CONTENT-TYPE']
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should not add additional headers if no payload is given" do
|
362
|
+
@post_query = BubbleWrap::HTTP::Query.new(@url_string, :post, {headers: @headers})
|
363
|
+
@post_query.request.allHTTPHeaderFields.should.equal @headers
|
364
|
+
end
|
365
|
+
|
366
|
+
end
|
367
|
+
|
327
368
|
describe "Generating GET params" do
|
328
369
|
|
329
370
|
it "should create params with nested hashes with prefix[key]=value" do
|
330
371
|
expected_params = [
|
331
|
-
'user[name]=marin',
|
332
|
-
'user[surname]=usalj',
|
372
|
+
'user[name]=marin',
|
373
|
+
'user[surname]=usalj',
|
333
374
|
'twitter=@mneorr',
|
334
375
|
'website=mneorr.com',
|
335
376
|
'values[]=apple',
|
336
377
|
'values[]=orange',
|
337
378
|
'values[]=peach',
|
338
|
-
"credentials[username]=mneorr",
|
379
|
+
"credentials[username]=mneorr",
|
339
380
|
"credentials[password]=123456xx!@crazy"
|
340
381
|
]
|
341
382
|
@query.send(:generate_get_params, @payload).should.equal expected_params
|
@@ -378,7 +419,7 @@ describe "HTTP" do
|
|
378
419
|
|
379
420
|
@query.connection(nil, didReceiveData:data)
|
380
421
|
query_received_data.length.should.equal 48
|
381
|
-
end
|
422
|
+
end
|
382
423
|
|
383
424
|
end
|
384
425
|
|
@@ -392,7 +433,7 @@ describe "HTTP" do
|
|
392
433
|
it "should turn off network indicator" do
|
393
434
|
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == true
|
394
435
|
@query.connection(nil, didFailWithError:@fake_error)
|
395
|
-
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
|
436
|
+
UIApplication.sharedApplication.isNetworkActivityIndicatorVisible.should == false
|
396
437
|
end
|
397
438
|
|
398
439
|
it "should set request_done to true" do
|
@@ -544,7 +585,7 @@ describe "HTTP" do
|
|
544
585
|
end
|
545
586
|
|
546
587
|
class BubbleWrap::HTTP::Query
|
547
|
-
def create_connection(request, delegate); FakeURLConnection.new(request, delegate); end
|
588
|
+
def create_connection(request, delegate); FakeURLConnection.new(request, delegate); end
|
548
589
|
end
|
549
590
|
|
550
591
|
class FakeURLConnection < NSURLConnection
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bubble-wrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-07-
|
14
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bacon
|
18
|
-
requirement: &
|
18
|
+
requirement: &70352193392320 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '0'
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70352193392320
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mocha-on-bacon
|
29
|
-
requirement: &
|
29
|
+
requirement: &70352193391900 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70352193391900
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rake
|
40
|
-
requirement: &
|
40
|
+
requirement: &70352193391480 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70352193391480
|
49
49
|
description: RubyMotion wrappers and helpers (Ruby for iOS) - Making Cocoa APIs more
|
50
50
|
Ruby like, one API at a time. Fork away and send your pull request.
|
51
51
|
email:
|
@@ -219,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
219
219
|
version: '0'
|
220
220
|
segments:
|
221
221
|
- 0
|
222
|
-
hash: -
|
222
|
+
hash: -1922890315766679291
|
223
223
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
224
|
none: false
|
225
225
|
requirements:
|
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
228
|
version: '0'
|
229
229
|
segments:
|
230
230
|
- 0
|
231
|
-
hash: -
|
231
|
+
hash: -1922890315766679291
|
232
232
|
requirements: []
|
233
233
|
rubyforge_project:
|
234
234
|
rubygems_version: 1.8.16
|