bootic_client 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +14 -5
- data/lib/bootic_client/strategies/strategy.rb +1 -1
- data/lib/bootic_client/version.rb +1 -1
- data/spec/authorized_strategy_spec.rb +8 -0
- data/spec/client_credentials_strategy_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3577184c13b3c030b8e7bce4bd7e560856564de
|
4
|
+
data.tar.gz: 06ceb2c371d1f60bdb4f246821397789401aa4d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5de054c0e2b96d5782e857f962991d27118552d23bd973d581a890d3074a46edb5869c36ff179a142f7b261dadb9d905ab7dae38d7b729d3b600b4bca8bbbff6
|
7
|
+
data.tar.gz: 43a6af6c0fef9c9bb91481b29a94fe788578778ff4a3d76942a56c7ce32992b3d5d7a7a5c05bc63fe0813c6b7837b17871da49f4764ebb55f069eef86663e09d
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[](https://travis-ci.org/bootic/bootic_client.rb)
|
2
|
+
[](http://badge.fury.io/rb/bootic_client)
|
2
3
|
|
3
4
|
## WORK IN PROGRESS
|
4
5
|
|
@@ -24,6 +25,8 @@ Or install it yourself as:
|
|
24
25
|
|
25
26
|
### Configure with you app's credentials
|
26
27
|
|
28
|
+
You first must create an OAuth2 Application in your Bootic dashboard. Then configure the client with your `client_id` and `client_secret`.
|
29
|
+
|
27
30
|
```ruby
|
28
31
|
BooticClient.configure do |c|
|
29
32
|
c.client_id = ENV['BOOTIC_CLIENT_ID']
|
@@ -41,9 +44,9 @@ bootic = BooticClient.client(:authorized, access_token: 'beidjbewjdiedue...', lo
|
|
41
44
|
|
42
45
|
root = bootic.root
|
43
46
|
|
44
|
-
if root.has?(:
|
47
|
+
if root.has?(:all_products)
|
45
48
|
# All products
|
46
|
-
all_products = root.
|
49
|
+
all_products = root.all_products(q: 'xmas presents')
|
47
50
|
all_products.total_items # => 23443
|
48
51
|
all_products.each do |product|
|
49
52
|
puts product.title
|
@@ -57,7 +60,11 @@ if root.has?(:products)
|
|
57
60
|
end
|
58
61
|
```
|
59
62
|
|
60
|
-
##
|
63
|
+
## Strategies
|
64
|
+
|
65
|
+
The Bootic Client supports different authentication strategies depending on the use case.
|
66
|
+
|
67
|
+
### 1. Refresh token flow (web apps)
|
61
68
|
|
62
69
|
In this flow you first get a token by authorizing an app. ie. using [omniauth-bootic](https://github.com/bootic/omniauth-bootic)
|
63
70
|
|
@@ -68,9 +75,12 @@ def client
|
|
68
75
|
end
|
69
76
|
end
|
70
77
|
```
|
78
|
+
Note how the client takes an optional block. This block will be called with a new access token whenever the old one expires.
|
79
|
+
It's up to your code to store this token somewhere.
|
71
80
|
|
81
|
+
### 2. User-less flow (client credentials - automated scripts)
|
72
82
|
|
73
|
-
|
83
|
+
This flow will first use your client credentials to obtain an access_token if started without one.
|
74
84
|
|
75
85
|
```ruby
|
76
86
|
client = BooticClient.client(:client_credentials, scope: 'admin', access_token: some_store[:access_token]) do |new_token|
|
@@ -78,7 +88,6 @@ client = BooticClient.client(:client_credentials, scope: 'admin', access_token:
|
|
78
88
|
end
|
79
89
|
```
|
80
90
|
|
81
|
-
|
82
91
|
## Cache storage
|
83
92
|
|
84
93
|
`BooticClient` honours HTTP caching headers included in API responses (such as `ETag` and `Last-Modified`).
|
@@ -5,7 +5,7 @@ module BooticClient
|
|
5
5
|
class Strategy
|
6
6
|
|
7
7
|
def initialize(config, client_opts = {}, &on_new_token)
|
8
|
-
@config, @options, @on_new_token = config, client_opts, (on_new_token || Proc.new)
|
8
|
+
@config, @options, @on_new_token = config, client_opts, (on_new_token || Proc.new{})
|
9
9
|
raise "MUST include client_id" unless config.client_id
|
10
10
|
raise "MUST include client_secret" unless config.client_secret
|
11
11
|
raise "MUST include api_root" unless config.api_root
|
@@ -82,6 +82,14 @@ describe 'BooticClient::Strategies::Authorized' do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
context 'without a block' do
|
86
|
+
it 'is valid' do
|
87
|
+
expect{
|
88
|
+
BooticClient.client(:authorized, access_token: 'abc')
|
89
|
+
}.not_to raise_error
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
85
93
|
context 'with valid token' do
|
86
94
|
before do
|
87
95
|
@root_request = stub_api_root('abc', 200, message: 'Hello!')
|
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.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|