Class: CodesWholesale::Client
- Inherits:
-
Object
- Object
- CodesWholesale::Client
- Includes:
- Accounts, Orders, Products, Configurable
- Defined in:
- lib/codes_wholesale/client.rb,
lib/codes_wholesale/client/orders.rb,
lib/codes_wholesale/client/accounts.rb,
lib/codes_wholesale/client/products.rb
Defined Under Namespace
Modules: Accounts, Orders, Products
Instance Attribute Summary
Attributes included from Configurable
#api_version, #client_id, #client_secret, #environment, #user_agent
Instance Method Summary collapse
- #agent ⇒ Object
- #get(url, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #post(url, options = {}) ⇒ Object
- #token ⇒ Object
Methods included from Orders
Methods included from Products
Methods included from Accounts
Methods included from Configurable
#api_endpoint, #configure, keys, #reset!
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/codes_wholesale/client.rb', line 13 def initialize( = {}) CodesWholesale::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", [key] || CodesWholesale.instance_variable_get(:"@#{key}")) end end |
Instance Method Details
#agent ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/codes_wholesale/client.rb', line 23 def agent @agent ||= Sawyer::Agent.new(api_endpoint, ) do |http| http.headers[:content_type] = 'application/json' http.headers[:user_agent] = user_agent http. :Bearer, token.token http.response :logger http.adapter Faraday.default_adapter end end |
#get(url, options = {}) ⇒ Object
33 34 35 |
# File 'lib/codes_wholesale/client.rb', line 33 def get(url, = {}) request(:get, url, ) end |
#post(url, options = {}) ⇒ Object
37 38 39 |
# File 'lib/codes_wholesale/client.rb', line 37 def post(url, = {}) request(:post, url, ) end |
#token ⇒ Object
19 20 21 |
# File 'lib/codes_wholesale/client.rb', line 19 def token OAuth2::Client.new(client_id, client_secret, site: "#{api_endpoint}/oauth/token").client_credentials.get_token end |