Class: YourMembership::Profile

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

Overview

The Profile object provides a convenient abstraction that encapsulates a person’s profile allowing clear and concise access to both the core fields provided by YourMembership and the custom fields added by site administrators

A new profile for a new person should be instantiated through the create_new method

A profile can be loaded by passing a hash directly to the initializer (Profile.new) method this can be useful in creating a profile object from an API response

A profile can be created empty or by passing a hash for standard and/or custom fields. This is useful for updating an existing profile without changing unnecessary records.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Profile

Returns a new instance of Profile.

Parameters:

  • options (Hash) (defaults to: {})

    Initial Values for the profile.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/your_membership/profile.rb', line 20

def initialize(options = {})
  @data = {}
  @custom_data = {}

  options.each do |k, v|
    if k == 'CustomFieldResponses'
      @custom_data = parse_custom_field_responses(v)
    else
      @data[k] = v
    end
  end
end

Instance Attribute Details

#custom_dataHash

These are fields that are the ones added as Custom Fields to a YourMembership Community

Returns:

  • (Hash)

    the current value of custom_data



16
17
18
# File 'lib/your_membership/profile.rb', line 16

def custom_data
  @custom_data
end

#dataHash

These are fields that are part of the core YourMembership profile implementation

Returns:

  • (Hash)

    the current value of data



16
17
18
# File 'lib/your_membership/profile.rb', line 16

def data
  @data
end

Class Method Details

.create_new(first_name, last_name, member_type_code, email, username, password, options = {}) ⇒ YourMembership::Profile

@note: It has been found that for some users you must also specify a ‘Membership’ field as well as the

'MemberTypeCode' The official documentation does not say this field is required but many times the user
cannot log in if no membership is provided. This means that the system cannot masquerade as this user until a
membership is specified.

Parameters:

  • last_name (String)
  • member_type_code (String)
  • email (String)
  • username (String)
  • password (String)
  • options (Hash) (defaults to: {})

Returns:



53
54
55
56
57
58
59
60
61
# File 'lib/your_membership/profile.rb', line 53

def self.create_new(first_name, last_name, member_type_code, email, username, password, options = {})
  options['FirstName'] = first_name
  options['LastName'] = last_name
  options['MemberTypeCode'] = member_type_code
  options['EmailAddr'] = email
  options['Username'] = username
  options['Password'] = password
  new(options)
end

Instance Method Details

#to_hHash

Returns the full contents of the profile in a Hash without items that have a Nil value

Returns:

  • (Hash)


35
36
37
38
39
40
# File 'lib/your_membership/profile.rb', line 35

def to_h
  temp_data = clean @data
  temp_custom_data = clean @custom_data
  temp_data['CustomFieldResponses'] = temp_custom_data
  temp_data
end