README.md in bootic_client-0.0.1 vs README.md in bootic_client-0.0.2

- old
+ new

@@ -1,6 +1,7 @@ [![Build Status](https://travis-ci.org/bootic/bootic_client.rb.svg?branch=master)](https://travis-ci.org/bootic/bootic_client.rb) +[![Gem Version](https://badge.fury.io/rb/bootic_client.svg)](http://badge.fury.io/rb/bootic_client) ## WORK IN PROGRESS # BooticClient @@ -22,10 +23,12 @@ ## Usage ### Configure with you app's credentials +You first must create an OAuth2 Application in your Bootic dashboard. Then configure the client with your `client_id` and `client_secret`. + ```ruby BooticClient.configure do |c| c.client_id = ENV['BOOTIC_CLIENT_ID'] c.client_secret = ENV['BOOTIC_CLIENT_SECRET'] c.logger = Logger.new(STDOUT) @@ -39,13 +42,13 @@ ```ruby bootic = BooticClient.client(:authorized, access_token: 'beidjbewjdiedue...', logging: true) root = bootic.root -if root.has?(:products) +if root.has?(:all_products) # All products - all_products = root.products(q: 'xmas presents') + all_products = root.all_products(q: 'xmas presents') all_products.total_items # => 23443 all_products.each do |product| puts product.title puts product.price end @@ -55,30 +58,36 @@ next_page.each{...} end end ``` -## 1. Refresh token flow (web apps) +## Strategies +The Bootic Client supports different authentication strategies depending on the use case. + +### 1. Refresh token flow (web apps) + In this flow you first get a token by authorizing an app. ie. using [omniauth-bootic](https://github.com/bootic/omniauth-bootic) ```ruby def client @client ||= BooticClient.client(:authorized, access_token: session[:access_token]) do |new_token| session[:access_token] = new_token end end ``` +Note how the client takes an optional block. This block will be called with a new access token whenever the old one expires. +It's up to your code to store this token somewhere. +### 2. User-less flow (client credentials - automated scripts) -## 2. User-less flow (client credentials - automated scripts) +This flow will first use your client credentials to obtain an access_token if started without one. ```ruby client = BooticClient.client(:client_credentials, scope: 'admin', access_token: some_store[:access_token]) do |new_token| some_store[:access_token] = new_token end ``` - ## Cache storage `BooticClient` honours HTTP caching headers included in API responses (such as `ETag` and `Last-Modified`).