Class: ActiveShipping::Correios::CorreiosRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shipping/carriers/correios.rb

Constant Summary collapse

URL =
"http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx"
RETURN_TYPE =
'xml'
RETURN_INFORMATION_TYPE =
{
  :prices => '1',
  :time => '2',
  :prices_and_time => '3'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, destination, packages, options) ⇒ CorreiosRequest

Returns a new instance of CorreiosRequest.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/active_shipping/carriers/correios.rb', line 64

def initialize(origin, destination, packages, options)
  @options = options
  @origin = origin
  @destination = destination

  packages = packages.map do |package|
    CorreiosPackage.new(package, 1)
  end

  @params = {
    company_id: options[:company_id],
    password: options[:password],
    service_type: service_type,
    origin_zip: origin.zip,
    destination_zip: destination.zip,
    mao_propria_extra: parse_boolean(options[:mao_propria_extra]),
    declared_value_extra: parse_currency(options[:declared_value_extra]),
    delivery_notice_extra: parse_boolean(options[:delivery_notice_extra]),
    return_type: RETURN_TYPE,
    return_information: RETURN_INFORMATION_TYPE[:prices]
  }
  @urls = packages.map { |package| create_url(package).to_s }
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



62
63
64
# File 'lib/active_shipping/carriers/correios.rb', line 62

def destination
  @destination
end

#originObject (readonly)

Returns the value of attribute origin.



62
63
64
# File 'lib/active_shipping/carriers/correios.rb', line 62

def origin
  @origin
end

#urlsObject (readonly)

Returns the value of attribute urls.



62
63
64
# File 'lib/active_shipping/carriers/correios.rb', line 62

def urls
  @urls
end

Instance Method Details

#create_response(raw_xmls) ⇒ Object



88
89
90
91
# File 'lib/active_shipping/carriers/correios.rb', line 88

def create_response(raw_xmls)
  correios_response = CorreiosResponse.new(self, raw_xmls)
  correios_response.rate_response
end