Class: Creem::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/creem/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, test_mode: nil, timeout: nil, open_timeout: nil) ⇒ Client

Returns a new instance of Client.

Raises:



11
12
13
14
15
16
17
18
19
# File 'lib/creem/client.rb', line 11

def initialize(api_key: nil, test_mode: nil, timeout: nil, open_timeout: nil)
  @config = Configuration.new
  @config.api_key = api_key || Creem.configuration.api_key
  @config.test_mode = test_mode.nil? ? Creem.configuration.test_mode : test_mode
  @config.timeout = timeout || Creem.configuration.timeout
  @config.open_timeout = open_timeout || Creem.configuration.open_timeout

  raise ConfigurationError, "API key is required" if @config.api_key.nil? || @config.api_key.empty?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/creem/client.rb', line 9

def config
  @config
end

Instance Method Details

#checkoutsObject



25
26
27
# File 'lib/creem/client.rb', line 25

def checkouts
  @checkouts ||= Resources::Checkouts.new(self)
end

#customersObject



33
34
35
# File 'lib/creem/client.rb', line 33

def customers
  @customers ||= Resources::Customers.new(self)
end

#discountsObject



45
46
47
# File 'lib/creem/client.rb', line 45

def discounts
  @discounts ||= Resources::Discounts.new(self)
end

#get(path, params = {}) ⇒ Object



49
50
51
# File 'lib/creem/client.rb', line 49

def get(path, params = {})
  request(:get, path, params: params)
end

#licensesObject



41
42
43
# File 'lib/creem/client.rb', line 41

def licenses
  @licenses ||= Resources::Licenses.new(self)
end

#post(path, body = {}) ⇒ Object



53
54
55
# File 'lib/creem/client.rb', line 53

def post(path, body = {})
  request(:post, path, body: body)
end

#productsObject



21
22
23
# File 'lib/creem/client.rb', line 21

def products
  @products ||= Resources::Products.new(self)
end

#subscriptionsObject



29
30
31
# File 'lib/creem/client.rb', line 29

def subscriptions
  @subscriptions ||= Resources::Subscriptions.new(self)
end

#transactionsObject



37
38
39
# File 'lib/creem/client.rb', line 37

def transactions
  @transactions ||= Resources::Transactions.new(self)
end