Class: Xolphin::Api::Endpoint::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/xolphin/api/endpoint/invoice.rb

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Invoice

Returns a new instance of Invoice.



5
6
7
# File 'lib/xolphin/api/endpoint/invoice.rb', line 5

def initialize(http)
  @http = http
end

Instance Method Details

#allObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/xolphin/api/endpoint/invoice.rb', line 9

def all
  invoices = []

  result = @http.get("/invoices", page: 1)
  response = Xolphin::Api::Responses::Invoices.new(result)

  unless response.error?
    invoices = response.invoices
    while response.page < response.pages
      result = @http.get("/invoices", page: response.page + 1)
      response = Xolphin::Api::Responses::Invoices.new(result)
      break if response.error?

      invoices += response.invoices
    end
  end

  invoices
end

#download(id, type = "PDF") ⇒ Object



34
35
36
# File 'lib/xolphin/api/endpoint/invoice.rb', line 34

def download(id, type = "PDF")
  @http.download("/invoices/#{id}/download", type: type)
end

#get(id) ⇒ Object



29
30
31
32
# File 'lib/xolphin/api/endpoint/invoice.rb', line 29

def get(id)
  result = @http.get("/invoices/#{id}")
  Xolphin::Api::Responses::Invoice.new(result)
end