Class: Viglink::Merchant

Inherits:
Struct
  • Object
show all
Defined in:
lib/viglink/merchant.rb,
lib/viglink/merchant.rb

Constant Summary collapse

SEARCH_PATH =
'/api/merchant/search'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#affiliate_cpaObject

Returns the value of attribute affiliate_cpa

Returns:

  • (Object)

    the current value of affiliate_cpa



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def affiliate_cpa
  @affiliate_cpa
end

#affiliate_cpcObject

Returns the value of attribute affiliate_cpc

Returns:

  • (Object)

    the current value of affiliate_cpc



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def affiliate_cpc
  @affiliate_cpc
end

#approvedObject

Returns the value of attribute approved

Returns:

  • (Object)

    the current value of approved



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def approved
  @approved
end

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def code
  @code
end

#countriesObject

Returns the value of attribute countries

Returns:

  • (Object)

    the current value of countries



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def countries
  @countries
end

#create_dateObject

Returns the value of attribute create_date

Returns:

  • (Object)

    the current value of create_date



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def create_date
  @create_date
end

#domainsObject

Returns the value of attribute domains

Returns:

  • (Object)

    the current value of domains



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def domains
  @domains
end

#group_idObject

Returns the value of attribute group_id

Returns:

  • (Object)

    the current value of group_id



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def group_id
  @group_id
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def id
  @id
end

#industry_typesObject

Returns the value of attribute industry_types

Returns:

  • (Object)

    the current value of industry_types



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def industry_types
  @industry_types
end

#insiderObject

Returns the value of attribute insider

Returns:

  • (Object)

    the current value of insider



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def insider
  @insider
end

#merchant_sensitive_typesObject

Returns the value of attribute merchant_sensitive_types

Returns:

  • (Object)

    the current value of merchant_sensitive_types



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def merchant_sensitive_types
  @merchant_sensitive_types
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def name
  @name
end

#ratesObject

Returns the value of attribute rates

Returns:

  • (Object)

    the current value of rates



4
5
6
# File 'lib/viglink/merchant.rb', line 4

def rates
  @rates
end

#update_dateObject

Returns the value of attribute update_date

Returns:

  • (Object)

    the current value of 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_mapObject



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