Class: PeanutLabs::Builder::IframeUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/peanut_labs/builder/iframe_url.rb

Constant Summary collapse

ENDPOINT =
'https://www.peanutlabs.com/userGreeting.php'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(params = nil) ⇒ IframeUrl

Returns a new instance of IframeUrl.



11
12
13
# File 'lib/peanut_labs/builder/iframe_url.rb', line 11

def initialize(params=nil)
  @credentials = Credentials.new(params)
end

Instance Method Details

#call(params) ⇒ Object

Documentation here: peanut-labs.github.io/publisher-doc/index.html#iframe-optionalpara

Accepts these parameters
params[:id] -> required, specially encoded from peanut labs user_id
params[:dob] -> not required, classes accepted - Date, DateTime, Time or formatted "MM-DD-YYYY" string
params[:sex] -> not required, 1 for male, 2 for female


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/peanut_labs/builder/iframe_url.rb', line 23

def call(params)
  raise PeanutLabs::UserIdMissingError if params[:id].nil? || params[:id].empty?

  result = "#{ENDPOINT}?userId=#{UserId.new(credentials: credentials).call(params[:id])}"

  if (sex = PeanutLabs::Parser::Sex.call(params[:sex]))
    result << "&sex=#{sex}"
  end

  if (dob = PeanutLabs::Parser::DateOfBirth.iframe(params[:dob]))
    result << "&dob=#{dob}"
  end

  result
end