Class: Boomerang::APICall
- Inherits:
-
Object
- Object
- Boomerang::APICall
- Defined in:
- lib/boomerang/api_call.rb
Constant Summary collapse
- CA_PATH =
File.join(File.dirname(__FILE__), *%w[.. .. data ca-bundle.crt])
Instance Method Summary collapse
-
#initialize(host, action, parameters) ⇒ APICall
constructor
A new instance of APICall.
- #response ⇒ Object
- #sign(access_key_id, secret_access_key) ⇒ Object
Constructor Details
#initialize(host, action, parameters) ⇒ APICall
Returns a new instance of APICall.
5 6 7 8 9 10 |
# File 'lib/boomerang/api_call.rb', line 5 def initialize(host, action, parameters) @host = host @parameters = Utilities.CamelCase(parameters) .merge( "Action" => Utilities.CamelCase(action), "Version" => "2008-09-17" ) end |
Instance Method Details
#response ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/boomerang/api_call.rb', line 18 def response url = "#{@host}/?#{Utilities.build_query(@parameters)}" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.ca_file = CA_PATH http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.verify_depth = 5 begin response = http.start { |session| get = Net::HTTP::Get.new("#{uri.path}?#{uri.query}") if (response = session.request(get)).is_a? Net::HTTPSuccess begin response.body rescue StandardError => error fail wrap_error( "HTTP", "#{error.} (#{error.class.name})", http_response: response, original_error: error ) end else fail wrap_error( "HTTP", "#{response.} (#{response.class.name})", http_response: response ) end } rescue Errors::HTTPError fail # pass through already wrapped errors rescue StandardError => error fail wrap_error( "Connection", "#{error.} (#{error.class.name})", original_error: error ) end end |