Class: Rack::TradeTracker::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/trade_tracker/parameters.rb,
lib/rack/trade_tracker/parameters/paired.rb,
lib/rack/trade_tracker/parameters/delimited.rb

Defined Under Namespace

Modules: Delimited, Paired

Constant Summary collapse

CAMPAIGN_ID_PARAM =
'campaignID'.freeze
TT_PARAM =
'tt'.freeze
MISSING_PARAM_VALUE =
''.freeze
PERMITTED_PARAMS =
%w(campaignID materialID affiliateID reference).freeze
MissingParametersError =
Class.new(RuntimeError)

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Parameters

Returns a new instance of Parameters.



17
18
19
20
21
22
23
24
25
26
# File 'lib/rack/trade_tracker/parameters.rb', line 17

def initialize(params)
  @params = params
  if params.include?(CAMPAIGN_ID_PARAM)
    extend Paired
  elsif params.include?(TT_PARAM)
    extend Delimited
  else
    fail MissingParametersError.new("URL must include either '#{CAMPAIGN_ID_PARAM}' or '#{TT_PARAM}' parameter")
  end
end

Instance Method Details

#to_hashObject



28
29
30
31
32
33
# File 'lib/rack/trade_tracker/parameters.rb', line 28

def to_hash
  PERMITTED_PARAMS.each_with_object({}) do |param, result|
    key = param.underscore.to_sym
    result[key] = send(key)
  end.merge(redirect_url: redirect_url)
end