Class: Blinksale::Invoices

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ Invoices

Returns a new instance of Invoices.



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

def initialize(service)
  @service = service
end

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



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

def service
  @service
end

Instance Method Details

#all(params = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/invoices.rb', line 27

def all(params = {})
  headers = {
    :content_type => "application/vnd.blinksale+xml",
    :accept => "application/vnd.blinksale+xml"
  }
  xml = service.rest_resource["invoices"].get(
    :params => params,
    :headers => headers
  )
  doc = Nokogiri::XML(xml)
  doc.xpath('//xmlns:invoice').map do |node|
    Invoice.from_node(node)
  end
end

#get(id, params = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/invoices.rb', line 42

def get(id, params = {})
  headers = {
    :content_type => "application/vnd.blinksale+xml",
    :accept => "application/vnd.blinksale+xml"
  }
  xml = service.rest_resource["invoices/#{ id }"].get(
    :params => params,
    :headers => headers
  )
  doc = Nokogiri::XML(xml)
  Invoice.from_node(doc.xpath('//xmlns:invoice').first)
end