Exception: Correios::Pricefier::CalculatePriceWithDate

Inherits:
CorreiosException show all
Defined in:
lib/pricefier/requests/calculate_price_with_date.rb

Constant Summary collapse

HELPER =
Helper.new
CLIENT =
Client.new

Instance Method Summary collapse

Methods inherited from CorreiosException

#format_error_message, #generate_exception

Constructor Details

#initialize(data = {}) ⇒ CalculatePriceWithDate

Returns a new instance of CalculatePriceWithDate.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pricefier/requests/calculate_price_with_date.rb', line 14

def initialize(data = {})
  @credentials = Correios.credentials

  @show_request = data[:show_request]
  @service_codes = data[:service_codes]
  @source_zip_code = data[:source_zip_code]
  @target_zip_code = data[:target_zip_code]
  @object = data[:object]
  @own_hands = data[:own_hands]
  @receipt_notification = data[:receipt_notification]
  @declared_value = data[:declared_value]
  @reference_date = data[:reference_date]
  super()
end

Instance Method Details

#requestObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pricefier/requests/calculate_price_with_date.rb', line 29

def request
  puts xml if @show_request == true
  begin
    format_response(CLIENT.client.call(:calc_preco_data,
                                       soap_action: 'http://tempuri.org/CalcPrecoData',
                                       xml: xml).to_hash)
  rescue Savon::SOAPFault => error
    generate_exception(error)
  rescue Savon::HTTPError => error
    if error.http.code == 401
      generate_exception("Unauthorized (#{error.http.code}).")
    end
    generate_exception("Unknown HTTP error (#{error.http.code}).")
  end
end