Class: ShippingScale::Response

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Response

Returns a new instance of Response.



13
14
15
# File 'lib/shipping_scale/response.rb', line 13

def initialize(xml)
  @xml = xml
end

Instance Attribute Details

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/shipping_scale/response.rb', line 3

def raw
  @raw
end

#xmlObject (readonly)

Returns the value of attribute xml.



17
18
19
# File 'lib/shipping_scale/response.rb', line 17

def xml
  @xml
end

Class Method Details

.parse(xml) ⇒ Object



6
7
8
9
10
# File 'lib/shipping_scale/response.rb', line 6

def parse(xml)
  response = self.new(xml)
  response.raw = xml
  response
end

Instance Method Details

#detailsObject



19
20
21
22
23
24
25
26
27
# File 'lib/shipping_scale/response.rb', line 19

def details
  details = {}

  xml.search("Package").children.each do |node|
    details[node.name.snakecase.to_sym] = node.text
  end

  return details
end

#priceObject



29
30
31
# File 'lib/shipping_scale/response.rb', line 29

def price
  xml.search("Package").children.search("Postage").text.to_f
end