Class: ANAF::WebServices::VatRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/anaf/web_services/vat_registry.rb

Overview

:nodoc:

Constant Summary collapse

BASE_URL =
'https://webservicesp.anaf.ro'
PATH =
'/PlatitorTvaRest/api/v8/ws/tva'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ids) ⇒ VatRegistry

Returns a new instance of VatRegistry.



13
14
15
# File 'lib/anaf/web_services/vat_registry.rb', line 13

def initialize(ids)
  @ids = ids
end

Instance Attribute Details

#idsObject (readonly)

Returns the value of attribute ids.



11
12
13
# File 'lib/anaf/web_services/vat_registry.rb', line 11

def ids
  @ids
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/anaf/web_services/vat_registry.rb', line 17

def call
  return [] if request_body.empty?

  response = conn.post(PATH, request_body)
  body = JSON.parse(response.body)

  return body['found'] if response.success? && body['cod'] == 200

  raise InvalidRequest, body['message']
rescue JSON::ParserError
  raise InvalidRequest, response.body
rescue Faraday::TimeoutError, Faraday::ConnectionFailed
  raise TimeoutError
end

#request_bodyObject



32
33
34
# File 'lib/anaf/web_services/vat_registry.rb', line 32

def request_body
  @request_body ||= ids.map { |id| { cui: id, data: date } }
end