Class: ShippingScale::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/shipping_scale/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Package

Returns a new instance of Package.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/shipping_scale/package.rb', line 3

def initialize(**options)
  @weight = options[:weight]
  @pounds = options[:pounds]
  @ounces = options[:ounces]
  @length = options[:length]
  @width = options[:width]
  @height = options[:height]
  @zip_origin = (options[:zip_origin]) ? options[:zip_origin] : ShippingScale.config.zip_origin 
  @zip_destination = (options[:zip_destination]) ? options[:zip_destination] : ShippingScale.config.zip_destination

  @attrs = options
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



16
17
18
# File 'lib/shipping_scale/package.rb', line 16

def response
  @response
end

Instance Method Details

#build_xml(package) ⇒ Object



18
19
20
21
22
23
# File 'lib/shipping_scale/package.rb', line 18

def build_xml(package) 
  package.tag!("Service", "All")
  package.tag!("Container", "VARAIBLE")
  package.tag!("Size", "REGULAR")
  @attrs.each { |k, v| package.tag!(k.to_s, v) }
end

#detailsObject



34
35
36
# File 'lib/shipping_scale/package.rb', line 34

def details
  response.details
end

#get_price!(options = {}) ⇒ Object



25
26
27
28
# File 'lib/shipping_scale/package.rb', line 25

def get_price!(options = {})
  ShippingScale::Request.config(options)
  @response = ShippingScale::Request.new(packages: [self]).send!     
end

#priceObject



30
31
32
# File 'lib/shipping_scale/package.rb', line 30

def price 
  response.price
end