mudbug 0.7.3.1 → 0.8.0.1
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 +8 -8
- data/VERSION +1 -1
- data/lib/mudbug.rb +24 -8
- data/test/mudbug.rb +30 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWQ5MTgyMDc4ODAxMzZlNGNjODA3Mzk4NmFjYmJmMzU5YWQ3MzY5ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzM5M2RlZTk4OGRhZGJmZTQwOGQ3Njc0MWVjMTAxZDJkNTQ2YTc2MA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjRkYmM5NWExY2IwZjA1YzJiN2Y3ZjFlZTFiOTU2NTY5YzE5ZGU0Y2Q3ODI4
|
10
|
+
YzQ0MDExNjZlODExMTAwM2FjOWQyOWU5NDg1YjA0MmYzYTkzYmUxOTQ4MTUw
|
11
|
+
NTVlNjhiOWRmZTliYmEwZjk5OTQzYTBiODc0YTk0YzVlMTAxNDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmQ0MTVjMTBmMjE0NmMwMjY4OTE2M2MyNzYzZGQ5MzVlZWQ4YWMwOTUwYjY1
|
14
|
+
NzNhMTBmY2ZjMTEwOTljNTBiYThkNGU0MTU4MTUxNjBiNjZiZWJjNjgwNjdj
|
15
|
+
YmRlYmU1N2Q0NjZlMGMwZmU5YTk4MTBiZDgxYzVmZWYyN2Q1MTc=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0.1
|
data/lib/mudbug.rb
CHANGED
@@ -116,15 +116,16 @@ class Mudbug
|
|
116
116
|
path = "/#{path}" unless path[0,1] == '/'
|
117
117
|
url = "http://#{@host}#{path}"
|
118
118
|
end
|
119
|
-
RestClient::Resource.new
|
119
|
+
RestClient::Resource.new(url, merge(options))
|
120
120
|
end
|
121
121
|
|
122
122
|
# no payload
|
123
123
|
#
|
124
124
|
[:get, :delete].each { |meth|
|
125
|
-
define_method(meth) { |path,
|
126
|
-
res = resource(path
|
127
|
-
|
125
|
+
define_method(meth) { |path, params = {}|
|
126
|
+
res = resource(path)
|
127
|
+
resp = res.send(meth, params: params)
|
128
|
+
self.class.process(resp, res.headers[:accept])
|
128
129
|
}
|
129
130
|
}
|
130
131
|
|
@@ -133,11 +134,26 @@ class Mudbug
|
|
133
134
|
# otherwise apply #to_json to payload automatically. Quack.
|
134
135
|
#
|
135
136
|
[:post, :put].each { |meth|
|
136
|
-
define_method(meth) { |path, payload,
|
137
|
-
options[:content_type] ||= CONTENT[:json][:type]
|
137
|
+
define_method(meth) { |path, payload, params = {}|
|
138
138
|
payload = payload.to_json unless payload.is_a?(String)
|
139
|
-
res = resource(path,
|
140
|
-
|
139
|
+
res = resource(path, content_type: CONTENT[:json][:type])
|
140
|
+
resp = res.send(meth, payload, params: params)
|
141
|
+
self.class.process(resp, res.headers[:accept])
|
141
142
|
}
|
142
143
|
}
|
144
|
+
|
145
|
+
# a standard merge would throw away @options[:headers][:accept], if
|
146
|
+
# options[:headers] is provided. Handle nested hashes while still allowing
|
147
|
+
# @options to be overridden
|
148
|
+
#
|
149
|
+
def merge(options)
|
150
|
+
# gah, let's go ahead and do this for all nested hashes we maintain
|
151
|
+
result = options.merge({}) # work on a copy, TODO: better way (not dup)
|
152
|
+
@options.each { |key, hsh|
|
153
|
+
if result[key] and result[key].is_a?(Hash) and hsh.is_a?(Hash)
|
154
|
+
result[key] = hsh.merge(result[key])
|
155
|
+
end
|
156
|
+
}
|
157
|
+
result
|
158
|
+
end
|
143
159
|
end
|
data/test/mudbug.rb
CHANGED
@@ -3,9 +3,35 @@ require 'minitest/autorun'
|
|
3
3
|
|
4
4
|
require_relative '../lib/mudbug'
|
5
5
|
|
6
|
-
describe "
|
7
|
-
it "should
|
8
|
-
|
9
|
-
|
6
|
+
describe "Mudbug#merge" do
|
7
|
+
it "should maintain 2nd-level nested hash keys" do
|
8
|
+
m = Mudbug.new
|
9
|
+
m.options[:headers].must_be_instance_of Hash
|
10
|
+
m.options[:headers][:accept].must_be_instance_of String
|
11
|
+
default_accept = m.options[:headers][:accept]
|
12
|
+
|
13
|
+
options = m.merge(headers: {})
|
14
|
+
options[:headers].must_be_instance_of Hash
|
15
|
+
options[:headers][:accept].must_equal default_accept
|
16
|
+
|
17
|
+
options = m.merge(headers: { accept: '12345' })
|
18
|
+
options[:headers].must_be_instance_of Hash
|
19
|
+
options[:headers][:accept].must_equal '12345'
|
20
|
+
|
21
|
+
distinct = { headers: { xmadeup: '12345' }, max_redirects: 5 }
|
22
|
+
options = m.merge(distinct)
|
23
|
+
options[:headers].must_be_instance_of Hash
|
24
|
+
options[:headers][:accept].must_equal default_accept
|
25
|
+
|
26
|
+
# make sure the outside hash takes precedence
|
27
|
+
distinct.each { |key, val|
|
28
|
+
if val.is_a?(Hash)
|
29
|
+
val.each { |key2, val2|
|
30
|
+
options[key][key2].must_equal val2
|
31
|
+
}
|
32
|
+
else
|
33
|
+
options[key].must_equal val
|
34
|
+
end
|
35
|
+
}
|
10
36
|
end
|
11
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mudbug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Hull
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|