Class: PeanutLabs::Builder::Profile

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

Constant Summary collapse

COUNTRY_CODES =
%w(
  AF AX AL DZ AS AD AO AI AQ AG AR AM AW AU AT AZ BS BH BD BB BY BE BZ BJ BM BT BO BA BW BV BR VG KH CM CA CV KY
  CF TD CL CN HK MO CX CC CO KM CG CD CK CR CI HR CU CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FK FO BN BG BF BI IO
  FJ FI FR GF PF TF GA GM GE DE GH GI GR GL GD GP GU GT GG GN GW GY HT HM VA HN HU IS IN ID IR IQ IE IM IL IT JM
  JP JE JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MK MG MW MY MV ML MT MH MQ MR MU YT MX FM MD MC MN ME
  MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG NU NF MP NO OM PK PW PS PA PG PY PE PH PN PL PT PR QA RE RO RU RW BL
  SH KN LC MF PM VC WS SM ST SA SN RS SC SL SG SK SI SB SO ZA GS SS ES LK SD SR SJ SZ SE CH SY TW TJ TZ TH TL TG
  TK TO TT TN TR TM TC TV UG UA AE GB US UM UY UZ VU VE VN VI WF EH YE ZM ZW
).freeze

Instance Method Summary collapse

Constructor Details

#initialize(params = nil) ⇒ Profile

Returns a new instance of Profile.



18
19
20
# File 'lib/peanut_labs/builder/profile.rb', line 18

def initialize(params = nil)
  @credentials = params[:credentials] || PeanutLabs::Credentials.new(params)
end

Instance Method Details

#call(params) ⇒ Object

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



34
35
36
37
38
39
40
41
42
43
44
45
46
# 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