Class: EasybillRestClient::DocumentApi

Inherits:
GenericApi
  • Object
show all
Defined in:
lib/easybill_rest_client/document_api.rb

Instance Attribute Summary

Attributes inherited from GenericApi

#api_client

Instance Method Summary collapse

Methods inherited from GenericApi

#build, #delete, #find, #find_all, #initialize, #save, #update

Constructor Details

This class inherits a constructor from EasybillRestClient::GenericApi

Instance Method Details

#cancel(document_id) ⇒ Object



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

def cancel(document_id)
  build(api_client.request(:post, "/documents/#{document_id}/cancel"))
end

#create(entity) ⇒ Object

This works around an issue on Easybill’s side, where they throw an exception about an item’s ‘id` being `null`, which only seems to go away if we compact the whole hash.



10
11
12
13
14
# File 'lib/easybill_rest_client/document_api.rb', line 10

def create(entity)
  attributes = entity.attributes
  attributes[:items] = entity.items.map { |item| item.attributes.compact }
  build(api_client.request(:post, "/#{resource_name}", attributes))
end

#finish(document_id) ⇒ Object



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

def finish(document_id)
  build(api_client.request(:put, "/#{resource_name}/#{document_id}/done"))
end

#get_pdf(document_id) ⇒ Object



24
25
26
# File 'lib/easybill_rest_client/document_api.rb', line 24

def get_pdf(document_id)
  api_client.request(:get, "/#{resource_name}/#{document_id}/pdf")
end

#resource_classObject



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

def resource_class
  Document
end

#resource_nameObject



16
17
18
# File 'lib/easybill_rest_client/document_api.rb', line 16

def resource_name
  'documents'
end

#send_email(document_id, email_params = {}) ⇒ Object



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

def send_email(document_id, email_params = {})
  api_client.request(:post, "/#{resource_name}/#{document_id}/send/email", email_params)
end