Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Sb 14700 log xml #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ebay/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions lib/ebay/request/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down