Class: Viglink::Merchant
- Inherits:
-
Struct
- Object
- Struct
- Viglink::Merchant
- Defined in:
- lib/viglink/merchant.rb,
lib/viglink/merchant.rb
Constant Summary collapse
- SEARCH_PATH =
'/api/merchant/search'
Instance Attribute Summary collapse
-
#affiliate_cpa ⇒ Object
Returns the value of attribute affiliate_cpa.
-
#affiliate_cpc ⇒ Object
Returns the value of attribute affiliate_cpc.
-
#approved ⇒ Object
Returns the value of attribute approved.
-
#code ⇒ Object
Returns the value of attribute code.
-
#countries ⇒ Object
Returns the value of attribute countries.
-
#create_date ⇒ Object
Returns the value of attribute create_date.
-
#domains ⇒ Object
Returns the value of attribute domains.
-
#group_id ⇒ Object
Returns the value of attribute group_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#industry_types ⇒ Object
Returns the value of attribute industry_types.
-
#insider ⇒ Object
Returns the value of attribute insider.
-
#merchant_sensitive_types ⇒ Object
Returns the value of attribute merchant_sensitive_types.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rates ⇒ Object
Returns the value of attribute rates.
-
#update_date ⇒ Object
Returns the value of attribute update_date.
Class Method Summary collapse
- .build_from_json(klass, items) ⇒ Object
- .build_search_parameters(params) ⇒ Object
- .from_json(merchant = {}) ⇒ Object
- .json_map ⇒ Object
- .search(params = {}) ⇒ Object
Instance Attribute Details
#affiliate_cpa ⇒ Object
Returns the value of attribute affiliate_cpa
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def affiliate_cpa @affiliate_cpa end |
#affiliate_cpc ⇒ Object
Returns the value of attribute affiliate_cpc
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def affiliate_cpc @affiliate_cpc end |
#approved ⇒ Object
Returns the value of attribute approved
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def approved @approved end |
#code ⇒ Object
Returns the value of attribute code
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def code @code end |
#countries ⇒ Object
Returns the value of attribute countries
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def countries @countries end |
#create_date ⇒ Object
Returns the value of attribute create_date
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def create_date @create_date end |
#domains ⇒ Object
Returns the value of attribute domains
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def domains @domains end |
#group_id ⇒ Object
Returns the value of attribute group_id
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def group_id @group_id end |
#id ⇒ Object
Returns the value of attribute id
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def id @id end |
#industry_types ⇒ Object
Returns the value of attribute industry_types
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def industry_types @industry_types end |
#insider ⇒ Object
Returns the value of attribute insider
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def insider @insider end |
#merchant_sensitive_types ⇒ Object
Returns the value of attribute merchant_sensitive_types
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def merchant_sensitive_types @merchant_sensitive_types end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def name @name end |
#rates ⇒ Object
Returns the value of attribute rates
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def rates @rates end |
#update_date ⇒ Object
Returns the value of attribute update_date
4 5 6 |
# File 'lib/viglink/merchant.rb', line 4 def update_date @update_date end |
Class Method Details
.build_from_json(klass, items) ⇒ Object
38 39 40 41 42 43 |
# 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) ⇒ Object
45 46 47 48 49 50 51 |
# 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 = {}) ⇒ Object
27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |