Class: Arctic::Vendor::API
- Inherits:
-
Object
- Object
- Arctic::Vendor::API
- Defined in:
- lib/arctic/vendor/api.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(**options) ⇒ API
constructor
A new instance of API.
-
#list_accounts ⇒ Object
List the current accounts available to the vendor.
-
#list_shops(account_id) ⇒ Object
List shops for a single account.
-
#send_products(account_id, shop_id, products) ⇒ Object
Send products to the Core API.
-
#show_account(account_id) ⇒ Object
Show details about a single account.
Constructor Details
#initialize(**options) ⇒ API
Returns a new instance of API.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/arctic/vendor/api.rb', line 10 def initialize(**) api_token = .fetch(:token, ENV.fetch('ARCTIC_CORE_API_TOKEN')) api_url = .fetch(:url, ENV.fetch('ARCTIC_CORE_API_URL', 'http://localhost:5000/v1/vendors')) @token = api_token headers = { Authorization: "Vendor #{token}", 'Content-Type': 'application/json', Accept: 'application/json', } @connection = Faraday.new url: api_url.chomp('/'), headers: headers end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/arctic/vendor/api.rb', line 8 def connection @connection end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
8 9 10 |
# File 'lib/arctic/vendor/api.rb', line 8 def token @token end |
Instance Method Details
#list_accounts ⇒ Object
List the current accounts available to the vendor
26 27 28 |
# File 'lib/arctic/vendor/api.rb', line 26 def list_accounts make_request :get, 'accounts' end |
#list_shops(account_id) ⇒ Object
List shops for a single account
36 37 38 |
# File 'lib/arctic/vendor/api.rb', line 36 def list_shops(account_id) make_request :get, "accounts/#{account_id}/shops" end |
#send_products(account_id, shop_id, products) ⇒ Object
Send products to the Core API
41 42 43 44 45 |
# File 'lib/arctic/vendor/api.rb', line 41 def send_products(account_id, shop_id, products) products.tap do |px| make_batch_request :post, "accounts/#{account_id}/shops/#{shop_id}/products", body: px end end |
#show_account(account_id) ⇒ Object
Show details about a single account
31 32 33 |
# File 'lib/arctic/vendor/api.rb', line 31 def show_account(account_id) make_request :get, "accounts/#{account_id}" end |