Class: YourMembership::Member
- 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
-
#email ⇒ String
The email address associated with the member.
-
#first_name ⇒ String
The First Name of the member.
-
#full_name ⇒ string
readonly
Format name parts in to a full name string.
-
#id ⇒ String
readonly
The API ID of the member.
-
#last_name ⇒ String
The Last Name of the member.
-
#profile ⇒ YourMembership::Profile
A session object bound to this member object.
-
#session ⇒ YourMembership::Session
The Session object bound to this member through authentication.
-
#website_id ⇒ String
readonly
The WebsiteID of the member which is used to construct urls for member navigation.
Class Method Summary collapse
-
.certifications_get(session, options = {}) ⇒ Array
Returns a list of Certifications for the specified user.
-
.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.
-
.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.
-
.commerce_store_order_get(session, invoiceID) ⇒ Hash
Returns the order details, including line items and products ordered, of a store order placed by the authenticated member.
-
.connection_approve(session, id, approve) ⇒ Object
Approves or declines a connection request.
-
.create_by_authentication(username, password) ⇒ YourMembership::Member
Creates a new Member object through username and password authentication.
-
.create_from_session(session) ⇒ YourMembership::Member
Creates a new Member object from a previously authenticated Session object.
-
.isAuthenticated(session) ⇒ String, Nil
Validates that the current session has been authenticated by returning the authenticated member’s ID.
-
.mediaGallery_upload(session, options = {}) ⇒ String
Creates An XML Body for submission with a file to the authenticated member’s media gallery.
-
.messages_getInbox(session, options = {}) ⇒ Array
Returns a list of messages from the authenticated member’s Inbox.
-
.messages_getSent(session, options = {}) ⇒ Array
Returns a list of messages from the authenticated member’s Sent folder, Returns a maximum of 100 records per request.
-
.messages_message_read(session, message_id) ⇒ Hash
Returns an individual message by MessageID and marks it as read.
-
.messages_message_send(session, member_id, subject, body) ⇒ Boolean
Message a member.
-
.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.
-
.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.
-
.profile_get(session) ⇒ YourMembership::Profile
Returns the authenticated member’s profile data.
-
.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.
-
.wall_post(session, post_text, id = nil) ⇒ Boolean
Post to a member’s wall.
Instance Method Summary collapse
-
#initialize(id, website_id, first_name, last_name, email, session = nil) ⇒ Member
constructor
Member Initializer - Use Member.create_from_session or Member.create_by_authentication to instantiate objects of this type.
-
#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.
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
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.
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
#email ⇒ String
The email address associated with the member.
14 15 16 |
# File 'lib/your_membership/member.rb', line 14 def email @email end |
#first_name ⇒ String
The First Name of the member.
14 15 16 |
# File 'lib/your_membership/member.rb', line 14 def first_name @first_name end |
#full_name ⇒ string (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.
14 15 16 |
# File 'lib/your_membership/member.rb', line 14 def full_name @full_name end |
#id ⇒ String (readonly)
The API ID of the member.
14 15 16 |
# File 'lib/your_membership/member.rb', line 14 def id @id end |
#last_name ⇒ String
The Last Name of the member.
14 15 16 |
# File 'lib/your_membership/member.rb', line 14 def last_name @last_name end |
#profile ⇒ YourMembership::Profile
A session object bound to this member object. This must be set manually.
14 15 16 |
# File 'lib/your_membership/member.rb', line 14 def profile @profile end |
#session ⇒ YourMembership::Session
The Session object bound to this member through authentication.
14 15 16 |
# File 'lib/your_membership/member.rb', line 14 def session @session end |
#website_id ⇒ String (readonly)
The WebsiteID of the member which is used to construct urls for member navigation.
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.
90 91 92 93 94 95 |
# File 'lib/your_membership/member.rb', line 90 def self.certifications_get(session, = {}) response = post('/', :body => build_XML_request('Member.Certifications.Get', session, )) 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.
115 116 117 118 119 120 |
# File 'lib/your_membership/member.rb', line 115 def self.certifications_journal_get(session, = {}) response = post('/', :body => build_XML_request('Member.Certifications.Journal.Get', session, )) 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.
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/your_membership/member.rb', line 134 def self.commerce_store_getOrderIDs(session, = {}) # rubocop:disable Style/MethodName if [:Status] [:Status] = YourMembership::Commerce.convert_order_status([:Status]) end response = post('/', :body => build_XML_request('Member.Commerce.Store.GetOrderIDs', session, )) response_valid? response response_to_array response['YourMembership_Response']['Member.Commerce.Store.GetOrderIDs']['Orders'], ['Order'], 'InvoiceID' end |
.commerce_store_order_get(session, invoiceID) ⇒ Hash
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.
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) = {} [:InvoiceID] = invoiceID response = post('/', :body => build_XML_request('Member.Commerce.Store.Order.Get', session, )) 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.
173 174 175 176 177 178 179 |
# File 'lib/your_membership/member.rb', line 173 def self.connection_approve(session, id, approve) = {} [:ID] = id [:Approve] = approve response = post('/', :body => build_XML_request('Member.Connection.Approve', session, )) response_valid? response end |
.create_by_authentication(username, password) ⇒ YourMembership::Member
Creates a new Member object through username and password authentication.
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.
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.
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.
200 201 202 |
# File 'lib/your_membership/member.rb', line 200 def self.mediaGallery_upload(session, = {}) # rubocop:disable Style/MethodName build_XML_request('Member.MediaGallery.Upload', session, ) end |
.messages_getInbox(session, options = {}) ⇒ Array
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.
216 217 218 219 220 221 |
# File 'lib/your_membership/member.rb', line 216 def self.(session, = {}) # rubocop:disable Style/MethodName response = post('/', :body => build_XML_request('Member.Messages.GetInbox', session, )) response_valid? response response_to_array_of_hashes response['YourMembership_Response']['Members.Messages.Get.Inbox'], ['Message'] end |
.messages_getSent(session, options = {}) ⇒ Array
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.
236 237 238 239 240 241 |
# File 'lib/your_membership/member.rb', line 236 def self.(session, = {}) # rubocop:disable Style/MethodName response = post('/', :body => build_XML_request('Member.Messages.GetSent', session, )) 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.
250 251 252 253 254 255 256 257 258 |
# File 'lib/your_membership/member.rb', line 250 def self.(session, ) = {} [:MessageID] = response = post('/', :body => build_XML_request('Member.Messages.Message.Read', session, )) 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.
269 270 271 272 273 274 275 276 |
# File 'lib/your_membership/member.rb', line 269 def self.(session, member_id, subject, body) = {} [:ID] = member_id [:Subject] = subject [:Body] = body response = post('/', :body => build_XML_request('Member.Messages.Message.Send', session, )) 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.
288 289 290 291 |
# File 'lib/your_membership/member.rb', line 288 def self.password_initializeReset(session, = {}) # rubocop:disable Style/MethodName response = post('/', :body => build_XML_request('Member.Password.InitializeReset', session, )) 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.
305 306 307 308 309 |
# File 'lib/your_membership/member.rb', line 305 def self.password_update(session, new_password, = {}) [:NewPassword] = new_password response = post('/', :body => build_XML_request('Member.Password.Update', session, )) response_valid? response end |
.profile_get(session) ⇒ YourMembership::Profile
Returns the authenticated member’s profile data.
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.
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.
347 348 349 350 351 352 353 |
# File 'lib/your_membership/member.rb', line 347 def self.wall_post(session, post_text, id = nil) = {} [:ID] = id if id [:PostText] = post_text response = post('/', :body => build_XML_request('Member.Wall.Post', session, )) response_valid? response end |