Class: Koho::Client

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

Defined Under Namespace

Classes: Contracts, Customers, InboundInvoices, InvoiceTerms, Invoices, ProjectTasks, Projects, WorkSessions

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.



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

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

Instance Attribute Details

#company_idObject

Returns the value of attribute company_id.



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

def company_id
  @company_id
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#contractsObject



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

def contracts; Contracts.new company_id, token; end

#customersObject



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

def customers; Customers.new company_id, token; end

#delete(action) ⇒ Object



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

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

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



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

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

#inbound_invoicesObject



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

def inbound_invoices; InboundInvoices.new company_id, token; end

#infoObject

3



55
56
57
# File 'lib/koho.rb', line 55

def info 
  get '/info'
end

#invoice_termsObject



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

def invoice_terms; InvoiceTerms.new company_id, token; end

#invoicesObject



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

def invoices; Invoices.new company_id, token; end

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



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

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

#project_tasksObject



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

def project_tasks; ProjectTasks.new company_id, token; end

#projectsObject



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

def projects; Projects.new company_id, token; end

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



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

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

#work_sessionsObject



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

def work_sessions; WorkSessions.new company_id, token; end