5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/usps/client.rb', line 5
def request(request, &block)
server = server(request)
options = { timeout: USPS.config.timeout,
params: { "API" => request.api, "XML" => request.build } }
unless USPS.config.proxy.blank?
options.merge!({ proxy: USPS.config.proxy })
end
response = Typhoeus::Request.get(server, options)
xml = Nokogiri::XML.parse(response.body)
if((error = xml.search('Error')).any?)
why = error.search('Description').text
code = error.search('Number').text
source = error.search('Source').text
raise Error.for_code(code).new(why, code, source)
end
request.response_for(xml)
end
|