global_registry 1.1.0 → 1.2.0

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: 64ce57dbf8a816d806e978b1bc5bcd31c84ea387
4
- data.tar.gz: 405831e2b00acd2096977138a5184569877b82d0
3
+ metadata.gz: 0c1da68dc3d18b0e400a36959cc3490b8305854e
4
+ data.tar.gz: 1bcf5038d5945ea5f38ac765e8fd33df78519156
5
5
  SHA512:
6
- metadata.gz: 0d9eb988e414bf32f4e5a2da3f312a66ec0e639d493a625b5f419d7e922d18049125c17079c9d887c42acb2a2932cf279e3340520a328de18cb7de565779d758
7
- data.tar.gz: 6ab0a32677502ddf3a49f03a31b6ddbac9fbe5a8da6b85b61fcd350eebcf6ddf8e7873cbca6b0d1fb951ff98007916d1d48246c0b754b7d1f8b8e2f06999d9c3
6
+ metadata.gz: 6a24e9f1d705dae61f8f0927c2aab03aa27e7c728dc939140693b3e407c014d6cc79709dab665fd8849f0d8ff2bf053e35bf19591022bbe6430a8d3bc7b19159
7
+ data.tar.gz: 3da71e5ad1571c46d787ee3b172c6060eb1a5d87cbe3dfc387eff81898b6028f6cb6c038015c0a5f299de43edb56180674cb5662e1cce668a7ea3a8a3a20392f
@@ -64,25 +64,29 @@ module GlobalRegistry
64
64
  def request(method, params, path = nil, headers = {})
65
65
  raise 'You need to configure GlobalRegistry with your access_token.' unless access_token
66
66
 
67
- path ||= default_path
68
- url = base_url
69
- url += '/' unless url.last == '/'
70
- url += path
67
+ url = if base_url.starts_with? 'http'
68
+ Addressable::URI.parse(base_url)
69
+ else
70
+ Addressable::URI.parse("http://#{base_url}")
71
+ end
72
+ url.path = path || default_path
73
+ url.query_values = headers.delete(:params) if headers[:params]
71
74
 
72
75
  case method
73
76
  when :post
74
77
  post_headers = default_headers.merge(content_type: :json, timeout: -1).merge(headers)
75
- RestClient.post(url, params.to_json, post_headers) { |response, request, result, &block|
78
+ RestClient.post(url.to_s, params.to_json, post_headers) { |response, request, result, &block|
76
79
  handle_response(response, request, result)
77
80
  }
78
81
  when :put
79
82
  put_headers = default_headers.merge(content_type: :json, timeout: -1).merge(headers)
80
- RestClient.put(url, params.to_json, put_headers) { |response, request, result, &block|
83
+ RestClient.put(url.to_s, params.to_json, put_headers) { |response, request, result, &block|
81
84
  handle_response(response, request, result)
82
85
  }
83
86
  else
84
- get_args = { method: method, url: url, timeout: -1,
85
- headers: default_headers.merge(params: params).merge(headers)
87
+ url.query_values = (url.query_values || {}).merge(params) if params.any?
88
+ get_args = { method: method, url: url.to_s, timeout: -1,
89
+ headers: default_headers.merge(headers)
86
90
  }
87
91
  RestClient::Request.execute(get_args) { |response, request, result, &block|
88
92
  handle_response(response, request, result)
@@ -1,4 +1,4 @@
1
1
  module GlobalRegistry
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
4
4
 
data/spec/base_spec.rb CHANGED
@@ -14,13 +14,21 @@ describe 'Base' do
14
14
  end
15
15
 
16
16
  it 'can be configured' do
17
- @custom_gr_url = stub_request(:get, 'http://cru.org/bases')
17
+ @custom_gr_url = stub_request(:get, 'https://cru.org/bases')
18
18
  .with(headers: { authorization: 'Bearer qwer',
19
19
  'X-Forwarded-For': '203.0.113.7' })
20
20
  .to_return(:body => {a: 'b'}.to_json)
21
- gr = GlobalRegistry::Base.new(access_token: 'qwer', base_url: 'cru.org', xff: '203.0.113.7')
21
+ gr = GlobalRegistry::Base.new(access_token: 'qwer', base_url: 'https://cru.org', xff: '203.0.113.7')
22
22
  expect(gr.get).to be_a Hash
23
23
  expect(@custom_gr_url).to have_been_requested
24
24
  end
25
25
  end
26
+
27
+ describe '#find' do
28
+ it 'correctly handles array params' do
29
+ @custom_gr_url = stub_request(:get, 'http://google.com/bases/1?a[]=b&a[]=c')
30
+ GlobalRegistry::Base.find(1, 'a[]': ['b','c'])
31
+ expect(@custom_gr_url).to have_been_requested
32
+ end
33
+ end
26
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global_registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Starcher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client