class YahooShoppingSearch::Clients::Base

Public Class Methods

response_class_name() click to toggle source
# File lib/yahoo_shopping_search/clients/base.rb, line 34
def response_class_name
  raise NotImplementedError
end
url() click to toggle source
# File lib/yahoo_shopping_search/clients/base.rb, line 38
def url
  raise NotImplementedError
end

Private Class Methods

base_params() click to toggle source
# File lib/yahoo_shopping_search/clients/base.rb, line 63
def base_params
  params = { appid: YahooShoppingSearch.config.app_id }
  params[:affiliate_id] = YahooShoppingSearch.config.affiliate_id if YahooShoppingSearch.config.affiliate_id&.present?
  params[:affiliate_type] = YahooShoppingSearch.config.affiliate_type if YahooShoppingSearch.config.affiliate_type&.present?

  params
end
error_message(res) click to toggle source
# File lib/yahoo_shopping_search/clients/base.rb, line 44
def error_message(res)
  if xml_response?(res)
    doc = REXML::Document.new(res.body)
    hash = Hash.from_xml(doc.to_s)
    return hash['Error']['Message']
  end

  json = JSON.parse(res.body)
  json['Error']['Message']
end
to_query(params) click to toggle source
# File lib/yahoo_shopping_search/clients/base.rb, line 59
def to_query(params)
  params.map { |k, v| "#{URI.encode(k)}=#{URI.encode(v)}" }.join('&')
end
xml_response?(res) click to toggle source
# File lib/yahoo_shopping_search/clients/base.rb, line 55
def xml_response?(res)
  res.header['content-type'].include?('text/xml')
end