bootic_client 0.0.17 → 0.0.18

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: e6d9d6472ee6d6d5ee26f1990f332eb1237b5769
4
- data.tar.gz: 31a1c0ac6719d1ec0491b9da3a595491e50379e8
3
+ metadata.gz: 7a89d8b5c05c6db2600def4db1c010412968182c
4
+ data.tar.gz: 407389c386a7f6323a4651b7200ce00881c9b0e9
5
5
  SHA512:
6
- metadata.gz: ebae4dfbebe06f14fd5c6d63931a92f5be0421beca9c37a9d0507a7049a71118af2341c8d1077c127c55a711c089917d477a49ab7d0eded308fd6a2152d61995
7
- data.tar.gz: 3ba8bf14ac98e1413726778b0a1eacaaf87ab148c056b51435156f8268487b982956973afd4e3a79f8d99f6d77d54f4d63a825982cf30e7e68741dad904e1336
6
+ metadata.gz: 703206264feeb2ce9e7baa20da05704655736e6429c9df239dadb6c7f7b6b59af21a154be20665d31760a372e829606665f68852c4a025a55bd20ce418fdbc63
7
+ data.tar.gz: 7001187975d691991a6ef3df1e8641776fdd42bc0462c3ad6f1580a6805a455cb2cccc2e64f82000f46ac5b05978c5015b65e797644047df06c9a18e4ca9718a
data/CHANGELOG.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Change Log
2
2
 
3
- ## [Unreleased](https://github.com/bootic/bootic_client.rb/tree/HEAD)
4
-
5
- [Full Changelog](https://github.com/bootic/bootic_client.rb/compare/v0.0.16...HEAD)
3
+ ## [v0.0.17](https://github.com/bootic/bootic_client.rb/tree/v0.0.17) (2017-04-02)
4
+ [Full Changelog](https://github.com/bootic/bootic_client.rb/compare/v0.0.16...v0.0.17)
6
5
 
7
6
  **Merged pull requests:**
8
7
 
data/README.md CHANGED
@@ -129,6 +129,13 @@ root = client.root # etc
129
129
 
130
130
  NOTE: `username` and `password` have nothing to do with your Bootic administrative credentials, and will be up to API maintainers to define.
131
131
 
132
+ ### 4. Bearer token
133
+
134
+ This strategy adds an access token as a header in the format `Authorization: Bearer <your-token-here>`.
135
+ It will not try to refresh an expired token from an Oauth2 server, so there's no need to configure Oauth2 credentials.
136
+
137
+ Use this with APIs that don't expire tokens, or for testing.
138
+
132
139
  ## Non GET links
133
140
 
134
141
  Most resource links lead to `GET` resources, but some will expect `POST`, `PUT`, `DELETE` or others.
@@ -0,0 +1,22 @@
1
+ require 'bootic_client/strategies/strategy'
2
+
3
+ module BooticClient
4
+ module Strategies
5
+ class Bearer < Strategy
6
+
7
+ private
8
+
9
+ def validate!
10
+ raise ArgumentError, "options MUST include access_token" unless options[:access_token]
11
+ end
12
+
13
+ def request_headers
14
+ {
15
+ 'Authorization' => "Bearer #{options[:access_token]}"
16
+ }
17
+ end
18
+ end
19
+ end
20
+
21
+ strategies[:bearer] = Strategies::Bearer
22
+ end
@@ -1,3 +1,3 @@
1
1
  module BooticClient
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'BooticClient::Strategies::Bearer' do
4
+ require 'webmock/rspec'
5
+
6
+ let(:root_data) {
7
+ {
8
+ '_links' => {
9
+ 'a_product' => {'href' => 'https://api.bootic.net/v1/products/1'}
10
+ },
11
+ 'message' => "Hello!"
12
+ }
13
+ }
14
+
15
+ let(:product_data) {
16
+ {'title' => 'iPhone 6 Plus'}
17
+ }
18
+
19
+ let(:client) { BooticClient.client(:bearer, access_token: 'foobar') }
20
+
21
+ describe '#inspect' do
22
+ it 'is informative' do
23
+ expect(client.inspect).to eql %(#<BooticClient::Strategies::Bearer root: https://api.bootic.net/v1>)
24
+ end
25
+ end
26
+
27
+ context 'with missing access token' do
28
+ it 'raises error' do
29
+ expect{
30
+ BooticClient.client(:bearer)
31
+ }.to raise_error(ArgumentError)
32
+ end
33
+ end
34
+
35
+ context 'with invalid access token' do
36
+ let!(:root_request) do
37
+ stub_request(:get, 'https://api.bootic.net/v1')
38
+ .with(headers: {"Authorization" => "Bearer foobar"})
39
+ .to_return(status: 401, body: JSON.dump(root_data))
40
+ end
41
+
42
+ it 'raises an Unauthorized error' do
43
+ expect{ client.root }.to raise_error(BooticClient::UnauthorizedError)
44
+ expect(root_request).to have_been_requested
45
+ end
46
+ end
47
+
48
+ context 'with valid access token' do
49
+ let!(:root_request) do
50
+ stub_request(:get, 'https://api.bootic.net/v1')
51
+ .with(headers: {"Authorization" => "Bearer foobar"})
52
+ .to_return(status: 200, body: JSON.dump(root_data))
53
+ end
54
+
55
+ let!(:product_request) do
56
+ stub_request(:get, 'https://api.bootic.net/v1/products/1')
57
+ .with(headers: {"Authorization" => "Bearer foobar"})
58
+ .to_return(status: 200, body: JSON.dump(product_data))
59
+ end
60
+
61
+ let!(:root) { client.root }
62
+
63
+ it 'includes Basic Auth credentials in request' do
64
+ expect(root_request).to have_been_requested
65
+ expect(root.message).to eql('Hello!')
66
+ end
67
+
68
+ it 'follows links as normal, including bearer token in every request' do
69
+ product = root.a_product
70
+ expect(product_request).to have_been_requested
71
+ expect(product.title).to eql 'iPhone 6 Plus'
72
+ end
73
+ end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootic_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-02 00:00:00.000000000 Z
11
+ date: 2017-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -189,12 +189,14 @@ files:
189
189
  - lib/bootic_client/stores/memcache.rb
190
190
  - lib/bootic_client/strategies/authorized.rb
191
191
  - lib/bootic_client/strategies/basic_auth.rb
192
+ - lib/bootic_client/strategies/bearer.rb
192
193
  - lib/bootic_client/strategies/client_credentials.rb
193
194
  - lib/bootic_client/strategies/oauth2_strategy.rb
194
195
  - lib/bootic_client/strategies/strategy.rb
195
196
  - lib/bootic_client/version.rb
196
197
  - spec/authorized_strategy_spec.rb
197
198
  - spec/basic_auth_strategy_spec.rb
199
+ - spec/bearer_strategy_spec.rb
198
200
  - spec/bootic_client_spec.rb
199
201
  - spec/client_credentials_strategy_spec.rb
200
202
  - spec/client_spec.rb
@@ -230,6 +232,7 @@ summary: Official Ruby client for the Bootic API
230
232
  test_files:
231
233
  - spec/authorized_strategy_spec.rb
232
234
  - spec/basic_auth_strategy_spec.rb
235
+ - spec/bearer_strategy_spec.rb
233
236
  - spec/bootic_client_spec.rb
234
237
  - spec/client_credentials_strategy_spec.rb
235
238
  - spec/client_spec.rb