Class: EcwidApi::Client
- Inherits:
-
Object
- Object
- EcwidApi::Client
- Defined in:
- lib/ecwid_api/client.rb
Overview
Public: Client objects manage the connection and interface to a single Ecwid store.
Examples
client = EcwidApi::Client.new do |config|
config.store_id = '12345'
config.url = 'http://app.ecwid.com/api/v1'
config.order_secret_key = 'ORDER_SECRET_KEY'
config.product_secret_key = 'PRODUCT_SECRET_KEY'
end
Constant Summary collapse
- DEFAULT_URL =
The default base URL for the Ecwid API
"https://app.ecwid.com/api/v1"
Instance Attribute Summary collapse
-
#order_secret_key ⇒ Object
Public: Gets or sets the Order API Secret Key for the Ecwid Store.
-
#product_secret_key ⇒ Object
Public: Gets or sets the default Product API Secret Key for the Ecwid Store.
-
#store_id ⇒ Object
Public: Returns the Ecwid Store ID.
Instance Method Summary collapse
-
#categories ⇒ Object
Public: Returns the Category API.
-
#get(path, params = {}) ⇒ Object
Public: Sends a GET request to the Ecwid API.
-
#initialize {|_self| ... } ⇒ Client
constructor
A new instance of Client.
-
#store_url ⇒ Object
Public: The URL of the API for the Ecwid Store.
-
#url ⇒ Object
Public: Returns the base URL of the Ecwid API.
-
#url=(url) ⇒ Object
Public: Sets the base URL for the Ecwid API.
Constructor Details
#initialize {|_self| ... } ⇒ Client
Returns a new instance of Client.
30 31 32 33 |
# File 'lib/ecwid_api/client.rb', line 30 def initialize yield(self) if block_given? raise Error.new("The store_id is required") unless store_id end |
Instance Attribute Details
#order_secret_key ⇒ Object
Public: Gets or sets the Order API Secret Key for the Ecwid Store
25 26 27 |
# File 'lib/ecwid_api/client.rb', line 25 def order_secret_key @order_secret_key end |
#product_secret_key ⇒ Object
Public: Gets or sets the default Product API Secret Key for the Ecwid Store
28 29 30 |
# File 'lib/ecwid_api/client.rb', line 28 def product_secret_key @product_secret_key end |
#store_id ⇒ Object
Public: Returns the Ecwid Store ID
22 23 24 |
# File 'lib/ecwid_api/client.rb', line 22 def store_id @store_id end |
Instance Method Details
#categories ⇒ Object
Public: Returns the Category API
74 75 76 |
# File 'lib/ecwid_api/client.rb', line 74 def categories @categories ||= CategoryApi.new(self) end |
#get(path, params = {}) ⇒ Object
Public: Sends a GET request to the Ecwid API
path - The String path for the URL of the request without the base URL params - A Hash of query string parameters
Examples
# Gets the Categories where the parent Category is 1
client.get("categories", parent: 1)
# => #<Faraday::Response>
Returns a Faraday::Response
69 70 71 |
# File 'lib/ecwid_api/client.rb', line 69 def get(path, params={}) connection.get(path, params) end |
#store_url ⇒ Object
Public: The URL of the API for the Ecwid Store
53 54 55 |
# File 'lib/ecwid_api/client.rb', line 53 def store_url "#{url}/#{store_id}" end |
#url ⇒ Object
Public: Returns the base URL of the Ecwid API
36 37 38 |
# File 'lib/ecwid_api/client.rb', line 36 def url @url || DEFAULT_URL end |
#url=(url) ⇒ Object
Public: Sets the base URL for the Ecwid API
41 42 43 44 |
# File 'lib/ecwid_api/client.rb', line 41 def url=(url) reset_connection @url = url end |