Class: ShipitAPI::Quotation
- Inherits:
-
Object
- Object
- ShipitAPI::Quotation
- Defined in:
- lib/shipit_api/quotation.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build! ⇒ Object
- #get_commune ⇒ Object
- #get_prices ⇒ Object
-
#initialize(opts = {}) ⇒ Quotation
constructor
A new instance of Quotation.
- #quotaiton_attrs ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Quotation
Returns a new instance of Quotation.
7 8 9 10 11 |
# File 'lib/shipit_api/quotation.rb', line 7 def initialize(opts = {}) @opts = opts @api_call = ShipitAPI::Session.connection('prices', 3) build! end |
Class Method Details
.get_prices(opts = {}) ⇒ Object
3 4 5 |
# File 'lib/shipit_api/quotation.rb', line 3 def self.get_prices(opts = {}) new(opts).get_prices end |
Instance Method Details
#build! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/shipit_api/quotation.rb', line 32 def build! @opts.each do |k,v| singleton_class.send(:attr_accessor, k) instance_variable_set("@#{k}", v) end end |
#get_commune ⇒ Object
24 25 26 |
# File 'lib/shipit_api/quotation.rb', line 24 def get_commune ShipitAPI::Commune.find_by_name({ name: @opts[:commune_name] }) end |
#get_prices ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/shipit_api/quotation.rb', line 13 def get_prices if !@opts[:commune_name].nil? commune = get_commune @opts.merge!({ to_commune_id: commune[:id]}) end package = { package: @opts } response = @api_call.post('', package.to_json) JSON.parse(response.body, symbolize_names: true) end |
#quotaiton_attrs ⇒ Object
28 29 30 |
# File 'lib/shipit_api/quotation.rb', line 28 def quotaiton_attrs { width: 10, length: 10, height: 10, weight: 1, destinty: 'Domicilio' } end |