Class: FourTell::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/four_tell/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_alias) ⇒ Request

Returns a new instance of Request.

Parameters:

  • client_alias (String)

    Your 4-Tell account name



6
7
8
9
10
11
# File 'lib/four_tell/request.rb', line 6

def initialize(client_alias)
  @client_alias = client_alias
  @format       = 'json'
  @num_results  = 20
  @result_type  = :cross_sell
end

Instance Attribute Details

#cart_product_ids=(value) ⇒ Object

List of product IDs in the customer’s cart

Parameters:

  • (Array)


48
49
50
# File 'lib/four_tell/request.rb', line 48

def cart_product_ids=(value)
  @cart_product_ids = value
end

#click_stream_product_ids=(value) ⇒ Object

Ordered list of most recently visited to least recently visited product IDs. Only 5 unique product IDs will be included.

Parameters:

  • (Array)


43
44
45
# File 'lib/four_tell/request.rb', line 43

def click_stream_product_ids=(value)
  @click_stream_product_ids = value
end

#customer_id=(value) ⇒ Object

REQUIRED: The customer_id sent to 4-Tell. This should correspond to the customer ID sent via data exports.

Parameters:

  • (Fixnum)


17
18
19
# File 'lib/four_tell/request.rb', line 17

def customer_id=(value)
  @customer_id = value
end

#num_results=(value) ⇒ Object

The number of desired results between 1-20 (20 is the max limit in the 4-Tell API)

Parameters:

  • (Fixnum)


32
33
34
# File 'lib/four_tell/request.rb', line 32

def num_results=(value)
  @num_results = value
end

#page_type=(value) ⇒ Object

Help 4-Tell provide the right kind of recommendations for the page

Can be one of:

- Hm
- Pdp1
- Pdp2
- Cat
- Srch
- Cart
- Chkout
- Bought
- Admin
- Other

Parameters:

  • (Symbol)


65
66
67
# File 'lib/four_tell/request.rb', line 65

def page_type=(value)
  @page_type = value
end

#product_id=(value) ⇒ Object

The product ID of the primary item on the page

Parameters:

  • (Fixnum)


37
38
39
# File 'lib/four_tell/request.rb', line 37

def product_id=(value)
  @product_id = value
end

#result_type=(value) ⇒ Object

The result type to return

  • cross-sell: recommending something based on a customer’s likes

  • personal: based upon purchase history

  • similar: just bought a shirt, here’s another

Parameters:

  • (Symbol)


26
27
28
# File 'lib/four_tell/request.rb', line 26

def result_type=(value)
  @result_type = value
end

Instance Method Details

#paramsHash

Parameters for the 4-Tell call. Empty parameters are omitted.

Returns:

  • (Hash)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/four_tell/request.rb', line 70

def params
  {}.tap { |h|
    h['clientAlias']    = client_alias
    h['format']         = format
    h['customerID']     = customer_id
    h['numResults']     = num_results
    h['resultType']     = result_type
    h['productIDs']     = product_id
    h['clickStreamIDs'] = click_stream_product_ids
    h['cartIDs']        = cart_product_ids
    h['pageType']       = page_type
  }.reduce({}) do |h, (k, v)|
    h[k] = v if v
    h
  end
end

#urlObject



87
88
89
90
91
# File 'lib/four_tell/request.rb', line 87

def url
  u = URI('https://live.4-tell.net/Boost2.0/rest/GetRecIDs/array')
  u.query = URI.encode_www_form(params)
  u.to_s
end