resource_kit 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/resource_kit.rb +0 -1
- data/lib/resource_kit/endpoint_resolver.rb +7 -5
- data/lib/resource_kit/version.rb +1 -1
- data/resource_kit.gemspec +1 -1
- data/spec/lib/resource_kit/endpoint_resolver_spec.rb +18 -3
- data/spec/spec_helper.rb +1 -0
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 158cb8dee1f383a0ab067cfdf45c5a829b9dbf6a
|
4
|
+
data.tar.gz: 14ac8a0b08632bc316542b33207c403a6bc6ea89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b8c836667ccd5eae36974b6baa51cebc6e2b492bf026d097cc588828a63e56375abec5ffed8c5f65cba622ec1e25883090cd91a421aa2ccb9d04021ed53c697
|
7
|
+
data.tar.gz: 5a4c3abd0ba46c9c8c877751dfae0aed1f2e021b6b5cbca22e0b35bc248274a56b0f8635eed23b870a28f8eb32127d2cd56376969afc23820d7933ef2608c741
|
data/lib/resource_kit.rb
CHANGED
@@ -10,8 +10,9 @@ module ResourceKit
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def resolve(values = {})
|
13
|
-
uri = Addressable::URI.
|
14
|
-
new_path = generated_path(values)
|
13
|
+
uri = Addressable::URI.parse(path)
|
14
|
+
new_path = generated_path(uri.path, values)
|
15
|
+
|
15
16
|
uri.path = normalized_path_components(new_path)
|
16
17
|
uri.query = append_query_values(uri, values) unless query_param_keys.empty?
|
17
18
|
|
@@ -20,8 +21,8 @@ module ResourceKit
|
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
|
-
def generated_path(values)
|
24
|
-
values.inject(
|
24
|
+
def generated_path(supplied_path, values)
|
25
|
+
values.inject(supplied_path) do |np, (key, value)|
|
25
26
|
np.gsub(":#{key}", value.to_s)
|
26
27
|
end
|
27
28
|
end
|
@@ -34,7 +35,8 @@ module ResourceKit
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def append_query_values(uri, values)
|
37
|
-
|
38
|
+
pre_vals = uri.query_values || {}
|
39
|
+
params = query_param_keys.each_with_object(pre_vals) do |key, query_values|
|
38
40
|
query_values[key] = values[key] if values.has_key?(key)
|
39
41
|
end
|
40
42
|
|
data/lib/resource_kit/version.rb
CHANGED
data/resource_kit.gemspec
CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency 'faraday'
|
23
22
|
spec.add_dependency 'addressable', '~> 2.3.6'
|
24
23
|
|
25
24
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
25
|
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency 'faraday'
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
28
|
spec.add_development_dependency "webmock", "~> 1.18.0"
|
29
29
|
spec.add_development_dependency "kartograph", "~> 0.0.8"
|
@@ -12,7 +12,10 @@ RSpec.describe ResourceKit::EndpointResolver do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#resolve' do
|
15
|
-
let(:
|
15
|
+
let(:path) { '/users' }
|
16
|
+
let(:query_param_keys) { [] }
|
17
|
+
let(:options) { { path: path, query_param_keys: query_param_keys } }
|
18
|
+
|
16
19
|
subject(:resolver) { ResourceKit::EndpointResolver.new(options) }
|
17
20
|
|
18
21
|
context 'simple resolve' do
|
@@ -23,7 +26,7 @@ RSpec.describe ResourceKit::EndpointResolver do
|
|
23
26
|
end
|
24
27
|
|
25
28
|
context 'substituted paths' do
|
26
|
-
let(:
|
29
|
+
let(:path) { '/users/:id' }
|
27
30
|
|
28
31
|
it 'creates a populated URL from passed values' do
|
29
32
|
endpoint = resolver.resolve(id: 1066)
|
@@ -32,7 +35,7 @@ RSpec.describe ResourceKit::EndpointResolver do
|
|
32
35
|
end
|
33
36
|
|
34
37
|
context 'with query parameters' do
|
35
|
-
let(:
|
38
|
+
let(:query_param_keys) { [:per_page, :page] }
|
36
39
|
|
37
40
|
it 'generates a URL with query parameters set correctly' do
|
38
41
|
endpoint = resolver.resolve(per_page: 2, page: 3)
|
@@ -41,5 +44,17 @@ RSpec.describe ResourceKit::EndpointResolver do
|
|
41
44
|
expect(uri.query_values).to eq("per_page" => '2', "page" => '3')
|
42
45
|
end
|
43
46
|
end
|
47
|
+
|
48
|
+
context 'with query parameters already appended' do
|
49
|
+
let(:path) { '/:something/users?foo=bar' }
|
50
|
+
let(:query_param_keys) { [:per_page, :page] }
|
51
|
+
|
52
|
+
it 'appends the query params to the url that already has some' do
|
53
|
+
endpoint = resolver.resolve(something: 'testing', per_page: 2, page: 3)
|
54
|
+
|
55
|
+
uri = Addressable::URI.parse(endpoint)
|
56
|
+
expect(uri.query_values).to eq("foo" => 'bar', "per_page" => '2', "page" => '3')
|
57
|
+
end
|
58
|
+
end
|
44
59
|
end
|
45
60
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resource_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Ross
|
@@ -9,22 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: faraday
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: addressable
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,6 +53,20 @@ dependencies:
|
|
67
53
|
- - ">="
|
68
54
|
- !ruby/object:Gem::Version
|
69
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: faraday
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|