|
@@ -48,6 +48,12 @@ module Ebaytr
|
|
|
"eBayAuthToken" => @@token
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ show_request_xml = 1 if hash[:show_request_xml].present?
|
|
|
+ show_response_xml = 1 if hash[:show_response_xml].present?
|
|
|
+ show_request_json = 1 if hash[:show_request_json].present?
|
|
|
+ show_response_json = 1 if hash[:show_response_json].present?
|
|
|
+ hash.except!(:show_request_xml, :show_response_xml, :show_request_json, :show_response_json)
|
|
|
|
|
|
main_hash = {
|
|
|
ErrorLanguage: "en_US",
|
|
@@ -84,20 +90,33 @@ module Ebaytr
|
|
|
puts "│ [#{@@site}][#{request_name}]#{main_str}"
|
|
|
puts "└---------------------------------------"
|
|
|
|
|
|
+ # 若有丟 show_request_xml 參數,就顯示 xml
|
|
|
+ puts req.body if show_request_xml.present?
|
|
|
+ # 若有丟 show_request_json 參數,就顯示 json
|
|
|
+ puts main_hash if show_request_json.present?
|
|
|
+
|
|
|
res = https.request(req)
|
|
|
|
|
|
# 特例 (attr 解析)
|
|
|
if request_name==:GetOrders
|
|
|
- #e.g. "USD\">151.96"
|
|
|
- tmp_str = res.body[res.body.index('<Subtotal currencyID').to_i+22..res.body.index('</Subtotal>').to_i-1]
|
|
|
- if tmp_str.present?
|
|
|
- #e.g. "USD"
|
|
|
- attr_currency = tmp_str.split('"').first
|
|
|
- res.body = res.body.insert(res.body.index('<Subtotal currencyID').to_i, "<SubtotalAttrCurrencyID>#{attr_currency}</SubtotalAttrCurrencyID>")
|
|
|
- end
|
|
|
+ if res.body.index('<Subtotal currencyID').present?
|
|
|
+ #e.g. "USD\">151.96"
|
|
|
+ tmp_str = res.body[res.body.index('<Subtotal currencyID').to_i+22..res.body.index('</Subtotal>').to_i-1]
|
|
|
+ if tmp_str.present?
|
|
|
+ #e.g. "USD"
|
|
|
+ attr_currency = tmp_str.split('"').first
|
|
|
+ res.body = res.body.insert(res.body.index('<Subtotal currencyID').to_i, "<SubtotalAttrCurrencyID>#{attr_currency}</SubtotalAttrCurrencyID>")
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
object_hash = Hash.from_xml(res.body)["#{request_name}Response"]
|
|
|
+
|
|
|
+ # 若有丟 show_response_xml 參數,就顯示 xml
|
|
|
+ puts res.body if show_response_xml.present?
|
|
|
+ # 若有丟 show_response_json 參數,就顯示 json
|
|
|
+ puts object_hash if show_response_json.present?
|
|
|
+
|
|
|
object_hash
|
|
|
end
|
|
|
|