Class: Cin7API::Client

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

Constant Summary collapse

BASE_URL =
"https://api.cin7.com/api/v1/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, api_key:, adapter: Faraday.default_adapter) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
# File 'lib/cin7_api/client.rb', line 11

def initialize(username:, api_key:, adapter: Faraday.default_adapter)
  @username = username
  @api_key = api_key
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



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

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#branchObject



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

def branch
  BranchResource.new(self)
end

#connectionObject



33
34
35
36
37
38
39
40
41
# File 'lib/cin7_api/client.rb', line 33

def connection
  @connection ||= Faraday.new do |conn|
    conn.url_prefix = BASE_URL
    conn.request :json
    conn.response :json, content_type: "application/json"
    conn.adapter adapter
    conn.request :authorization, :basic, username, api_key
  end
end

#credit_noteObject



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

def credit_note
  CreditNoteResource.new(self)
end

#paymentObject



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

def payment
  PaymentResource.new(self)
end

#sales_orderObject



17
18
19
# File 'lib/cin7_api/client.rb', line 17

def sales_order
  SalesOrderResource.new(self)
end