Class: InvoiceCount::Invoice

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

Class Method Summary collapse

Class Method Details

.count(id, starting_date, ending_date) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/invoice_count/invoice.rb', line 3

def self.count(id, starting_date, ending_date)
  response = InvoiceCount::Connection.instance.get do |request|
    request.url('/facturas')

    request.params['id']     = id
    request.params['start']  = starting_date
    request.params['finish'] = ending_date
  end

  # server responds with an ASCII-8BIT string
  body = response.body.force_encoding('utf-8').encode

  case body
  when /Hay más de 100 resultados/
    raise InvoiceCount::Error::TooManyResults
  when /Te faltan parámetros/
    raise InvoiceCount::Error::BadRequest
  end

  body.to_i
end