Reputation: 5826
Im new to ruby and need to know how to easily display the specific variables in this returned response below.
Any help is greatly appreciated.
[#<Fedex::Rate:0x007fb9320ba7f0 @service_type="FEDEX_GROUND",
@rate_type="PAYOR_ACCOUNT_PACKAGE", @rate_zone="4", @total_billing_weight="6.0 LB",
@total_freight_discounts={:currency=>"USD", :amount=>"2.75"}, @total_net_charge="6.84",
@total_taxes="0.0", @total_net_freight="6.42", @total_surcharges="0.42",
@total_base_charge="9.17", @total_net_fedex_charge=nil, @total_rebates="0.0">]
Upvotes: 1
Views: 51
Reputation: 37517
According to the docs, you call it this way:
rate = fedex.rate(:shipper=>shipper,
:recipient => recipient,
:packages => packages,
:service_type => "FEDEX_GROUND",
:shipping_options => shipping_options)
and then any of the instance variables (the @
variables) can be retrieved via an accessor:
puts rate.total_net_charge
Upvotes: 1
Reputation: 2909
It looks like the response is an array with one object of type Fedex::Rate. As mentioned by others, you should read the docs to see what Fedex::Rate exposes as methods. To programatically see the methods Fedex::Rate exposes you could use:
rate = response.first
puts rate.methods
Alternatively if you want to read the variables from the object (which is probably a bad idea), you could use:
rate.instance_variable_get('@total_freight_discounts')
Upvotes: 1