Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LabelRequestResponse Params & VoidLabelResponse #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/endicia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,11 @@ def self.refund_request(tracking_number, options = {})
response[:form_number] = result['FormNumber']

result = result['RefundList']['PICNumber']
response[:success] = (result.match(/<IsApproved>YES<\/IsApproved>/) ? true : false)
response[:error_message] = result.match(/<ErrorMsg>(.+)<\/ErrorMsg>/)[1]
# match against the raw response because httpparty seems to be chucking
# the invalid xml w/in PICNumber
raw_response = response[:response_body]
response[:success] = (raw_response.match(/<IsApproved>YES<\/IsApproved>/) ? true : false)
response[:error_message] = raw_response.match(/<ErrorMsg>(.+)<\/ErrorMsg>/)[1]
end
end

Expand Down
25 changes: 15 additions & 10 deletions lib/endicia/label.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
module Endicia
class Label
attr_accessor :image,
:status,
:tracking_number,
:final_postage,
:transaction_date_time,
:transaction_id,
:postmark_date,
:postage_balance,
attr_accessor :image,
:status,
:tracking_number,
:final_postage,
:transaction_date_time,
:transaction_id,
:postmark_date,
:postage_balance,
:pic,
:error_message,
:reference_id,
:reference_id2,
:reference_id3,
:reference_id4,
:requester_id,
:cost_center,
:request_body,
:request_url,
Expand All @@ -20,10 +24,11 @@ def initialize(result)
data = result["LabelRequestResponse"] || {}
data.each do |k, v|
k = "image" if k == 'Base64LabelImage'
send(:"#{k.tableize.singularize}=", v) if !k['xmlns']
setter = :"#{k.tableize.singularize}="
send(setter, v) if !k['xmlns'] && respond_to?(setter)
end
end

private
def filter_response_body(string)
# Strip image data for readability:
Expand Down
7 changes: 6 additions & 1 deletion test/test_endicia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class TestEndicia < Test::Unit::TestCase
setup do
# See https://app.sgizmo.com/users/4508/Endicia_Label_Server.pdf
# Table 3-2: LabelRequestResponse XML Elements
# (Note: linked PDF is out of date and does not reflect the newest API)
@response = fake_response({
"LabelRequestResponse" => {
"Status" => 123,
Expand All @@ -184,7 +185,11 @@ class TestEndicia < Test::Unit::TestCase
"CostCenter" => 12345,
"ReferenceID" => "abcde12345",
"PostmarkDate" => "20110102",
"PostageBalance" => 3.4
"PostageBalance" => 3.4,
"RequesterID" => "abcd",
"ReferenceID2" => "ref2",
"ReferenceID3" => "ref3",
"ReferenceID4" => "ref4"
}
})
end
Expand Down