Class: ShippingScale::Client
- Inherits:
-
Object
- Object
- ShippingScale::Client
- Defined in:
- lib/shipping_scale/client.rb
Instance Method Summary collapse
Instance Method Details
#request(request) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/shipping_scale/client.rb', line 3 def request(request) server = "http://production.shippingapis.com/ShippingAPI.dll" response = Typhoeus::Request.get(server, { timeout: ShippingScale.config.timeout, params: { "API" => request.api, "XML" => request.build.body.clean_xml } }) xml = Nokogiri::XML.parse(response.body) if ((error = xml.search('Error')).any?) why = error.search("Description").children.first code = error.search("Number").children.first.to_s source = error.search("Source").children.first raise ShippingScale::Error.for_code(code).new(why, code, source) end ShippingScale::Response.parse(xml) end |
#server(request) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/shipping_scale/client.rb', line 30 def server(request) case when request.secure? "https://secure.shippingapis.com/ShippingAPI.dll" when testing? "http://testing.shippingapis.com/ShippingAPI.dll" else "http://production.shippingapis.com/ShippingAPI.dll" end end |
#testing? ⇒ Boolean
26 27 28 |
# File 'lib/shipping_scale/client.rb', line 26 def testing? ShippingScale.config.testing? end |