require "ebaytr/version" # require 'yaml' require "net/http" require "uri" module Ebaytr # CONFIG_FILE_PATH = %w(ebay_client.yml) # yml = YAML.load_file(Rails.root.join(*CONFIG_FILE_PATH)) # yml = YAML::load(IO.read(path_to_yaml_file)) mattr_accessor :token, :url, :api, :site, :app_name @@token = ''#yml[Rails.env]["token"] @@app_name = ''#yml[Rails.env]["appid"] @@url = "https://api.sandbox.ebay.com/ws/api.dll" @@api = "967" @@site = "0" def self.trading(request_name,hash = {}) url = URI.parse(@@url) https = Net::HTTP.new(url.host,url.port) https.use_ssl = true req = Net::HTTP::Post.new(url.path) req.add_field("X-EBAY-API-SITEID", @@site) req.add_field("X-EBAY-API-COMPATIBILITY-LEVEL", @@api) req.add_field("X-EBAY-API-CALL-NAME", request_name) main_hash = { RequesterCredentials: { eBayAuthToken: @@token }, ErrorLanguage: "en_US", WarningLevel: "High" }.merge(hash) # body = main_hash.to_xml(root: 'ReplaceRoot', skip_instruct: true).gsub('','').gsub('','') body = Gyoku.xml(main_hash, { key_converter: :camelcase }) req.body = <<-XML <#{request_name}Request xmlns="urn:ebay:apis:eBLBaseComponents"> #{body} XML req.body = req.body.gsub("'","'") puts req.body res = https.request(req) object_hash = Hash.from_xml(res.body)["#{request_name}Response"] object_hash end def self.finding(request_name,hash = {}) api_url = "http://svcs.ebay.com/services/search/FindingService/v1" url = URI.parse(api_url) https = Net::HTTP.new(url.host,url.port) # https.use_ssl = true req = Net::HTTP::Post.new(url.path) req.add_field("X-EBAY-SOA-SECURITY-APPNAME", @@app_name) req.add_field("X-EBAY-SOA-OPERATION-NAME", request_name) body = Gyoku.xml(hash) req.body = <<-XML <#{request_name}Request xmlns="http://www.ebay.com/marketplace/search/v1/services"> #{body} XML req.body = req.body.gsub("'","'") puts req.body res = https.request(req) object_hash = Hash.from_xml(res.body)["#{request_name}Response"] object_hash end end