restful_resource 2.2.8 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ec111ab5ac7ec4d10d07eaaff544481e7267280d
4
- data.tar.gz: 97286bf61d3fce595bec163ecdacbb0fddaf2f54
2
+ SHA256:
3
+ metadata.gz: eecf67a6ba417dae5f868966a577a527eaf35560ddf9ec17af5aa7070e9935bb
4
+ data.tar.gz: 4ddd23ce149cd8f4f9db30af2cdef923654771608108ed44ff8891199bb1643c
5
5
  SHA512:
6
- metadata.gz: e82565fc5a04369d88a211c702e49f7bf95998a16fa00b39a64bcd97f598c4ccc2f68a6b4f0a90a82f85f98c59adb1205aa39c69fc17659311904e9b2a4f1ac6
7
- data.tar.gz: 2b3c6af8446db0154e62f4b4809b020d8f30f1503f14d65bf989ae749feef95d0388c63a88ee36c55b08fe1b43bd478fcb43e6f990f2ae7947ab5552a2f36ab7
6
+ metadata.gz: 6893e6298085c0e14e28f5d08ca7ab9144eafea210d18eabeb865df3dfa9b670af1a9f0052db5a0c2ad84ed6f6b9061cb0e101b7724514385e9b14509ab138e4
7
+ data.tar.gz: 0f2c0c895a4ae9a77d17b6816a15cbd0cd17f0bdbb6e46417aebfd471f1c2e33e0f3c8c997016e7bb2213d25058c6b9525106bd870145a5e8efee0da15325d9a
data/Rakefile CHANGED
@@ -9,12 +9,12 @@ desc "Upload to rubygems"
9
9
  task :upload => :build do
10
10
  # Check if tag with v#{ResearchSiteApiClient::VERSION} version exists, if so, return with error
11
11
 
12
- if tag_exists?(current_tag_name)
13
- puts "Tag exists, did you run rake increase_revision_number after merging with master?"
14
- exit 1
15
- end
12
+ # if tag_exists?(current_tag_name)
13
+ # puts "Tag exists, did you run rake increase_revision_number after merging with master?"
14
+ # exit 1
15
+ # end
16
16
 
17
- create_tag(current_tag_name)
17
+ # create_tag(current_tag_name)
18
18
  Rake::Task[:release].invoke
19
19
  end
20
20
 
@@ -5,6 +5,7 @@ module RestfulResource
5
5
  def self.configure(base_url: nil,
6
6
  username: nil,
7
7
  password: nil,
8
+ auth_token: nil,
8
9
  logger: nil,
9
10
  cache_store: nil,
10
11
  instrumentation: {},
@@ -14,6 +15,7 @@ module RestfulResource
14
15
 
15
16
  @http = RestfulResource::HttpClient.new(username: username,
16
17
  password: password,
18
+ auth_token: auth_token,
17
19
  logger: logger,
18
20
  cache_store: cache_store,
19
21
  instrumentation: instrumentation,
@@ -70,6 +70,7 @@ module RestfulResource
70
70
 
71
71
  def initialize(username: nil,
72
72
  password: nil,
73
+ auth_token: nil,
73
74
  logger: nil,
74
75
  cache_store: nil,
75
76
  connection: nil,
@@ -101,7 +102,12 @@ module RestfulResource
101
102
  server_cache_instrument_name: instrumentation.fetch(:server_cache_instrument_name, nil),
102
103
  faraday_config: faraday_config)
103
104
 
104
- @connection.basic_auth(username, password) if username && password
105
+ if auth_token
106
+ @connection.headers[:authorization] = "Bearer #{auth_token}"
107
+ elsif username && password
108
+ @connection.basic_auth(username, password)
109
+ end
110
+
105
111
  @connection.headers[:user_agent] = build_user_agent(instrumentation[:app_name])
106
112
  @default_open_timeout = open_timeout
107
113
  @default_timeout = timeout
@@ -1,3 +1,3 @@
1
1
  module RestfulResource
2
- VERSION = '2.2.8'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -313,6 +313,7 @@ RSpec.describe RestfulResource::Base do
313
313
  describe ".configure" do
314
314
  let(:username) { double }
315
315
  let(:password) { double }
316
+ let(:auth_token) { double }
316
317
  let(:logger) { double }
317
318
  let(:cache_store) { double }
318
319
  let(:instrumentation) { double }
@@ -321,6 +322,7 @@ RSpec.describe RestfulResource::Base do
321
322
  it "passes arguments to HttpClient" do
322
323
  expect(RestfulResource::HttpClient).to receive(:new).with(username: username,
323
324
  password: password,
325
+ auth_token: auth_token,
324
326
  logger: logger,
325
327
  cache_store: cache_store,
326
328
  instrumentation: instrumentation,
@@ -329,6 +331,7 @@ RSpec.describe RestfulResource::Base do
329
331
  RestfulResource::Base.configure(base_url: 'http://foo.bar',
330
332
  username: username,
331
333
  password: password,
334
+ auth_token: auth_token,
332
335
  logger: logger,
333
336
  cache_store: cache_store,
334
337
  instrumentation: instrumentation,
@@ -169,18 +169,36 @@ RSpec.describe RestfulResource::HttpClient do
169
169
  end
170
170
 
171
171
  describe 'Authentication' do
172
- def http_client(connection)
173
- described_class.new(connection: connection, username: 'user', password: 'passwd')
172
+ describe 'Basic auth' do
173
+ def http_client(connection)
174
+ described_class.new(connection: connection, username: 'user', password: 'passwd')
175
+ end
176
+
177
+ it 'should execute authenticated get' do
178
+ connection = faraday_connection do |stubs|
179
+ stubs.get('http://httpbin.org/basic-auth/user/passwd') { |env| [200, {}, nil] }
180
+ end
181
+
182
+ response = http_client(connection).get('http://httpbin.org/basic-auth/user/passwd', headers: {"Authorization"=>"Basic dXNlcjpwYXNzd2Q="})
183
+
184
+ expect(response.status).to eq 200
185
+ end
174
186
  end
175
187
 
176
- it 'should execute authenticated get' do
177
- connection = faraday_connection do |stubs|
178
- stubs.get('http://httpbin.org/basic-auth/user/passwd') { |env| [200, {}, nil] }
188
+ describe 'Token auth' do
189
+ def http_client(connection)
190
+ described_class.new(connection: connection, auth_token: 'abc123')
179
191
  end
180
192
 
181
- response = http_client(connection).get('http://httpbin.org/basic-auth/user/passwd', headers: {"Authorization"=>"Basic dXNlcjpwYXNzd2Q="})
193
+ it 'should execute authenticated get' do
194
+ connection = faraday_connection do |stubs|
195
+ stubs.get('http://httpbin.org/bearer', { 'Authorization' => 'Bearer abc123'} ) { |env| [200, {}, nil] }
196
+ end
182
197
 
183
- expect(response.status).to eq 200
198
+ response = http_client(connection).get('http://httpbin.org/bearer', headers: { 'Authorization' => 'Bearer abc123'})
199
+
200
+ expect(response.status).to eq 200
201
+ end
184
202
  end
185
203
  end
186
204
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.8
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Santoro
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-25 00:00:00.000000000 Z
12
+ date: 2018-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  version: '0'
259
259
  requirements: []
260
260
  rubyforge_project:
261
- rubygems_version: 2.6.14.1
261
+ rubygems_version: 2.7.7
262
262
  signing_key:
263
263
  specification_version: 4
264
264
  summary: A simple activerecord inspired rest resource base class implemented using