Class: Endicia::RefundResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/endicia_ruby/refund_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ RefundResponse

An array with information about all requested tracking numbers Each entry is an OpenStruct with:

pic_number: '123456789',         # the tracking number you requested
approved:   true,                # or false
message:    "the message"        # message describing success or failure


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/endicia_ruby/refund_response.rb', line 18

def initialize(response)
  @success = true
  @tracking_numbers = []
  @raw_response = response.body

  @parsed_response = Nokogiri::XML(response.body)
  refund_response = @parsed_response.xpath('/RefundResponse')
  @form_number = refund_response.at('FormNumber').content

  refund_list = refund_response.at('RefundList')

  refund_list.xpath('//PICNumber').each do |refund_node|
    approved = refund_node.at('IsApproved').content.try(:strip).try(:upcase) == "YES"
    @tracking_numbers << OpenStruct.new(pic_number: refund_node.children.first.text.try(:strip),
                                        approved:   approved,
                                        message:    refund_node.at('ErrorMsg').content.try(:strip))
    @success = @success && approved
  end
end

Instance Attribute Details

#form_numberObject

Returns the value of attribute form_number.



7
8
9
# File 'lib/endicia_ruby/refund_response.rb', line 7

def form_number
  @form_number
end

#parsed_responseObject

Returns the value of attribute parsed_response.



7
8
9
# File 'lib/endicia_ruby/refund_response.rb', line 7

def parsed_response
  @parsed_response
end

#raw_responseObject

Returns the value of attribute raw_response.



7
8
9
# File 'lib/endicia_ruby/refund_response.rb', line 7

def raw_response
  @raw_response
end

#successObject

Returns the value of attribute success.



7
8
9
# File 'lib/endicia_ruby/refund_response.rb', line 7

def success
  @success
end

#tracking_numbersObject

Returns the value of attribute tracking_numbers.



7
8
9
# File 'lib/endicia_ruby/refund_response.rb', line 7

def tracking_numbers
  @tracking_numbers
end