springboard-retail 4.2.1 → 4.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -3
- data/lib/springboard/client.rb +3 -4
- data/lib/springboard/client/resource.rb +13 -3
- data/lib/springboard/client/uri.rb +45 -32
- data/spec/springboard/client/resource_spec.rb +44 -33
- data/spec/springboard/client/response_spec.rb +1 -1
- data/spec/springboard/client/uri_spec.rb +63 -15
- data/spec/springboard/client_spec.rb +21 -1
- data/springboard-retail.gemspec +1 -2
- data/vendor/cache/hashie-3.6.0.gem +0 -0
- metadata +3 -17
- data/vendor/cache/hashie-3.5.7.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd35455f3b848e238263429302242ec4897b99f9190841b9cc03cd78e7fe70c9
|
4
|
+
data.tar.gz: 1f768fc9359ac7ec8daff47888b647eedb7b84f9f91cf2a1b8fa24b474afe266
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e1ea9566b62cd2cfc1676ef8ddb2aa9627cecb56b0d4a8d47ce8536586ff824d81bd44cc06bad91f91239ae84be33c4915abff21ae08bf759da4c9c4e7793bf
|
7
|
+
data.tar.gz: 7ad3f24caf64aa63b0608f63bd047c3472abbb6e81c51388de342089953cfedc3c1d441a10e714b3c482254c0146d2123eeca78e7b7cec2b35d5e17be6719b3d
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
springboard-retail (4.
|
5
|
-
addressable (~> 2.2.8)
|
4
|
+
springboard-retail (4.3.0)
|
6
5
|
hashie
|
7
6
|
json (>= 1.7.4)
|
8
7
|
patron (= 0.4.18)
|
@@ -24,7 +23,7 @@ GEM
|
|
24
23
|
safe_yaml (~> 1.0.0)
|
25
24
|
diff-lcs (1.2.5)
|
26
25
|
docile (1.1.5)
|
27
|
-
hashie (3.
|
26
|
+
hashie (3.6.0)
|
28
27
|
json (2.1.0)
|
29
28
|
method_source (0.8.2)
|
30
29
|
mime-types (2.4.3)
|
data/lib/springboard/client.rb
CHANGED
@@ -30,7 +30,7 @@ module Springboard
|
|
30
30
|
DEFAULT_CONNECT_TIMEOUT = 10
|
31
31
|
|
32
32
|
##
|
33
|
-
# @return [
|
33
|
+
# @return [URI] The client's base URI
|
34
34
|
attr_reader :base_uri
|
35
35
|
|
36
36
|
##
|
@@ -80,7 +80,7 @@ module Springboard
|
|
80
80
|
unless opts[:username] && opts[:password]
|
81
81
|
raise "Must specify :username and :password"
|
82
82
|
end
|
83
|
-
body = ::
|
83
|
+
body = ::URI.encode_www_form \
|
84
84
|
:auth_key => opts[:username],
|
85
85
|
:password => opts[:password]
|
86
86
|
response = post '/auth/identity/callback', body,
|
@@ -236,8 +236,7 @@ module Springboard
|
|
236
236
|
|
237
237
|
def prepare_uri(uri)
|
238
238
|
uri = URI.parse(uri)
|
239
|
-
uri.
|
240
|
-
uri
|
239
|
+
uri.to_s.gsub(/^#{base_uri.to_s}|^#{base_uri.path}/, '')
|
241
240
|
end
|
242
241
|
|
243
242
|
def new_response(patron_response)
|
@@ -21,7 +21,7 @@ module Springboard
|
|
21
21
|
#
|
22
22
|
# @return [Addressable::URI]
|
23
23
|
attr_reader :uri
|
24
|
-
|
24
|
+
|
25
25
|
##
|
26
26
|
# The underlying Springboard Client.
|
27
27
|
#
|
@@ -31,9 +31,9 @@ module Springboard
|
|
31
31
|
##
|
32
32
|
# @param [Springboard::Client] client
|
33
33
|
# @param [Addressable::URI, #to_s] uri
|
34
|
-
def initialize(client,
|
34
|
+
def initialize(client, uri_or_path)
|
35
35
|
@client = client
|
36
|
-
@uri =
|
36
|
+
@uri = normalize_uri(uri_or_path)
|
37
37
|
end
|
38
38
|
|
39
39
|
##
|
@@ -195,6 +195,16 @@ module Springboard
|
|
195
195
|
|
196
196
|
private
|
197
197
|
|
198
|
+
##
|
199
|
+
# Normalizes the URI or path given to a URI
|
200
|
+
def normalize_uri(uri_or_path)
|
201
|
+
uri = URI.parse(uri_or_path)
|
202
|
+
return uri if uri.to_s.start_with?(client.base_uri.to_s)
|
203
|
+
path = uri_or_path.to_s.start_with?('/') ? uri_or_path : "/#{uri_or_path}"
|
204
|
+
path.to_s.gsub!(/^#{client.base_uri.to_s}|^#{client.base_uri.path}/, '')
|
205
|
+
URI.parse("#{client.base_uri}#{path}")
|
206
|
+
end
|
207
|
+
|
198
208
|
##
|
199
209
|
# Calls a client method, passing the URI as the first argument.
|
200
210
|
def call_client(method, *args, &block)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'uri'
|
2
2
|
|
3
3
|
module Springboard
|
4
4
|
class Client
|
5
5
|
##
|
6
|
-
# A wrapper around
|
6
|
+
# A wrapper around URI
|
7
7
|
class URI
|
8
8
|
##
|
9
9
|
# Returns a URI object based on the parsed string.
|
@@ -11,15 +11,7 @@ module Springboard
|
|
11
11
|
# @return [URI]
|
12
12
|
def self.parse(value)
|
13
13
|
return value.dup if value.is_a?(self)
|
14
|
-
new(::
|
15
|
-
end
|
16
|
-
|
17
|
-
##
|
18
|
-
# Joins several URIs together.
|
19
|
-
#
|
20
|
-
# @return [URI]
|
21
|
-
def self.join(*args)
|
22
|
-
new(::Addressable::URI.join(*args))
|
14
|
+
new(::URI.parse(value.to_s))
|
23
15
|
end
|
24
16
|
|
25
17
|
##
|
@@ -46,59 +38,80 @@ module Springboard
|
|
46
38
|
def subpath(subpath)
|
47
39
|
uri = dup
|
48
40
|
uri.path = "#{path}/" unless path.end_with?('/')
|
49
|
-
uri.
|
41
|
+
uri.path = uri.path + ::URI.encode(subpath.to_s.gsub(/^\//, ''))
|
42
|
+
uri
|
50
43
|
end
|
51
44
|
|
52
45
|
##
|
53
46
|
# Merges the given hash of query string parameters and values with the URI's
|
54
47
|
# existing query string parameters (if any).
|
55
48
|
def merge_query_values!(values)
|
56
|
-
|
49
|
+
old_query_values = self.query_values || {}
|
50
|
+
self.query_values = old_query_values.merge(normalize_query_hash(values))
|
57
51
|
end
|
58
52
|
|
53
|
+
##
|
54
|
+
# Checks if supplied URI matches current URI
|
55
|
+
#
|
56
|
+
# @return [boolean]
|
59
57
|
def ==(other_uri)
|
60
58
|
return false unless other_uri.is_a?(self.class)
|
61
59
|
uri == other_uri.__send__(:uri)
|
62
60
|
end
|
63
61
|
|
62
|
+
##
|
63
|
+
# Overwrites the query using the supplied query values
|
64
|
+
def query_values=(values)
|
65
|
+
self.query = ::URI.encode_www_form(normalize_query_hash(values).sort)
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Returns a hash of query string parameters and values
|
70
|
+
#
|
71
|
+
# @return [hash]
|
72
|
+
def query_values
|
73
|
+
return nil if query.nil?
|
74
|
+
::URI.decode_www_form(query).each_with_object({}) do |(k, v), hash|
|
75
|
+
if k.end_with?('[]')
|
76
|
+
k.gsub!(/\[\]$/, '')
|
77
|
+
hash[k] = Array(hash[k]) + [v]
|
78
|
+
else
|
79
|
+
hash[k] = v
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
64
84
|
private
|
65
85
|
|
66
86
|
attr_reader :uri
|
67
87
|
|
68
|
-
def springboard_query_values=(values)
|
69
|
-
retval = self.query_values = normalize_query_hash(values)
|
70
|
-
# Hack to strip digits from Addressable::URI's subscript notation
|
71
|
-
self.query = self.query.gsub(/\[\d+\]=/, '[]=')
|
72
|
-
retval
|
73
|
-
end
|
74
|
-
|
75
88
|
def self.delegate_and_wrap(*methods)
|
76
89
|
methods.each do |method|
|
77
90
|
define_method(method) do |*args, &block|
|
78
|
-
|
79
|
-
if result.is_a?(Addressable::URI)
|
80
|
-
self.class.new(result)
|
81
|
-
else
|
82
|
-
result
|
83
|
-
end
|
91
|
+
@uri.__send__(method, *args, &block)
|
84
92
|
end
|
85
93
|
end
|
86
94
|
end
|
87
95
|
|
88
96
|
delegate_and_wrap(
|
89
|
-
:
|
90
|
-
:query_values, :query_values=, :query, :query=
|
97
|
+
:path, :path=, :to_s, :query, :query=
|
91
98
|
)
|
92
99
|
|
93
100
|
def normalize_query_hash(hash)
|
94
101
|
hash.inject({}) do |copy, (k, v)|
|
95
|
-
|
96
|
-
|
97
|
-
when true, false then v.to_s
|
98
|
-
else v end
|
102
|
+
k = "#{k}[]" if v.is_a?(Array) && !k.to_s.end_with?('[]')
|
103
|
+
copy[k.to_s] = normalize_query_value(v)
|
99
104
|
copy
|
100
105
|
end
|
101
106
|
end
|
107
|
+
|
108
|
+
def normalize_query_value(value)
|
109
|
+
case value
|
110
|
+
when Hash then normalize_query_hash(value)
|
111
|
+
when true, false then value.to_s
|
112
|
+
when Array then value.uniq
|
113
|
+
else value end
|
114
|
+
end
|
102
115
|
end
|
103
116
|
end
|
104
117
|
end
|
@@ -13,7 +13,7 @@ describe Springboard::Client::Resource do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should return a resource with the given subpath appended to its URI" do
|
16
|
-
expect(resource["subpath"].uri.to_s).to eq("/some/path/subpath")
|
16
|
+
expect(resource["subpath"].uri.to_s).to eq("#{base_url}/some/path/subpath")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should return a resource with the same client instance" do
|
@@ -21,15 +21,13 @@ describe Springboard::Client::Resource do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should accept a symbol as a path" do
|
24
|
-
expect(resource[:subpath].uri.to_s).to eq("/some/path/subpath")
|
24
|
+
expect(resource[:subpath].uri.to_s).to eq("#{base_url}/some/path/subpath")
|
25
25
|
end
|
26
26
|
|
27
|
-
it "should
|
28
|
-
expect(resource[
|
29
|
-
|
30
|
-
|
31
|
-
it "should not URI encode the given subpath" do
|
32
|
-
expect(resource["subpath with spaces"].uri.to_s).to eq("/some/path/subpath with spaces")
|
27
|
+
it "should URI encode the given subpath" do
|
28
|
+
expect(resource["subpath with spaces"].uri.to_s).to eq(
|
29
|
+
"#{base_url}/some/path/subpath%20with%20spaces"
|
30
|
+
)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
@@ -37,22 +35,25 @@ describe Springboard::Client::Resource do
|
|
37
35
|
describe method do
|
38
36
|
describe "when called with a hash" do
|
39
37
|
it "should set the query string parameters" do
|
40
|
-
expect(resource.__send__(method, :a => 1, :b => 2).uri.to_s).to eq("/some/path?a=1&b=2")
|
38
|
+
expect(resource.__send__(method, :a => 1, :b => 2).uri.to_s).to eq("#{base_url}/some/path?a=1&b=2")
|
41
39
|
end
|
42
40
|
|
43
41
|
it "should URL encode the given keys and values" do
|
44
|
-
expect(resource.__send__(method, "i have spaces" => "so do i: duh").uri.to_s).
|
45
|
-
|
42
|
+
expect(resource.__send__(method, "i have spaces" => "so do i: duh").uri.to_s).to eq(
|
43
|
+
"#{base_url}/some/path?i+have+spaces=so+do+i%3A+duh"
|
44
|
+
)
|
46
45
|
end
|
47
46
|
|
48
47
|
it "should add bracket notation for array parameters" do
|
49
|
-
expect(resource.__send__(method, :somearray => [1, 2, 3]).uri.to_s).to eq(
|
48
|
+
expect(resource.__send__(method, :somearray => [1, 2, 3]).uri.to_s).to eq(
|
49
|
+
"#{base_url}/some/path?somearray%5B%5D=1&somearray%5B%5D=2&somearray%5B%5D=3"
|
50
|
+
)
|
50
51
|
end
|
51
52
|
|
52
53
|
it "should return a new resource without modifying the existing URI" do
|
53
54
|
new_resource = resource.query(per_page: 1)
|
54
|
-
expect(new_resource.uri.to_s).to eq("/some/path?per_page=1")
|
55
|
-
expect(resource.uri.to_s).to eq("/some/path")
|
55
|
+
expect(new_resource.uri.to_s).to eq("#{base_url}/some/path?per_page=1")
|
56
|
+
expect(resource.uri.to_s).to eq("#{base_url}/some/path")
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -70,7 +71,7 @@ describe Springboard::Client::Resource do
|
|
70
71
|
describe "when given a hash" do
|
71
72
|
it "should add a _filter query string param" do
|
72
73
|
expect(resource.filter(:a => 1, :b => 2).uri).to eq(
|
73
|
-
|
74
|
+
"#{base_url}/some/path?_filter=%7B%22a%22%3A1%2C%22b%22%3A2%7D".to_uri
|
74
75
|
)
|
75
76
|
end
|
76
77
|
end
|
@@ -78,7 +79,7 @@ describe Springboard::Client::Resource do
|
|
78
79
|
describe "when called multiple times" do
|
79
80
|
it "should append args to _filter param as JSON array" do
|
80
81
|
expect(resource.filter(:a => 1).filter(:b => 2).filter(:c => 3).uri).to eq(
|
81
|
-
|
82
|
+
"#{base_url}/some/path?_filter=%5B%7B%22a%22%3A1%7D%2C%7B%22b%22%3A2%7D%2C%7B%22c%22%3A3%7D%5D".to_uri
|
82
83
|
)
|
83
84
|
end
|
84
85
|
end
|
@@ -86,7 +87,15 @@ describe Springboard::Client::Resource do
|
|
86
87
|
describe "when given a string" do
|
87
88
|
it "should add a _filter query string param" do
|
88
89
|
expect(resource.filter('{"a":1,"b":2}').uri).to eq(
|
89
|
-
|
90
|
+
"#{base_url}/some/path?_filter=%7B%22a%22%3A1%2C%22b%22%3A2%7D".to_uri
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "when called multiple times with other methods" do
|
96
|
+
it "should append args to _filter param as JSON array" do
|
97
|
+
expect(resource.filter(:a => 1).embed(:other).only(:field).filter(:b => 2).uri).to eq(
|
98
|
+
"#{base_url}/some/path?_filter=%5B%7B%22a%22%3A1%7D%2C%7B%22b%22%3A2%7D%5D&_include%5B%5D=other&_only%5B%5D=field".to_uri
|
90
99
|
)
|
91
100
|
end
|
92
101
|
end
|
@@ -94,22 +103,30 @@ describe Springboard::Client::Resource do
|
|
94
103
|
|
95
104
|
describe "sort" do
|
96
105
|
it "should set the sort parameter based on the given values" do
|
97
|
-
expect(resource.sort('f1', 'f2,desc').uri.
|
106
|
+
expect(resource.sort('f1', 'f2,desc').uri.to_s).to eq(
|
107
|
+
"#{base_url}/some/path?sort%5B%5D=f1&sort%5B%5D=f2%2Cdesc"
|
108
|
+
)
|
98
109
|
end
|
99
110
|
|
100
111
|
it "should replace any existing sort parameter" do
|
101
112
|
resource.sort('f1', 'f2,desc')
|
102
|
-
expect(resource.sort('f3,asc', 'f4').uri.
|
113
|
+
expect(resource.sort('f3,asc', 'f4').uri.to_s).to eq(
|
114
|
+
"#{base_url}/some/path?sort%5B%5D=f3%2Casc&sort%5B%5D=f4"
|
115
|
+
)
|
103
116
|
end
|
104
117
|
end
|
105
118
|
|
106
119
|
describe "only" do
|
107
120
|
it "should set the _only parameter based on the given values" do
|
108
|
-
expect(resource.only('f1', 'f2').uri.
|
121
|
+
expect(resource.only('f1', 'f2').uri.to_s).to eq(
|
122
|
+
"#{base_url}/some/path?_only%5B%5D=f1&_only%5B%5D=f2"
|
123
|
+
)
|
109
124
|
end
|
110
125
|
|
111
126
|
it "should replace the existing _only parameters" do
|
112
|
-
expect(resource.only('f1').only('f2', 'f3').uri.
|
127
|
+
expect(resource.only('f1').only('f2', 'f3').uri.to_s).to eq(
|
128
|
+
"#{base_url}/some/path?_only%5B%5D=f2&_only%5B%5D=f3"
|
129
|
+
)
|
113
130
|
end
|
114
131
|
end
|
115
132
|
|
@@ -167,7 +184,7 @@ describe Springboard::Client::Resource do
|
|
167
184
|
it "should not modify the original resource URI" do
|
168
185
|
request_stub = stub_request(:get, "#{base_url}/some/path?page=1&per_page=1").to_return(response_data)
|
169
186
|
resource.count
|
170
|
-
expect(resource.uri.to_s).to eq("/some/path")
|
187
|
+
expect(resource.uri.to_s).to eq("#{base_url}/some/path")
|
171
188
|
end
|
172
189
|
end
|
173
190
|
|
@@ -193,38 +210,32 @@ describe Springboard::Client::Resource do
|
|
193
210
|
it "should not modify the original resource URI" do
|
194
211
|
request_stub = stub_request(:get, "#{base_url}/some/path?page=1&per_page=1").to_return(response_data)
|
195
212
|
resource.first
|
196
|
-
expect(resource.uri.to_s).to eq("/some/path")
|
213
|
+
expect(resource.uri.to_s).to eq("#{base_url}/some/path")
|
197
214
|
end
|
198
215
|
end
|
199
216
|
|
200
217
|
describe "embed" do
|
201
218
|
it "should support a single embed" do
|
202
219
|
expect(resource.embed(:thing1).uri.to_s).to eq(
|
203
|
-
|
220
|
+
"#{base_url}/some/path?_include%5B%5D=thing1"
|
204
221
|
)
|
205
222
|
end
|
206
223
|
|
207
224
|
it "should support multiple embeds" do
|
208
225
|
expect(resource.embed(:thing1, :thing2, :thing3).uri.to_s).to eq(
|
209
|
-
|
210
|
-
)
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should merge multiple embed calls" do
|
214
|
-
expect(resource.embed(:thing1, :thing2).embed(:thing3, :thing4).uri.to_s).to eq(
|
215
|
-
'/some/path?_include[]=thing1&_include[]=thing2&_include[]=thing3&_include[]=thing4'
|
226
|
+
"#{base_url}/some/path?_include%5B%5D=thing1&_include%5B%5D=thing2&_include%5B%5D=thing3"
|
216
227
|
)
|
217
228
|
end
|
218
229
|
|
219
230
|
it "should merge multiple embed calls" do
|
220
231
|
expect(resource.embed(:thing1, :thing2).embed(:thing3, :thing4).uri.to_s).to eq(
|
221
|
-
|
232
|
+
"#{base_url}/some/path?_include%5B%5D=thing1&_include%5B%5D=thing2&_include%5B%5D=thing3&_include%5B%5D=thing4"
|
222
233
|
)
|
223
234
|
end
|
224
235
|
|
225
236
|
it "should merge a call to embed with a manually added _include query param" do
|
226
237
|
expect(resource.query('_include[]' => :thing1).embed(:thing2, :thing3).uri.to_s).to eq(
|
227
|
-
|
238
|
+
"#{base_url}/some/path?_include%5B%5D=thing1&_include%5B%5D=thing2&_include%5B%5D=thing3"
|
228
239
|
)
|
229
240
|
end
|
230
241
|
end
|
@@ -70,40 +70,88 @@ describe Springboard::Client::URI do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe "merge_query_values!" do
|
73
|
-
it "should
|
74
|
-
uri.query_values = {'a' => '1'}
|
75
|
-
|
76
|
-
uri.
|
73
|
+
it "should merge the given values with the existing query_values" do
|
74
|
+
uri.query_values = {'a' => '1', 'b' => '2'}
|
75
|
+
uri.merge_query_values! 'c' => '3'
|
76
|
+
expect(uri.query_values).to eq(
|
77
|
+
{'a' => '1', 'b' => '2', 'c' => '3'}
|
78
|
+
)
|
77
79
|
end
|
78
80
|
|
79
|
-
it "should
|
81
|
+
it "should overwrite the previous values when a new value is given" do
|
80
82
|
uri.query_values = {'a' => '1', 'b' => '2'}
|
81
|
-
uri.merge_query_values! '
|
82
|
-
expect(uri.query_values).to eq(
|
83
|
+
uri.merge_query_values! 'a' => '3', 'b' => '4'
|
84
|
+
expect(uri.query_values).to eq(
|
85
|
+
{'a' => '3', 'b' => '4'}
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should overwrite the previous values if a new array is given" do
|
90
|
+
uri.query_values = {'a' => '1', 'b' => ['2', '3']}
|
91
|
+
uri.merge_query_values! 'b' => ['4', '5']
|
92
|
+
expect(uri.query_values).to eq(
|
93
|
+
{'a' => '1', 'b' => ['4', '5']}
|
94
|
+
)
|
83
95
|
end
|
84
96
|
|
85
97
|
it "should set the given values if there are no existing query_values" do
|
86
98
|
expect(uri.query_values).to be_nil
|
87
|
-
uri.merge_query_values! 'b' => '20', 'c' => '30'
|
88
|
-
expect(uri.query_values).to eq({'b' => '20', 'c' => '30'})
|
99
|
+
uri.merge_query_values! 'a' => ['10'], 'b' => '20', 'c' => '30'
|
100
|
+
expect(uri.query_values).to eq({'a' => ['10'], 'b' => '20', 'c' => '30'})
|
89
101
|
end
|
90
102
|
end
|
91
103
|
|
92
|
-
describe "
|
104
|
+
describe "query_values=" do
|
105
|
+
it "should set the string value for the specified key" do
|
106
|
+
uri.query_values = {'p1' => '1'}
|
107
|
+
expect(uri.query_values).to eq({'p1' => '1'})
|
108
|
+
end
|
109
|
+
|
93
110
|
it "should preserve empty bracket notation for array params" do
|
94
111
|
uri.query = 'sort[]=f1&sort[]=f2'
|
95
|
-
uri.
|
96
|
-
expect(uri.to_s).to eq('/relative/path?sort
|
112
|
+
uri.query_values = uri.query_values
|
113
|
+
expect(uri.to_s).to eq('/relative/path?sort%5B%5D=f1&sort%5B%5D=f2')
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should stringify symbol keys" do
|
117
|
+
uri.query_values = {:a => '1'}
|
118
|
+
expect(uri.query_values).to eq({'a' => '1'})
|
97
119
|
end
|
98
120
|
|
99
121
|
it "should stringify boolean param values" do
|
100
|
-
uri.
|
122
|
+
uri.query_values = {:p1 => true, :p2 => false}
|
101
123
|
expect(uri.to_s).to eq('/relative/path?p1=true&p2=false')
|
102
124
|
end
|
103
125
|
|
104
126
|
it "should support hash param values" do
|
105
|
-
uri.
|
106
|
-
expect(uri.to_s).to eq(
|
127
|
+
uri.query_values = {:a => {:b => {:c => 123}}}
|
128
|
+
expect(uri.to_s).to eq(
|
129
|
+
'/relative/path?a=%7B%22b%22%3D%3E%7B%22c%22%3D%3E123%7D%7D'
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should add [] to the key for array values" do
|
134
|
+
uri.query_values = {:a => ['1', '2', '3']}
|
135
|
+
expect(uri.query).to eq('a%5B%5D=1&a%5B%5D=2&a%5B%5D=3')
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should remove duplicate values for the same key" do
|
139
|
+
uri.query_values = {:a => ['1', '1', '2']}
|
140
|
+
expect(uri.query_values).to eq({'a' => ['1', '2']})
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "query_values" do
|
145
|
+
it "should return the current query values" do
|
146
|
+
uri.query = 'sort[]=f1&sort[]=f2&per_page=all'
|
147
|
+
uri.query_values = uri.query_values
|
148
|
+
expect(uri.query_values).to eq({'sort' => ['f1', 'f2'], 'per_page' => 'all'})
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should remove [] from array keys" do
|
152
|
+
uri.query = 'sort[]=f1&sort[]=f2'
|
153
|
+
uri.query_values = uri.query_values
|
154
|
+
expect(uri.query_values).to eq({'sort' => ['f1', 'f2']})
|
107
155
|
end
|
108
156
|
end
|
109
157
|
end
|
@@ -84,8 +84,28 @@ describe Springboard::Client do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
describe "[]" do
|
87
|
-
it "should return a resource object with the given path and client" do
|
87
|
+
it "should return a resource object with the given path string and client" do
|
88
88
|
expect(client["path"]).to be_a Springboard::Client::Resource
|
89
|
+
expect(client[:path].uri.to_s).to eq("#{base_url}/path")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return a resource object when given a path as a symbol" do
|
93
|
+
expect(client[:path]).to be_a Springboard::Client::Resource
|
94
|
+
expect(client[:path].uri.to_s).to eq("#{base_url}/path")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return a resource object when given a path as a URI" do
|
98
|
+
uri = 'path'.to_uri
|
99
|
+
expect(client[uri]).to be_a Springboard::Client::Resource
|
100
|
+
expect(client[uri].uri.to_s).to eq("#{base_url}/path")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should not duplicate the base URI path" do
|
104
|
+
expect(client['api/subpath'].uri.to_s).to eq("#{base_url}/subpath")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not duplicate the base URI" do
|
108
|
+
expect(client["#{base_url}/subpath"].uri.to_s).to eq("#{base_url}/subpath")
|
89
109
|
end
|
90
110
|
end
|
91
111
|
|
data/springboard-retail.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'springboard-retail'
|
3
|
-
s.version = '4.
|
3
|
+
s.version = '4.3.0'
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ['Jay Stotz']
|
6
6
|
s.summary = 'Springboard Retail API client library'
|
@@ -8,7 +8,6 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.required_rubygems_version = '>= 1.3.6'
|
9
9
|
|
10
10
|
s.add_runtime_dependency 'patron', '0.4.18'
|
11
|
-
s.add_runtime_dependency 'addressable', '~> 2.2.8'
|
12
11
|
s.add_runtime_dependency 'json', '>= 1.7.4'
|
13
12
|
s.add_runtime_dependency 'hashie'
|
14
13
|
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: springboard-retail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Stotz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: patron
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.4.18
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: addressable
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 2.2.8
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 2.2.8
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: json
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,7 +90,7 @@ files:
|
|
104
90
|
- vendor/cache/crack-0.4.2.gem
|
105
91
|
- vendor/cache/diff-lcs-1.2.5.gem
|
106
92
|
- vendor/cache/docile-1.1.5.gem
|
107
|
-
- vendor/cache/hashie-3.
|
93
|
+
- vendor/cache/hashie-3.6.0.gem
|
108
94
|
- vendor/cache/json-2.1.0.gem
|
109
95
|
- vendor/cache/method_source-0.8.2.gem
|
110
96
|
- vendor/cache/mime-types-2.4.3.gem
|
Binary file
|