Class: EcwidApi::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:

Raises:



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_keyObject

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_keyObject

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_idObject

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

#categoriesObject

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_urlObject

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

#urlObject

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