Class: Koho::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/koho.rb

Defined Under Namespace

Classes: Contracts, Customers, InboundInvoices, InvoiceTerms, Invoices

Constant Summary collapse

API_BASE_URL =
'https://dev.koho-online.com/api'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(company_id, token) ⇒ Client

Returns a new instance of Client.



16
17
18
19
# File 'lib/koho.rb', line 16

def initialize company_id, token
  @company_id = company_id
  @token = token
end

Instance Attribute Details

#company_idObject

Returns the value of attribute company_id.



13
14
15
# File 'lib/koho.rb', line 13

def company_id
  @company_id
end

#tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/koho.rb', line 13

def token
  @token
end

Instance Method Details

#contractsObject



41
# File 'lib/koho.rb', line 41

def contracts; Contracts.new company_id, token; end

#customersObject



37
# File 'lib/koho.rb', line 37

def customers; Customers.new company_id, token; end

#delete(action) ⇒ Object



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

def delete action
  JSON.parse(self.class.delete action, {method: '_DELETE', body: {company_id: @company_id, token: @token}})
end

#get(action, data = {}) ⇒ Object



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

def get action, data = {}
  JSON.parse(self.class.get action, query: data.merge(company_id: @company_id, token: @token))
end

#inbound_invoicesObject



39
# File 'lib/koho.rb', line 39

def inbound_invoices; InboundInvoices.new company_id, token; end

#infoObject

3



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

def info 
  get '/info'
end

#invoice_termsObject



40
# File 'lib/koho.rb', line 40

def invoice_terms; InvoiceTerms.new company_id, token; end

#invoicesObject



38
# File 'lib/koho.rb', line 38

def invoices; Invoices.new company_id, token; end

#post(action, data = {}) ⇒ Object



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

def post action, data = {}
  JSON.parse(self.class.post action, {method: '_POST', body: {company_id: @company_id, token: @token}.merge(data)})
end

#put(action, data = {}) ⇒ Object



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

def put action, data = {}
  JSON.parse(self.class.put action, {method: '_PUT', body: {company_id: @company_id, token: @token}.merge(data)})
end