class PeanutLabs::Builder::Profile
Constants
- COUNTRY_CODES
Attributes
credentials[R]
Public Class Methods
new(params = nil)
click to toggle source
# File lib/peanut_labs/builder/profile.rb, line 18 def initialize(params = nil) @credentials = params[:credentials] || PeanutLabs::Credentials.new(params) end
Public Instance Methods
call(params)
click to toggle source
This class build a user profile and validates following parameters:
-
params - mandatory, will be later built to user_go_id
-
params - mandatory, will be validated for correctness
-
params - mandatory, all DateTime, Time, Date object will be formatted, already formatted string is accepted
-
params - mandatory, will attempt to interpret any common definitions of SEX
more info peanut-labs.github.io/publisher-doc/index.html#iv-payload
you can map more parameters, you can find mapping for additional fields here: docs.google.com/spreadsheets/d/1v-qYMKBUVGNTrG4BSL_hIYsg9v_eLMBfehETtAqg240/edit#gid=1572744670
# File lib/peanut_labs/builder/profile.rb, line 34 def call(params) raise PeanutLabs::UserIdMissingError if params[:user_id].nil? raise PeanutLabs::DateOfBirthMissingError if params[:dob].nil? raise PeanutLabs::SexMissingError if params[:sex].nil? raise PeanutLabs::CountryMissingError if params[:country].nil? { user_id: UserId.new(credentials: credentials).call(params[:user_id]), cc: country(params[:country]), dob: date_of_birth(params[:dob]), sex: sex(params[:sex]) }.to_json end
Private Instance Methods
country(value)
click to toggle source
# File lib/peanut_labs/builder/profile.rb, line 52 def country(value) if COUNTRY_CODES.include? value value else raise PeanutLabs::CountryMissingError.new("Wrong value provided #{value}") end end
date_of_birth(value)
click to toggle source
# File lib/peanut_labs/builder/profile.rb, line 68 def date_of_birth(value) if (dob = PeanutLabs::Parser::DateOfBirth.profile(value)) dob else raise PeanutLabs::DateOfBirthMissingError.new("Wrong value provided #{value}") end end
sex(value)
click to toggle source
# File lib/peanut_labs/builder/profile.rb, line 60 def sex(value) if (sex = PeanutLabs::Parser::Sex.call(value)) sex else raise PeanutLabs::SexMissingError.new("Wrong value provided #{value}") end end