Class: ACube::Endpoint::Invoices

Inherits:
ItApiBase show all
Defined in:
lib/acube/endpoint/invoices.rb

Instance Attribute Summary

Attributes inherited from ItApiBase

#connection

Instance Method Summary collapse

Methods inherited from ItApiBase

#initialize

Constructor Details

This class inherits a constructor from ACube::Endpoint::ItApiBase

Instance Method Details

#create(invoice_xml) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/acube/endpoint/invoices.rb', line 4

def create(invoice_xml)
  response = connection.post do |req|
    req.url "/invoices"
    req.body = invoice_xml
  end

  if response.success?
    return JSON.parse(response.body)["uuid"]
  else
    raise "Invoice creation failed: #{response.body} -- #{response.inspect} "
  end
end

#download(uuid) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/acube/endpoint/invoices.rb', line 17

def download(uuid)
  response = connection.get do |req|
    req.url "/invoices/#{uuid}"
    req.headers['Content-Type'] = 'application/pdf'
    req.headers['X-PrintTheme'] = ACube.invoice_print_theme || 'standard'
  end

  if response.success?
    return StringIO.new(response.body)
  else
    raise "Invoice download failed: #{response.body} -- #{response.inspect}"
  end
end