Class: BcnNi::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/bcn_ni/helpers/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Request

Returns a new instance of Request.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bcn_ni/helpers/request.rb', line 33

def initialize(args = {})
  @request_mode = (args[:request_mode] || :scrapping).to_sym
  @exceptions   = []

  case @request_mode
  when :scrapping
    @request_url = "https://www.bcn.gob.ni/IRR/tipo_cambio_mensual/mes.php"
  when :soap
    # See 'https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx' for more info about how to build a RAW SOAP request
    @request_url = "https://servicios.bcn.gob.ni/Tc_Servicio/ServicioTC.asmx?WSDL"
  else
    raise NotImplementedError, 'Request mode not implemented'
  end
end

Instance Method Details

#exceptionsObject



29
30
31
# File 'lib/bcn_ni/helpers/request.rb', line 29

def exceptions
  return @exceptions
end

#exchange_day(year, month, day) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bcn_ni/helpers/request.rb', line 66

def exchange_day(year, month, day)
  begin
    # Evaluate scrapping mode to call the correct method for processing the request
    case request_mode
    when :scrapping
      return scra__exchange_day(year, month, day)
    when :soap
      return soap__exchange_day(year, month, day)
    end
  rescue Exception => e
    # Save the exception into the exception list for future error messages or debugging
    @exceptions.push e

    # Return an empty value according to the called method
    return nil
  end
end

#exchange_month(year, month) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bcn_ni/helpers/request.rb', line 48

def exchange_month(year, month)
  begin
    # Evaluate scrapping mode to call the correct method for processing the request
    case request_mode
    when :scrapping
      return scra__exchange_month(year, month)
    when :soap
      return soap__exchange_month(year, month)
    end
  rescue Exception => e
    # Save the exception into the exception list for future error messages or debugging
    @exceptions.push e

    # Return an empty value according to the called method
    return []
  end
end

#request_modeObject



25
26
27
# File 'lib/bcn_ni/helpers/request.rb', line 25

def request_mode
  return @request_mode
end

#request_urlObject



21
22
23
# File 'lib/bcn_ni/helpers/request.rb', line 21

def request_url
  return @request_url
end