class Viglink::Merchant
Constants
- SEARCH_PATH
Public Class Methods
build_from_json(klass, items)
click to toggle source
# File lib/viglink/merchant.rb, line 38 def self.build_from_json(klass, items) return [] unless items.is_a? Array items.map do |industry_type| klass.from_json(industry_type) end end
build_search_parameters(params)
click to toggle source
# File lib/viglink/merchant.rb, line 45 def self.build_search_parameters(params) params[:page] ||= 1 { keyword: params[:keyword], cartegory: params[:cartegory], updatedDate: params[:updated_date], createDate: params[:create_date], insider: params[:insider], domain: params[:domain], page: params[:page] } end
from_json(merchant = {})
click to toggle source
# File lib/viglink/merchant.rb, line 27 def self.from_json(merchant = {}) merchant['rates'] = build_from_json(Viglink::Rate, merchant['rates']) merchant['industryTypes'] = build_from_json(Viglink::IndustryType, merchant['industryTypes']) merchant['countries'] = merchant['countries'].split(',').map(&:upcase) new json_map.each_with_object({}) { |(k, v), h| h[k] = merchant[v]; } end
json_map()
click to toggle source
# File lib/viglink/merchant.rb, line 53 def self.json_map { id: 'id', code: 'code', group_id: 'groupId', name: 'name', update_date: 'updateDate', create_date: 'createDate', insider: 'insider', industry_types: 'industryTypes', affiliate_cpa: 'affiliateCPA', affiliate_cpc: 'affiliateCPC', approved: 'approved', domains: 'domains', countries: 'countries', rates: 'rates', merchant_sensitive_types: 'merchantSensitiveTypes' } end
search(params = {})
click to toggle source
# File lib/viglink/merchant.rb, line 13 def self.search(params = {}) response = HTTPClient.get path: SEARCH_PATH, query: build_search_parameters(params) merchants = response.parsed_response['merchants'].map do |merchant| next if merchant.nil? Merchant.from_json(merchant) end MerchantResults.new total_pages: response.parsed_response['totalPages'], page: response.parsed_response['page'], merchants: merchants end