Class: YourMembership::Member

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

Overview

The member object provides a convenient abstraction that encapsulates the member methods and caches some basic details about the member.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

build_XML_request, new_call_id, post, response_to_array, response_to_array_of_hashes, response_valid?, response_ym_error?

Constructor Details

#initialize(id, website_id, first_name, last_name, email, session = nil) ⇒ Member

Note:

There is not yet a compelling reason to call Member.new() directly, however it can be done.

Member Initializer - Use Member.create_from_session or Member.create_by_authentication to instantiate objects of this type.

Parameters:

  • id (String)

    The API ID of the member.

  • website_id (String)

    The WebsiteID of the member which is used to construct urls for member navigation.

  • first_name (String)

    The First Name of the member.

  • last_name (String)

    The Last Name of the member.

  • email (String)

    The email address associated with the member.

  • session (YourMembership::Session, Nil) (defaults to: nil)

    The Session object bound to this member through authentication.



29
30
31
32
33
34
35
36
37
# File 'lib/your_membership/member.rb', line 29

def initialize(id, website_id, first_name, last_name, email, session = nil)
  @id = id
  @website_id = website_id
  @first_name = first_name
  @last_name = last_name
  @email = email
  @session = session
  @profile = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Allow an instance to call all class methods (unless they are specifically restricted) and pass the session and arguments of the current object.



49
50
51
52
53
54
55
# File 'lib/your_membership/member.rb', line 49

def method_missing(name, *args)
  if [:create_by_authentication, :create_from_session].include? name
    raise NoMethodError.new("Cannot call method #{name} on class #{self.class} because it is specifically denied.", 'Method Protected')
  else
    self.class.send(name, @session, *args)
  end
end

Instance Attribute Details

#emailString

The email address associated with the member.

Returns:

  • (String)

    the current value of email



14
15
16
# File 'lib/your_membership/member.rb', line 14

def email
  @email
end

#first_nameString

The First Name of the member.

Returns:

  • (String)

    the current value of first_name



14
15
16
# File 'lib/your_membership/member.rb', line 14

def first_name
  @first_name
end

#full_namestring (readonly)

Format name parts in to a full name string. If you wish different behavior (perhaps ‘last_name, first_name’) this method should be overridden.

Returns:

  • (string)

    Returns a formatted name.



14
15
16
# File 'lib/your_membership/member.rb', line 14

def full_name
  @full_name
end

#idString (readonly)

The API ID of the member.

Returns:

  • (String)

    the current value of id



14
15
16
# File 'lib/your_membership/member.rb', line 14

def id
  @id
end

#last_nameString

The Last Name of the member.

Returns:

  • (String)

    the current value of last_name



14
15
16
# File 'lib/your_membership/member.rb', line 14

def last_name
  @last_name
end

#profileYourMembership::Profile

A session object bound to this member object. This must be set manually.

Returns:



14
15
16
# File 'lib/your_membership/member.rb', line 14

def profile
  @profile
end

#sessionYourMembership::Session

The Session object bound to this member through authentication.

Returns:



14
15
16
# File 'lib/your_membership/member.rb', line 14

def session
  @session
end

#website_idString (readonly)

The WebsiteID of the member which is used to construct urls for member navigation.

Returns:

  • (String)

    the current value of website_id



14
15
16
# File 'lib/your_membership/member.rb', line 14

def website_id
  @website_id
end

Class Method Details

.certifications_get(session, options = {}) ⇒ Array

Returns a list of Certifications for the specified user.

Parameters:

Options Hash (options):

  • :IsArchived (Boolean)

    Include archived certification records in the returned result. Default: True

Returns:

  • (Array)

    An Array of Hashes representing the Certifications of the authenticated user.

See Also:



90
91
92
93
94
95
# File 'lib/your_membership/member.rb', line 90

def self.certifications_get(session, options = {})
  response = post('/', :body => build_XML_request('Member.Certifications.Get', session, options))

  response_valid? response
  response_to_array_of_hashes response['YourMembership_Response']['Member.Certifications.Get'], ['Certification']
end

.certifications_journal_get(session, options = {}) ⇒ Array

Returns a list of Certification Journal Entries for the signed in user that may be optionally filterd by date, expiration, and paging.

Parameters:

Options Hash (options):

  • :ShowExpired (Boolean)

    Include expired journal entries in the returned result.

  • :StartDate (DateTime)

    Only include Journal Entries that are newer that the supplied date.

  • :EntryID (Integer)

    Filter the returned results by sequential EntryID. Only those Certification Journals which have an EntryID greater than the supplied integer will be returned.

  • :CertificationID (String)

    Filter the Journal Entries returned by the specified Certification ID.

  • :PageSize (Integer)

    The number of items that are returned per call of this method. Default is 200 entries.

  • :PageNumber (Integer)

    PageNumber can be used to retrieve multiple result sets. Page 1 is returned by default.

Returns:

  • (Array)

    An Array of Hashes representing the Certification Journal Entries of the authenticated user.

See Also:



115
116
117
118
119
120
# File 'lib/your_membership/member.rb', line 115

def self.certifications_journal_get(session, options = {})
  response = post('/', :body => build_XML_request('Member.Certifications.Journal.Get', session, options))

  response_valid? response
  response_to_array_of_hashes response['YourMembership_Response']['Member.Certifications.Journal.Get'], ['Entry']
end

.commerce_store_getOrderIDs(session, options = {}) ⇒ Array

Returns a list of order IDs for the authenticated user that may be optionally filtered by timestamp and status.

Parameters:

Options Hash (options):

  • :Timestamp (DateTime)

    Filter the returned results by date/time. Only those orders which were placed after the supplied date/time will be returned.

  • :Status (Symbol, Integer)

    Filter the returned results by Status. (-1 = :Cancelled; 0 = :open; 1 = :processed; 2 = :shipped or :closed)

Returns:

  • (Array)

    A list of Invoice Id Strings for the authenticated user.

See Also:



134
135
136
137
138
139
140
141
142
143
# File 'lib/your_membership/member.rb', line 134

def self.commerce_store_getOrderIDs(session, options = {}) # rubocop:disable Style/MethodName
  if options[:Status]
    options[:Status] = YourMembership::Commerce.convert_order_status(options[:Status])
  end

  response = post('/', :body => build_XML_request('Member.Commerce.Store.GetOrderIDs', session, options))

  response_valid? response
  response_to_array response['YourMembership_Response']['Member.Commerce.Store.GetOrderIDs']['Orders'], ['Order'], 'InvoiceID'
end

.commerce_store_order_get(session, invoiceID) ⇒ Hash

Note:

This method depends on the HTTParty Monkey Patch that HTML Decodes response bodies before parsing. YourMembership returns invalid XML when embedding <![CDATA] elements.

Returns the order details, including line items and products ordered, of a store order placed by the authenticated member.

Parameters:

Returns:

  • (Hash)

    Returns a Hash representing a users order referenced by the invoiceID

See Also:



156
157
158
159
160
161
162
163
164
# File 'lib/your_membership/member.rb', line 156

def self.commerce_store_order_get(session, invoiceID)
  options = {}
  options[:InvoiceID] = invoiceID

  response = post('/', :body => build_XML_request('Member.Commerce.Store.Order.Get', session, options))

  response_valid? response
  response_to_array_of_hashes response['YourMembership_Response']['Member.Commerce.Store.Order.Get'], ['Order']
end

.connection_approve(session, id, approve) ⇒ Object

Approves or declines a connection request.

Parameters:

  • session (YourMembership::Session)
  • id (String)

    ID or Profile ID of the member to approve/decline.

  • approve (Boolean)

    0 or 1 to decline or approve a connection 0 = Decline, 1 = Approve

See Also:



173
174
175
176
177
178
179
# File 'lib/your_membership/member.rb', line 173

def self.connection_approve(session, id, approve)
  options = {}
  options[:ID] = id
  options[:Approve] = approve
  response = post('/', :body => build_XML_request('Member.Connection.Approve', session, options))
  response_valid? response
end

.create_by_authentication(username, password) ⇒ YourMembership::Member

Creates a new Member object through username and password authentication.

Parameters:

  • username (String)

    The username in cleartext

  • password (String)

    The password in cleartext

Returns:



61
62
63
64
# File 'lib/your_membership/member.rb', line 61

def self.create_by_authentication(username, password)
  session = YourMembership::Session.create username, password
  create_from_session(session)
end

.create_from_session(session) ⇒ YourMembership::Member

Creates a new Member object from a previously authenticated Session object.

Parameters:

Returns:



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/your_membership/member.rb', line 69

def self.create_from_session(session)
  profile = profile_getMini session
  new(
    profile['ID'],
    profile['WebsiteID'],
    profile['FirstName'],
    profile['LastName'],
    profile['EmailAddr'],
    session
  )
end

.isAuthenticated(session) ⇒ String, Nil

Validates that the current session has been authenticated by returning the authenticated member’s ID.

Parameters:

Returns:

  • (String)

    if provided session is authenticated returns the members’s ID

  • (Nil)

    if provided session is not authenticated returns nil.

Raises:

  • (HTTParty::ResponseError.new(response))

See Also:



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/your_membership/member.rb', line 363

def self.isAuthenticated(session) # rubocop:disable Style/MethodName
  response = post('/', :body => build_XML_request('Member.IsAuthenticated', session))

  # Fail on HTTP Errors
  raise HTTParty::ResponseError.new(response), 'Connection to YourMembership API failed.' unless response.success?

  error_code = response['YourMembership_Response']['ErrCode']

  # Error Code 202 means that the session itself has expired, we don't
  # want to throw an exception for that, just return that the session is
  # not authenticated.
  return nil if error_code == '202'

  # Error Code 403 means that the method requires Authentication, if the
  # call is not authenticated then the session cannot be authenticated.
  return nil if error_code == '403'

  # All other non-zero Error Codes indicate an unrecoverable issue that
  # we need to raise an exception for.
  if error_code != '0'
    raise YourMembership::Error.new(
      response['YourMembership_Response']['ErrCode'],
      response['YourMembership_Response']['ErrDesc']
    )
  end

  if response['YourMembership_Response']['Member.IsAuthenticated']
    # If everything is ok retun the authenticated users ID
    return response['YourMembership_Response']['Member.IsAuthenticated']['ID']
  else
    # If there is no ID in the data returned then the session is not
    # authenticated.
    nil
  end
end

.mediaGallery_upload(session, options = {}) ⇒ String

Creates An XML Body for submission with a file to the authenticated member’s media gallery. Valid files must be an RGB image in GIF, JPEG or PNG format. API requests must be submitted as multipart/form-data with the XML API request submitted in the named field value XMLMessage. This function returns a string that can be embedded as this field value.

Parameters:

Options Hash (options):

  • :AlbumID (Integer)

    AlbumID of the media gallery item to submit to.

  • :Caption (String)

    Caption to be associated with the media gallery item. (Limited to 150 Chars.)

  • :AllowComments (String)

    Setting for allowing comments. Available values are: :all = Comments are allowed :connections = Comments limited to a member’s connections :none = Comments not allowed

  • :IsPublic (Boolean)

    Setting for allowing anonymous visitors to view uploaded photos for public member types. True makes the image visible to everyone, False makes the image only available to Members.

Returns:

  • (String)

    This string should be submitted as the XMLMessage field in a multipart/form-data post to api.yourmembership.com/

See Also:



200
201
202
# File 'lib/your_membership/member.rb', line 200

def self.mediaGallery_upload(session, options = {}) # rubocop:disable Style/MethodName
  build_XML_request('Member.MediaGallery.Upload', session, options)
end

.messages_getInbox(session, options = {}) ⇒ Array

Note:

BUG WORKAROUND: The API documentation indicates that GetInbox should return an <GetInbox> XML structure, but instead it returns <Get.Inbox>

Returns a list of messages from the authenticated member’s Inbox. Returns a maximum of 100 records per request.

Parameters:

Options Hash (options):

  • :PageSize (Integer)

    The maximum number of records in the returned result set.

  • :StartRecord (Integer)

    The record number at which to start the returned result set.

Returns:

  • (Array)

    Returns an Array of Hashes representing a member’s inbox messages

See Also:



216
217
218
219
220
221
# File 'lib/your_membership/member.rb', line 216

def self.messages_getInbox(session, options = {}) # rubocop:disable Style/MethodName
  response = post('/', :body => build_XML_request('Member.Messages.GetInbox', session, options))

  response_valid? response
  response_to_array_of_hashes response['YourMembership_Response']['Members.Messages.Get.Inbox'], ['Message']
end

.messages_getSent(session, options = {}) ⇒ Array

Note:

BUG WORKAROUND: The API documentation indicates that GetInbox should return an <GetSent> XML structure, but instead it returns <Get.Sent>

Returns a list of messages from the authenticated member’s Sent folder, Returns a maximum of 100 records per request.

Parameters:

Options Hash (options):

  • :PageSize (Integer)

    The maximum number of records in the returned result set.

  • :StartRecord (Integer)

    The record number at which to start the returned result set.

Returns:

  • (Array)

    Returns an Array of Hashes representing a member’s sent messages

See Also:



236
237
238
239
240
241
# File 'lib/your_membership/member.rb', line 236

def self.messages_getSent(session, options = {}) # rubocop:disable Style/MethodName
  response = post('/', :body => build_XML_request('Member.Messages.GetSent', session, options))

  response_valid? response
  response_to_array_of_hashes response['YourMembership_Response']['Members.Messages.Get.Sent'], ['Message']
end

.messages_message_read(session, message_id) ⇒ Hash

Returns an individual message by MessageID and marks it as read.

Parameters:

Returns:

  • (Hash)

    Returns a has of all of the message’s fields.

See Also:



250
251
252
253
254
255
256
257
258
# File 'lib/your_membership/member.rb', line 250

def self.messages_message_read(session, message_id)
  options = {}
  options[:MessageID] = message_id
  response = post('/', :body => build_XML_request('Member.Messages.Message.Read', session, options))

  response_valid? response
  # Note that the response key is not the same as the request key, this could just be a typo in the API
  response['YourMembership_Response']['Members.Messages.Message.Read']['Message']
end

.messages_message_send(session, member_id, subject, body) ⇒ Boolean

Message a member.

Parameters:

  • session (YourMembership::Session)
  • member_id (String)

    ID or ProfileID of the member to send a message.

  • subject (String)

    Subject line of the message.

  • body (String)

    Body of the message.

Returns:

  • (Boolean)

    True if successful

See Also:



269
270
271
272
273
274
275
276
# File 'lib/your_membership/member.rb', line 269

def self.messages_message_send(session, member_id, subject, body)
  options = {}
  options[:ID] = member_id
  options[:Subject] = subject
  options[:Body] = body
  response = post('/', :body => build_XML_request('Member.Messages.Message.Send', session, options))
  response_valid? response
end

.password_initializeReset(session, options = {}) ⇒ Boolean

Upon validating Username or Email Address given, sends an email to matching members with a link needed to reset their password. This method does not require authentication.

Parameters:

Options Hash (options):

  • :Username (String)

    Username of the member

  • :EmailAddress (String)

    Email Address of the member

Returns:

  • (Boolean)

    Returns True if successful

See Also:



288
289
290
291
# File 'lib/your_membership/member.rb', line 288

def self.password_initializeReset(session, options = {}) # rubocop:disable Style/MethodName
  response = post('/', :body => build_XML_request('Member.Password.InitializeReset', session, options))
  response_valid? response
end

.password_update(session, new_password, options = {}) ⇒ Boolean

After validating ResetToken or CurrentPassword given, this method updates the associated member’s password to the new value. This method requires Authentication only when passing in CurrentPassword parameter.

Parameters:

  • session (YourMembership::Session)
  • new_password (String)

    The new password to use.

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

Options Hash (options):

  • :CurrentPassword (String)

    Member’s current password. The API request must be Authenticated when using this parameter. Used when members are signed in, but want to change their password.

  • :ResetToken (String)

    Reset Token from the Password Reset email.

Returns:

  • (Boolean)

    Returns True if successful

See Also:



305
306
307
308
309
# File 'lib/your_membership/member.rb', line 305

def self.password_update(session, new_password, options = {})
  options[:NewPassword] = new_password
  response = post('/', :body => build_XML_request('Member.Password.Update', session, options))
  response_valid? response
end

.profile_get(session) ⇒ YourMembership::Profile

Returns the authenticated member’s profile data.

Parameters:

Returns:

See Also:



317
318
319
320
321
322
# File 'lib/your_membership/member.rb', line 317

def self.profile_get(session)
  response = post('/', :body => build_XML_request('Member.Profile.Get', session))

  response_valid? response
  YourMembership::Profile.new response['YourMembership_Response']['Member.Profile.Get']
end

.profile_getMini(session) ⇒ Hash

Returns a subset of the authenticated member’s profile data along with statistics and permissions for the purpose of creating a profile snapshot and navigation control.

Parameters:

Returns:

  • (Hash)

    Returns a Hash of details and permissions for the authenticated user.

See Also:



331
332
333
334
335
336
# File 'lib/your_membership/member.rb', line 331

def self.profile_getMini(session) # rubocop:disable Style/MethodName
  response = post('/', :body => build_XML_request('Member.Profile.GetMini', session))

  response_valid? response
  response['YourMembership_Response']['Member.Profile.GetMini']
end

.wall_post(session, post_text, id = nil) ⇒ Boolean

Post to a member’s wall.

Parameters:

  • session (YourMembership::Session)
  • post_text (String)

    Text to post on the member’s wall.

  • id (String) (defaults to: nil)

    ID or ProfileID of any member that is connected to the authenticated member whose wall to post on. Omit this argument to post on the authenticated member’s own wall.

Returns:

  • (Boolean)

    True if successful

See Also:



347
348
349
350
351
352
353
# File 'lib/your_membership/member.rb', line 347

def self.wall_post(session, post_text, id = nil)
  options = {}
  options[:ID] = id if id
  options[:PostText] = post_text
  response = post('/', :body => build_XML_request('Member.Wall.Post', session, options))
  response_valid? response
end