Class: LoyverseApi::Client

Constant Summary

Constants included from Endpoints::Discounts

Endpoints::Discounts::APPLIES_TO_ITEM, Endpoints::Discounts::APPLIES_TO_RECEIPT, Endpoints::Discounts::DEFAULT_APPLIES_TO, Endpoints::Discounts::TYPE_DISCOUNT_BY_POINTS, Endpoints::Discounts::TYPE_FIXED_AMOUNT, Endpoints::Discounts::TYPE_FIXED_PERCENT, Endpoints::Discounts::TYPE_VARIABLE_AMOUNT, Endpoints::Discounts::TYPE_VARIABLE_PERCENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Endpoints::Modifiers

#create_modifier, #delete_modifier, #get_modifier, #list_modifiers

Methods included from Endpoints::Employees

#get_employee, #list_employees

Methods included from Endpoints::Discounts

#create_discount, #delete_discount, #get_discount, #list_discounts, #update_discount

Methods included from Endpoints::Customers

#create_customer, #delete_customer, #get_customer, #list_customers, #update_customer

Methods included from Endpoints::Webhooks

#create_webhook, #delete_webhook, #get_webhook, #list_webhooks, #verify_webhook_signature

Methods included from Endpoints::Receipts

#create_receipt, #create_refund, #get_receipt, #list_receipts

Methods included from Endpoints::Inventory

#list_inventory, #update_inventory

Methods included from Endpoints::Categories

#create_category, #delete_category, #get_category, #list_categories

Methods included from Endpoints::Items

#create_item, #delete_item, #get_item, #list_items, #update_item

Constructor Details

#initialize(configuration = nil) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
# File 'lib/loyverse_api/client.rb', line 17

def initialize(configuration = nil)
  @configuration = configuration || LoyverseApi.configuration || Configuration.new

  raise AuthenticationError, "Access token is required" if @configuration.access_token.nil?
end

Instance Attribute Details

#configuration ⇒ Object (readonly)

Returns the value of attribute configuration.



15
16
17
# File 'lib/loyverse_api/client.rb', line 15

def configuration
  @configuration
end

Instance Method Details

#connection ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/loyverse_api/client.rb', line 23

def connection
  @connection ||= Faraday.new(url: configuration.base_url) do |conn|
    conn.request :json
    conn.request :retry, {
      max: 3,
      interval: 0.5,
      interval_randomness: 0.5,
      backoff_factor: 2,
      retry_statuses: [429, 500, 502, 503, 504],
      methods: [:get, :post, :put, :delete]
    }
    conn.response :json, content_type: /\bjson$/
    conn.headers['Authorization'] = "Bearer #{configuration.access_token}"
    conn.headers['Content-Type'] = 'application/json'
    conn.headers['Accept'] = 'application/json'
    conn.adapter Faraday.default_adapter
    conn.options.timeout = configuration.timeout
    conn.options.open_timeout = configuration.open_timeout
  end
end

#delete(path) ⇒ Object



59
60
61
62
# File 'lib/loyverse_api/client.rb', line 59

def delete(path)
    response = connection.delete(path)
    response
end

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



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

def get(path, params: {})
    response = connection.get(path, params)
    response
end

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



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

def post(path, body: {})
    response = connection.post(path, body)
    response
end

#put(path, body: {}) ⇒ Object



54
55
56
57
# File 'lib/loyverse_api/client.rb', line 54

def put(path, body: {})
    response = connection.put(path, body)
    response
end