bootic_client 0.0.1 → 0.0.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: 4311719bc6b53b09e5026c67183f7313c491f48f
4
- data.tar.gz: 7f85b7946a404ae8b32019cb05df811ce6a60709
3
+ metadata.gz: c3577184c13b3c030b8e7bce4bd7e560856564de
4
+ data.tar.gz: 06ceb2c371d1f60bdb4f246821397789401aa4d9
5
5
  SHA512:
6
- metadata.gz: 125c0102f1890b005ef8e4ff9ca74f4f597d16c8c542c097edb1e5541ee17c05edc3cd64b0200e7dc61282bd1d5b72dcf8a32e8f3b5f1ce2e0f11ee4907e86f9
7
- data.tar.gz: f9b42eeb52e5e031b35d3b2d3c25a20408e0753348c60e358b3fd8fa8f198a21918c8958377a809484f65304ff2b60a1209f1081eb8cc36c75da6ab34e45d187
6
+ metadata.gz: 5de054c0e2b96d5782e857f962991d27118552d23bd973d581a890d3074a46edb5869c36ff179a142f7b261dadb9d905ab7dae38d7b729d3b600b4bca8bbbff6
7
+ data.tar.gz: 43a6af6c0fef9c9bb91481b29a94fe788578778ff4a3d76942a56c7ce32992b3d5d7a7a5c05bc63fe0813c6b7837b17871da49f4764ebb55f069eef86663e09d
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://travis-ci.org/bootic/bootic_client.rb.svg?branch=master)](https://travis-ci.org/bootic/bootic_client.rb)
2
+ [![Gem Version](https://badge.fury.io/rb/bootic_client.svg)](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?(:products)
47
+ if root.has?(:all_products)
45
48
  # All products
46
- all_products = root.products(q: 'xmas presents')
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
- ## 1. Refresh token flow (web apps)
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
- ## 2. User-less flow (client credentials - automated scripts)
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
@@ -1,3 +1,3 @@
1
1
  module BooticClient
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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!')
@@ -15,6 +15,7 @@ describe 'BooticClient::Strategies::ClientCredentials' do
15
15
 
16
16
  describe 'with missing client credentials' do
17
17
  it 'raises error' do
18
+ BooticClient.client_id = nil
18
19
  expect{
19
20
  BooticClient.client(:client_credentials, scope: 'admin')
20
21
  }.to raise_error
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.1
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-15 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday