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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5b4f9ef92b9859bec0fff18766087660f650fe1
4
- data.tar.gz: 365c6e38731eae50c87eb11f7d225daa364e29de
3
+ metadata.gz: 158cb8dee1f383a0ab067cfdf45c5a829b9dbf6a
4
+ data.tar.gz: 14ac8a0b08632bc316542b33207c403a6bc6ea89
5
5
  SHA512:
6
- metadata.gz: fc1e6f8e169f2bf93da9e32019a525ac8374bda740266a482d95164456315a4495160ca5715761a0d978ea2f1ab5577b93a7f3ce7037c1c9442540afab59299d
7
- data.tar.gz: f06860e9f4bf4789bfd7865c61e2977239f73d9a69f1cd7f2933381f0a8d9ce80c36957ddcb7e8d40ac335dd3438d18a50dc60a28e6d3604f3c28461eaaea69e
6
+ metadata.gz: 1b8c836667ccd5eae36974b6baa51cebc6e2b492bf026d097cc588828a63e56375abec5ffed8c5f65cba622ec1e25883090cd91a421aa2ccb9d04021ed53c697
7
+ data.tar.gz: 5a4c3abd0ba46c9c8c877751dfae0aed1f2e021b6b5cbca22e0b35bc248274a56b0f8635eed23b870a28f8eb32127d2cd56376969afc23820d7933ef2608c741
@@ -1,5 +1,4 @@
1
1
  require 'resource_kit/version'
2
- require 'faraday'
3
2
 
4
3
  module ResourceKit
5
4
  ALLOWED_VERBS = [:get, :post, :put, :delete, :head, :patch, :options]
@@ -10,8 +10,9 @@ module ResourceKit
10
10
  end
11
11
 
12
12
  def resolve(values = {})
13
- uri = Addressable::URI.new
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(path) do |np, (key, value)|
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
- params = query_param_keys.each_with_object({}) do |key, query_values|
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
 
@@ -1,3 +1,3 @@
1
1
  module ResourceKit
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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(:options) { { path: '/users' } }
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(:options) { super().merge(path: '/users/:id') }
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(:options) { super().merge(path: '/users', query_param_keys: [:per_page, :page]) }
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
@@ -1,6 +1,7 @@
1
1
  require 'resource_kit'
2
2
  require 'resource_kit/testing'
3
3
  require 'pry'
4
+ require 'faraday'
4
5
 
5
6
  RSpec.configure do |config|
6
7
  config.order = :random
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.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: 2014-10-01 00:00:00.000000000 Z
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