Class: EcwidApi::Client
- Inherits:
-
Object
- Object
- EcwidApi::Client
- Extended by:
- Forwardable
- Defined in:
- lib/ecwid_api/client.rb
Overview
Constant Summary collapse
- DEFAULT_URL =
The default base URL for the Ecwid API
"https://app.ecwid.com/api/v3"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#customers ⇒ Object
readonly
Returns the value of attribute customers.
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
-
#product_types ⇒ Object
readonly
Returns the value of attribute product_types.
-
#products ⇒ Object
readonly
Returns the value of attribute products.
-
#store_id ⇒ Object
readonly
Public: Returns the Ecwid Store ID.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #delete(*args, &block) ⇒ Object
-
#initialize(store_id, token, adapter = Faraday.default_adapter) ⇒ Client
constructor
Public: Initializes a new Client to interact with the API.
- #post(*args, &block) ⇒ Object
-
#post_image(url, filename) ⇒ Object
Public: A helper method for POSTing an image.
- #put(*args, &block) ⇒ Object
-
#store_url ⇒ Object
Public: The URL of the API for the Ecwid Store.
Constructor Details
#initialize(store_id, token, adapter = Faraday.default_adapter) ⇒ Client
Public: Initializes a new Client to interact with the API
store_id - the Ecwid store_id to interact with token - the authorization token provided by oAuth. See the
Authentication class
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ecwid_api/client.rb', line 31 def initialize(store_id, token, adapter = Faraday.default_adapter) @store_id, @token, @adapter = store_id, token, adapter @connection = Faraday.new store_url do |conn| conn.request :oauth2, token, param_name: :token conn.request :json conn.response :json, content_type: /\bjson$/ conn.response :logger conn.adapter adapter end @categories = Api::Categories.new(self) @customers = Api::Customers.new(self) @orders = Api::Orders.new(self) @products = Api::Products.new(self) @product_types = Api::ProductTypes.new(self) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
21 22 23 |
# File 'lib/ecwid_api/client.rb', line 21 def adapter @adapter end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
23 24 25 |
# File 'lib/ecwid_api/client.rb', line 23 def categories @categories end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
23 24 25 |
# File 'lib/ecwid_api/client.rb', line 23 def connection @connection end |
#customers ⇒ Object (readonly)
Returns the value of attribute customers.
23 24 25 |
# File 'lib/ecwid_api/client.rb', line 23 def customers @customers end |
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
23 24 25 |
# File 'lib/ecwid_api/client.rb', line 23 def orders @orders end |
#product_types ⇒ Object (readonly)
Returns the value of attribute product_types.
23 24 25 |
# File 'lib/ecwid_api/client.rb', line 23 def product_types @product_types end |
#products ⇒ Object (readonly)
Returns the value of attribute products.
23 24 25 |
# File 'lib/ecwid_api/client.rb', line 23 def products @products end |
#store_id ⇒ Object (readonly)
Public: Returns the Ecwid Store ID
19 20 21 |
# File 'lib/ecwid_api/client.rb', line 19 def store_id @store_id end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
20 21 22 |
# File 'lib/ecwid_api/client.rb', line 20 def token @token end |
Instance Method Details
#delete(*args, &block) ⇒ Object
66 67 68 |
# File 'lib/ecwid_api/client.rb', line 66 def delete(*args, &block) raise_on_failure connection.delete(*args, &block) end |
#post(*args, &block) ⇒ Object
58 59 60 |
# File 'lib/ecwid_api/client.rb', line 58 def post(*args, &block) raise_on_failure connection.post(*args, &block) end |
#post_image(url, filename) ⇒ Object
Public: A helper method for POSTing an image
url - the URL to POST the image to filename - the path or URL to the image to upload
Returns a Faraday::Response
77 78 79 80 81 |
# File 'lib/ecwid_api/client.rb', line 77 def post_image(url, filename) post(url) do |req| req.body = open(filename).read end end |
#put(*args, &block) ⇒ Object
62 63 64 |
# File 'lib/ecwid_api/client.rb', line 62 def put(*args, &block) raise_on_failure connection.put(*args, &block) end |
#store_url ⇒ Object
Public: The URL of the API for the Ecwid Store
52 53 54 |
# File 'lib/ecwid_api/client.rb', line 52 def store_url "#{DEFAULT_URL}/#{store_id}" end |