Class: YourMembership::Profile
- Inherits:
-
Object
- Object
- YourMembership::Profile
- 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
-
#custom_data ⇒ Hash
These are fields that are the ones added as Custom Fields to a YourMembership Community.
-
#data ⇒ Hash
These are fields that are part of the core YourMembership profile implementation.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Profile
constructor
A new instance of Profile.
-
#to_h ⇒ Hash
Returns the full contents of the profile in a Hash without items that have a Nil value.
Constructor Details
#initialize(options = {}) ⇒ Profile
Returns a new instance of Profile.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/your_membership/profile.rb', line 20 def initialize( = {}) @data = {} @custom_data = {} .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_data ⇒ Hash
These are fields that are the ones added as Custom Fields to a YourMembership Community
16 17 18 |
# File 'lib/your_membership/profile.rb', line 16 def custom_data @custom_data end |
#data ⇒ Hash
These are fields that are part of the core YourMembership profile implementation
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.
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, = {}) ['FirstName'] = first_name ['LastName'] = last_name ['MemberTypeCode'] = member_type_code ['EmailAddr'] = email ['Username'] = username ['Password'] = password new() end |
Instance Method Details
#to_h ⇒ Hash
Returns the full contents of the profile in a Hash without items that have a Nil value
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 |