module Taobao
Constants
- API_VERSION
- PRODUCTION_URL
- VERSION
Attributes
private_key[W]
public_key[RW]
Public Class Methods
api_request(options)
click to toggle source
Performs API calls to Taobao
@param options [Hash] @return [Hash] API request result
# File lib/taobao/base.rb, line 20 def self.api_request(options) uri = URI(PRODUCTION_URL) response = Net::HTTP.post_form uri, self.append_required_options(options) parse_to_hash response end
search(query)
click to toggle source
Search products by name @param query [String] @return [Taobao::ProductList] list of found products
# File lib/taobao/search.rb, line 5 def self.search(query) ProductList.new(q: query) end
Private Class Methods
append_required_options(options)
click to toggle source
# File lib/taobao/base.rb, line 35 def self.append_required_options(options) options.merge!({ app_key: @public_key, format: :xml, v: API_VERSION, timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S'), sign_method: :md5 }) options[:sign] = self.create_signature(options) options end
create_signature(options)
click to toggle source
# File lib/taobao/base.rb, line 27 def self.create_signature(options) values_str = options.sort.inject('') do |str, item| str + item.first.to_s + item.last.to_s end str = @private_key.to_s + values_str + @private_key.to_s Digest::MD5.hexdigest(str).upcase end
parse_to_hash(response)
click to toggle source
# File lib/taobao/base.rb, line 47 def self.parse_to_hash(response) result = Nokogiri::XML(response.body).to_symbolized_hash raise Taobao::ApiError.new(result) if result.key? :error_response result end