diff --git a/lib/ebay/api.rb b/lib/ebay/api.rb index cd77aeff..8a3f588d 100644 --- a/lib/ebay/api.rb +++ b/lib/ebay/api.rb @@ -50,7 +50,7 @@ class << self alias_method :ru_name=, :runame= end - attr_reader :auth_token, :site_id, :using_oauth2, :keyset + attr_reader :auth_token, :site_id, :using_oauth2, :keyset, :http_options self.sandbox_url = 'https://api.sandbox.ebay.com/ws/api.dll' self.production_url = 'https://api.ebay.com/ws/api.dll' @@ -126,6 +126,7 @@ def initialize(options = {}) @site_id = options[:site_id] || self.class.site_id @using_oauth2 = options[:using_oauth2] || false @keyset = options[:keyset] || {} + @http_options = options[:http_options] || {} end # Returns the URL used to sign-in to eBay to fetch a user token @@ -184,7 +185,7 @@ def build_body(request) end def connection(refresh = false) - @connection = Connection.new(service_uri) if refresh || @connection.nil? + @connection = Connection.new(service_uri, http_options) if refresh || @connection.nil? @connection end @@ -204,6 +205,7 @@ def parse(content, format) case format when :object xml = REXML::Document.new(content) + # Fixes the wrong case of API returned by eBay fix_root_element_name(xml) result = XML::Mapping.load_object_from_xml(xml.root) @@ -217,6 +219,8 @@ def parse(content, format) raise ArgumentError, "Unknown response format '#{format}' requested" end result + rescue REXML::ParseException => e + raise RequestError.new(e.message) end def fix_root_element_name(xml) diff --git a/lib/ebay/request/connection.rb b/lib/ebay/request/connection.rb index 28af49d7..d3117874 100644 --- a/lib/ebay/request/connection.rb +++ b/lib/ebay/request/connection.rb @@ -27,8 +27,11 @@ class ResourceNotFound < ClientError #:nodoc: end class Connection #:nodoc: - def initialize(site) + attr_reader :http_options + + def initialize(site, http_options = {}) @site = site + @http_options = http_options end def post(path, body, headers) @@ -54,9 +57,14 @@ def request(method, *arguments) end def http - http = Net::HTTP.new(@site.host, @site.port) - http.use_ssl = @site.is_a?(URI::HTTPS) - http.verify_mode = OpenSSL::SSL::VERIFY_NONE #if http.use_ssl? + http = Net::HTTP.new(@site.host, @site.port) + http.use_ssl = @site.is_a?(URI::HTTPS) + http.verify_mode = OpenSSL::SSL::VERIFY_NONE #if http.use_ssl? + if http_options.present? + http_options.each do |key, value| + http.send("#{key}=", value) if http.respond_to?(key) + end + end http end end