Class: EInvoice::Header

Inherits:
Invoice show all
Defined in:
lib/e_invoice/header.rb

Instance Attribute Summary

Attributes inherited from Invoice

#response_body

Instance Method Summary collapse

Methods inherited from Invoice

#basic_params, #response_code

Constructor Details

#initialize(payload, start_date, end_date) ⇒ Header

Returns a new instance of Header.



5
6
7
8
9
10
# File 'lib/e_invoice/header.rb', line 5

def initialize(payload, start_date, end_date)
  super(payload)
  @start_date = start_date
  @end_date = end_date
  start_and_end_at_the_same_month
end

Instance Method Details

#detailsObject



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

def details
  @response_body["details"]
end

#requestObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/e_invoice/header.rb', line 12

def request
  params = basic_params
  params[:action] = EInvoice::HEADER_ACTION
  params[:onlyWinningInv] = EInvoice::ONLY_WINNING_INV
  params[:startDate] = @start_date.tr("-", "/")
  params[:endDate] = @end_date.tr("-", "/")
  response = HTTPClient.new.post(EInvoice::URL + EInvoice::HEADER_PATH, params)
  @response_body = JSON.parse(response.body)
  self
end

#start_and_end_at_the_same_monthObject



27
28
29
30
31
# File 'lib/e_invoice/header.rb', line 27

def start_and_end_at_the_same_month
  if DateTime.parse(@start_date).month != DateTime.parse(@end_date).month
    raise "Start_date & end_date must be the same month."
  end
end