your_membership 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +5 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +10 -0
- data/README.md +12 -10
- data/lib/httparty/patch.rb +33 -33
- data/lib/your_membership/base.rb +197 -197
- data/lib/your_membership/commerce.rb +25 -25
- data/lib/your_membership/config.rb +41 -41
- data/lib/your_membership/convert.rb +24 -24
- data/lib/your_membership/error.rb +21 -21
- data/lib/your_membership/events.rb +60 -60
- data/lib/your_membership/feeds.rb +37 -37
- data/lib/your_membership/member.rb +399 -397
- data/lib/your_membership/members.rb +124 -124
- data/lib/your_membership/people.rb +38 -38
- data/lib/your_membership/profile.rb +92 -85
- data/lib/your_membership/sa.rb +6 -6
- data/lib/your_membership/sa_auth.rb +34 -34
- data/lib/your_membership/sa_certifications.rb +22 -22
- data/lib/your_membership/sa_commerce.rb +22 -22
- data/lib/your_membership/sa_events.rb +66 -66
- data/lib/your_membership/sa_export.rb +195 -195
- data/lib/your_membership/sa_groups.rb +30 -30
- data/lib/your_membership/sa_member.rb +49 -49
- data/lib/your_membership/sa_members.rb +180 -179
- data/lib/your_membership/sa_nonmembers.rb +41 -41
- data/lib/your_membership/sa_people.rb +92 -92
- data/lib/your_membership/session.rb +148 -152
- data/lib/your_membership/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_multiple.yml +51 -0
- data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_none.yml +51 -0
- data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_single.yml +51 -0
- data/spec/lib/{profile_spec.rb → your_membership/profile_spec.rb} +232 -197
- data/spec/lib/your_membership/sa_members_spec.rb +38 -0
- data/spec/spec_helper.rb +101 -78
- data/your_membership.gemspec +4 -0
- metadata +85 -19
@@ -1,25 +1,25 @@
|
|
1
|
-
module YourMembership
|
2
|
-
# The Commerce Namespace does not currently have any methods in the
|
3
|
-
# YourMembership.com API. This is used for some helper methods.
|
4
|
-
class Commerce
|
5
|
-
# Converts some convenient Symbols to the Integer that the YourMembership API expects
|
6
|
-
# @param [Symbol] status Accepts :cancelled, :open, :processed, :shipped
|
7
|
-
# @return [Integer] Returns the integer that the API expects
|
8
|
-
def self.convert_order_status(status)
|
9
|
-
status_code = 0
|
10
|
-
case status
|
11
|
-
when :cancelled, :Cancelled
|
12
|
-
status_code = -1
|
13
|
-
when :open, :Open
|
14
|
-
status_code = 0
|
15
|
-
when :processed, :Processed
|
16
|
-
status_code = 1
|
17
|
-
when :shipped, :Shipped, :closed, :Closed
|
18
|
-
status_code = 2
|
19
|
-
else
|
20
|
-
status_code = status
|
21
|
-
end
|
22
|
-
status_code
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
# The Commerce Namespace does not currently have any methods in the
|
3
|
+
# YourMembership.com API. This is used for some helper methods.
|
4
|
+
class Commerce
|
5
|
+
# Converts some convenient Symbols to the Integer that the YourMembership API expects
|
6
|
+
# @param [Symbol] status Accepts :cancelled, :open, :processed, :shipped
|
7
|
+
# @return [Integer] Returns the integer that the API expects
|
8
|
+
def self.convert_order_status(status)
|
9
|
+
status_code = 0
|
10
|
+
case status
|
11
|
+
when :cancelled, :Cancelled
|
12
|
+
status_code = -1
|
13
|
+
when :open, :Open
|
14
|
+
status_code = 0
|
15
|
+
when :processed, :Processed
|
16
|
+
status_code = 1
|
17
|
+
when :shipped, :Shipped, :closed, :Closed
|
18
|
+
status_code = 2
|
19
|
+
else
|
20
|
+
status_code = status
|
21
|
+
end
|
22
|
+
status_code
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
module YourMembership
|
3
|
-
# Configuration defaults
|
4
|
-
@config = {
|
5
|
-
:publicKey => '',
|
6
|
-
:privateKey => '',
|
7
|
-
:saPasscode => '',
|
8
|
-
:baseUri => 'https://api.yourmembership.com',
|
9
|
-
:version => '2.00'
|
10
|
-
}
|
11
|
-
|
12
|
-
@valid_config_keys = @config.keys
|
13
|
-
|
14
|
-
# Configure through hash
|
15
|
-
# @example
|
16
|
-
# YourMembership.configure(:publicKey => 45G2E6DC-98NA-45W7-8493-D97C4E2C156A,
|
17
|
-
# :privateKey => D74H44B2-2348-4ACT-B531-45W385TGB966, :saPasscode => WPIkriJtqS4m)
|
18
|
-
# @note The baseUri and version are both defaulted to the current API for the release version.
|
19
|
-
def self.configure(opts = {})
|
20
|
-
opts.each { |k, v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
|
21
|
-
end
|
22
|
-
|
23
|
-
# Configure through yaml file
|
24
|
-
# @example
|
25
|
-
# ---
|
26
|
-
# publicKey: 45G2E6DC-98NA-45W7-8493-D97C4E2C156A
|
27
|
-
# privateKey: D74H44B2-2348-4ACT-B531-45W385TGB966
|
28
|
-
# saPasscode: WPIkriJtqS4m
|
29
|
-
# baseUri: 'https://api.yourmembership.com'
|
30
|
-
# version: '2.00'
|
31
|
-
# @note The baseUri and version are both defaulted to the current API for the release version.
|
32
|
-
def self.configure_with(path_to_yaml_file)
|
33
|
-
config = YAML.load(IO.read(path_to_yaml_file))
|
34
|
-
configure(config)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Access configuration variables by calling YourMembership.config[ :attribute ]
|
38
|
-
def self.config # rubocop:disable Style/TrivialAccessors
|
39
|
-
@config
|
40
|
-
end
|
41
|
-
end
|
1
|
+
require 'yaml'
|
2
|
+
module YourMembership
|
3
|
+
# Configuration defaults
|
4
|
+
@config = {
|
5
|
+
:publicKey => '',
|
6
|
+
:privateKey => '',
|
7
|
+
:saPasscode => '',
|
8
|
+
:baseUri => 'https://api.yourmembership.com',
|
9
|
+
:version => '2.00'
|
10
|
+
}
|
11
|
+
|
12
|
+
@valid_config_keys = @config.keys
|
13
|
+
|
14
|
+
# Configure through hash
|
15
|
+
# @example
|
16
|
+
# YourMembership.configure(:publicKey => 45G2E6DC-98NA-45W7-8493-D97C4E2C156A,
|
17
|
+
# :privateKey => D74H44B2-2348-4ACT-B531-45W385TGB966, :saPasscode => WPIkriJtqS4m)
|
18
|
+
# @note The baseUri and version are both defaulted to the current API for the release version.
|
19
|
+
def self.configure(opts = {})
|
20
|
+
opts.each { |k, v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
|
21
|
+
end
|
22
|
+
|
23
|
+
# Configure through yaml file
|
24
|
+
# @example
|
25
|
+
# ---
|
26
|
+
# publicKey: 45G2E6DC-98NA-45W7-8493-D97C4E2C156A
|
27
|
+
# privateKey: D74H44B2-2348-4ACT-B531-45W385TGB966
|
28
|
+
# saPasscode: WPIkriJtqS4m
|
29
|
+
# baseUri: 'https://api.yourmembership.com'
|
30
|
+
# version: '2.00'
|
31
|
+
# @note The baseUri and version are both defaulted to the current API for the release version.
|
32
|
+
def self.configure_with(path_to_yaml_file)
|
33
|
+
config = YAML.load(IO.read(path_to_yaml_file))
|
34
|
+
configure(config)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Access configuration variables by calling YourMembership.config[ :attribute ]
|
38
|
+
def self.config # rubocop:disable Style/TrivialAccessors
|
39
|
+
@config
|
40
|
+
end
|
41
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
module YourMembership
|
2
|
-
# YourMembership Convert Namespace
|
3
|
-
class Convert < YourMembership::Base
|
4
|
-
# Converts the given local time to current Eastern Time, factoring in adjustments for Daylight Savings Time.
|
5
|
-
# @see https://api.yourmembership.com/reference/2_00/Convert_ToEasternTime.htm
|
6
|
-
#
|
7
|
-
# @param [YourMembership::Session] session
|
8
|
-
# @param [DateTime] localTime A DateTime that you want to convert to US/Eastern Time
|
9
|
-
# @param [Integer] localGMTBias The Number of hours the local time zone is away from GMT
|
10
|
-
# @return [Hash] Returns an Hash with 'Converted' and 'ServerGmtBias'
|
11
|
-
# @note This is probably not necessary as Ruby will happily convert dates.
|
12
|
-
def self.ToEasternTime(session, localTime, localGMTBias) # rubocop:disable Style/MethodName
|
13
|
-
options = {}
|
14
|
-
options[:LocalTime] = format_date_string localTime
|
15
|
-
options[:LocalGmtBias] = localGMTBias
|
16
|
-
|
17
|
-
response = post('/', :body => build_XML_request('Convert.ToEasternTime', session, options))
|
18
|
-
|
19
|
-
if response_valid? response
|
20
|
-
response['YourMembership_Response']['Convert.ToEasternTime']
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
# YourMembership Convert Namespace
|
3
|
+
class Convert < YourMembership::Base
|
4
|
+
# Converts the given local time to current Eastern Time, factoring in adjustments for Daylight Savings Time.
|
5
|
+
# @see https://api.yourmembership.com/reference/2_00/Convert_ToEasternTime.htm
|
6
|
+
#
|
7
|
+
# @param [YourMembership::Session] session
|
8
|
+
# @param [DateTime] localTime A DateTime that you want to convert to US/Eastern Time
|
9
|
+
# @param [Integer] localGMTBias The Number of hours the local time zone is away from GMT
|
10
|
+
# @return [Hash] Returns an Hash with 'Converted' and 'ServerGmtBias'
|
11
|
+
# @note This is probably not necessary as Ruby will happily convert dates.
|
12
|
+
def self.ToEasternTime(session, localTime, localGMTBias) # rubocop:disable Style/MethodName
|
13
|
+
options = {}
|
14
|
+
options[:LocalTime] = format_date_string localTime
|
15
|
+
options[:LocalGmtBias] = localGMTBias
|
16
|
+
|
17
|
+
response = post('/', :body => build_XML_request('Convert.ToEasternTime', session, options))
|
18
|
+
|
19
|
+
if response_valid? response
|
20
|
+
response['YourMembership_Response']['Convert.ToEasternTime']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module YourMembership
|
2
|
-
# Custom exception for YourMembership error codes.
|
3
|
-
# @attr [Integer] error_code The Error Code
|
4
|
-
# @attr [String] error_description A Description of what the error means.
|
5
|
-
class Error < StandardError
|
6
|
-
attr_accessor :error_code, :error_description
|
7
|
-
|
8
|
-
# @param [Integer] error_code The Error Code
|
9
|
-
# @param [String] error_description A Description of what the error means.
|
10
|
-
# @see https://api.yourmembership.com/reference/2_00/Error_Codes.htm
|
11
|
-
def initialize(error_code, error_description)
|
12
|
-
self.error_code = error_code
|
13
|
-
self.error_description = error_description
|
14
|
-
end
|
15
|
-
|
16
|
-
# @return [String] A highly readable error message.
|
17
|
-
def to_s
|
18
|
-
"Your Membership Returned An Error Code: #{error_code} With Message: #{error_description}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
# Custom exception for YourMembership error codes.
|
3
|
+
# @attr [Integer] error_code The Error Code
|
4
|
+
# @attr [String] error_description A Description of what the error means.
|
5
|
+
class Error < StandardError
|
6
|
+
attr_accessor :error_code, :error_description
|
7
|
+
|
8
|
+
# @param [Integer] error_code The Error Code
|
9
|
+
# @param [String] error_description A Description of what the error means.
|
10
|
+
# @see https://api.yourmembership.com/reference/2_00/Error_Codes.htm
|
11
|
+
def initialize(error_code, error_description)
|
12
|
+
self.error_code = error_code
|
13
|
+
self.error_description = error_description
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [String] A highly readable error message.
|
17
|
+
def to_s
|
18
|
+
"Your Membership Returned An Error Code: #{error_code} With Message: #{error_description}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,60 +1,60 @@
|
|
1
|
-
module YourMembership
|
2
|
-
# YourMembership Events Namespace
|
3
|
-
class Events < YourMembership::Base
|
4
|
-
# Returns a list of Community Events based on the supplied search term.
|
5
|
-
#
|
6
|
-
# @see https://api.yourmembership.com/reference/2_00/Events_All_Search.htm
|
7
|
-
#
|
8
|
-
# @param [YourMembership::Session] session
|
9
|
-
# @param [Hash] options
|
10
|
-
# @option options [String] :SearchText Text to be searched.
|
11
|
-
# @option options [Integer] :PageSize The maximum number of records in the returned result set.
|
12
|
-
# @option options [Integer] :StartRecord The record number at which to start the returned result set.
|
13
|
-
# @return [Array] Returns an Array of Hashes representing events based on a search result.
|
14
|
-
def self.all_search(session, options = {})
|
15
|
-
# Options include :SearchText(String), :PageSize(Integer), :StartRecord(Integer)
|
16
|
-
|
17
|
-
response = post('/', :body => build_XML_request('Events.All.Search', session, options))
|
18
|
-
|
19
|
-
response_valid? response
|
20
|
-
response_to_array_of_hashes response['YourMembership_Response']['Events.All.Search'], ['Results', 'Item']
|
21
|
-
end
|
22
|
-
|
23
|
-
# Returns a list of all Attendees for the specified event including both Registrations and RSVPs. If the Event
|
24
|
-
# Registration contains a related Custom Form, the form data will be included in the <DataSet> element as it is
|
25
|
-
# stored in our database. Records for authenticated members also include the <ID> element to cross reference the
|
26
|
-
# Member's data.
|
27
|
-
#
|
28
|
-
# @see https://api.yourmembership.com/reference/2_00/Events_Event_Attendees_Get.htm
|
29
|
-
#
|
30
|
-
# @param [YourMembership::Session] session
|
31
|
-
# @param [Integer] event_id An Event ID for which to return event details.
|
32
|
-
# @return [Array] Returns an Array of Hashes representing the attendees to a specific event.
|
33
|
-
def self.event_attendees_get(session, event_id)
|
34
|
-
options = {}
|
35
|
-
options[:EventID] = event_id
|
36
|
-
|
37
|
-
response = post('/', :body => build_XML_request('Events.Event.Attendees.Get', session, options))
|
38
|
-
|
39
|
-
response_valid? response
|
40
|
-
response_to_array_of_hashes response['YourMembership_Response']['Events.Event.Attendees.Get'], ['Attendees', 'Attendee']
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns details about the provided Event ID.
|
44
|
-
#
|
45
|
-
# @see https://api.yourmembership.com/reference/2_00/Events_Event_Get.htm
|
46
|
-
#
|
47
|
-
# @param [YourMembership::Session] session
|
48
|
-
# @param [Integer] event_id An Event ID for which to return event details.
|
49
|
-
# @return [Hash] Returns a Hash of details about a particular event.
|
50
|
-
def self.event_get(session, event_id)
|
51
|
-
options = {}
|
52
|
-
options[:EventID] = event_id
|
53
|
-
|
54
|
-
response = post('/', :body => build_XML_request('Events.Event.Get', session, options))
|
55
|
-
|
56
|
-
response_valid? response
|
57
|
-
response['YourMembership_Response']['Events.Event.Get'].to_h
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
# YourMembership Events Namespace
|
3
|
+
class Events < YourMembership::Base
|
4
|
+
# Returns a list of Community Events based on the supplied search term.
|
5
|
+
#
|
6
|
+
# @see https://api.yourmembership.com/reference/2_00/Events_All_Search.htm
|
7
|
+
#
|
8
|
+
# @param [YourMembership::Session] session
|
9
|
+
# @param [Hash] options
|
10
|
+
# @option options [String] :SearchText Text to be searched.
|
11
|
+
# @option options [Integer] :PageSize The maximum number of records in the returned result set.
|
12
|
+
# @option options [Integer] :StartRecord The record number at which to start the returned result set.
|
13
|
+
# @return [Array] Returns an Array of Hashes representing events based on a search result.
|
14
|
+
def self.all_search(session, options = {})
|
15
|
+
# Options include :SearchText(String), :PageSize(Integer), :StartRecord(Integer)
|
16
|
+
|
17
|
+
response = post('/', :body => build_XML_request('Events.All.Search', session, options))
|
18
|
+
|
19
|
+
response_valid? response
|
20
|
+
response_to_array_of_hashes response['YourMembership_Response']['Events.All.Search'], ['Results', 'Item']
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns a list of all Attendees for the specified event including both Registrations and RSVPs. If the Event
|
24
|
+
# Registration contains a related Custom Form, the form data will be included in the <DataSet> element as it is
|
25
|
+
# stored in our database. Records for authenticated members also include the <ID> element to cross reference the
|
26
|
+
# Member's data.
|
27
|
+
#
|
28
|
+
# @see https://api.yourmembership.com/reference/2_00/Events_Event_Attendees_Get.htm
|
29
|
+
#
|
30
|
+
# @param [YourMembership::Session] session
|
31
|
+
# @param [Integer] event_id An Event ID for which to return event details.
|
32
|
+
# @return [Array] Returns an Array of Hashes representing the attendees to a specific event.
|
33
|
+
def self.event_attendees_get(session, event_id)
|
34
|
+
options = {}
|
35
|
+
options[:EventID] = event_id
|
36
|
+
|
37
|
+
response = post('/', :body => build_XML_request('Events.Event.Attendees.Get', session, options))
|
38
|
+
|
39
|
+
response_valid? response
|
40
|
+
response_to_array_of_hashes response['YourMembership_Response']['Events.Event.Attendees.Get'], ['Attendees', 'Attendee']
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns details about the provided Event ID.
|
44
|
+
#
|
45
|
+
# @see https://api.yourmembership.com/reference/2_00/Events_Event_Get.htm
|
46
|
+
#
|
47
|
+
# @param [YourMembership::Session] session
|
48
|
+
# @param [Integer] event_id An Event ID for which to return event details.
|
49
|
+
# @return [Hash] Returns a Hash of details about a particular event.
|
50
|
+
def self.event_get(session, event_id)
|
51
|
+
options = {}
|
52
|
+
options[:EventID] = event_id
|
53
|
+
|
54
|
+
response = post('/', :body => build_XML_request('Events.Event.Get', session, options))
|
55
|
+
|
56
|
+
response_valid? response
|
57
|
+
response['YourMembership_Response']['Events.Event.Get'].to_h
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
module YourMembership
|
2
|
-
# YourMembership Feeds Namespace
|
3
|
-
class Feeds < YourMembership::Base
|
4
|
-
# Returns a list of RSS 2.0 community feeds.
|
5
|
-
#
|
6
|
-
# @see https://api.yourmembership.com/reference/2_00/Feeds_Get.htm
|
7
|
-
#
|
8
|
-
# @param [YourMembership::Session] session
|
9
|
-
# @return [Array] Returns an Array of Hashes representing all of your community's feeds.
|
10
|
-
def self.get(session)
|
11
|
-
response = post('/', :body => build_XML_request('Feeds.Get', session))
|
12
|
-
|
13
|
-
response_valid? response
|
14
|
-
response_to_array_of_hashes response['YourMembership_Response']['Feeds.Get'], ['Feed']
|
15
|
-
end
|
16
|
-
|
17
|
-
# Returns a RSS 2.0 community feed
|
18
|
-
#
|
19
|
-
# @see https://api.yourmembership.com/reference/2_00/Feeds_Feed_Get.htm
|
20
|
-
#
|
21
|
-
# @param [YourMembership::Session] session
|
22
|
-
# @param [String] feed_id ID of the Feed to be returned.
|
23
|
-
# @param [Hash] options
|
24
|
-
# @option options [Integer] :PageSize The maximum number of records in the returned result set.
|
25
|
-
# @option options [Integer] :StartRecord The record number at which to start the returned result set.
|
26
|
-
# @return [Nokogiri::XML] Returns a Nokogiri XML document that represents an rss feed
|
27
|
-
def self.feed_get(session, feed_id, options = {})
|
28
|
-
options[:FeedID] = feed_id
|
29
|
-
|
30
|
-
response = post('/', :body => build_XML_request('Feeds.Feed.Get', session, options))
|
31
|
-
|
32
|
-
response_valid? response
|
33
|
-
xml_body = Nokogiri::XML response.body
|
34
|
-
xml_body.at_xpath '//rss'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
# YourMembership Feeds Namespace
|
3
|
+
class Feeds < YourMembership::Base
|
4
|
+
# Returns a list of RSS 2.0 community feeds.
|
5
|
+
#
|
6
|
+
# @see https://api.yourmembership.com/reference/2_00/Feeds_Get.htm
|
7
|
+
#
|
8
|
+
# @param [YourMembership::Session] session
|
9
|
+
# @return [Array] Returns an Array of Hashes representing all of your community's feeds.
|
10
|
+
def self.get(session)
|
11
|
+
response = post('/', :body => build_XML_request('Feeds.Get', session))
|
12
|
+
|
13
|
+
response_valid? response
|
14
|
+
response_to_array_of_hashes response['YourMembership_Response']['Feeds.Get'], ['Feed']
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns a RSS 2.0 community feed
|
18
|
+
#
|
19
|
+
# @see https://api.yourmembership.com/reference/2_00/Feeds_Feed_Get.htm
|
20
|
+
#
|
21
|
+
# @param [YourMembership::Session] session
|
22
|
+
# @param [String] feed_id ID of the Feed to be returned.
|
23
|
+
# @param [Hash] options
|
24
|
+
# @option options [Integer] :PageSize The maximum number of records in the returned result set.
|
25
|
+
# @option options [Integer] :StartRecord The record number at which to start the returned result set.
|
26
|
+
# @return [Nokogiri::XML] Returns a Nokogiri XML document that represents an rss feed
|
27
|
+
def self.feed_get(session, feed_id, options = {})
|
28
|
+
options[:FeedID] = feed_id
|
29
|
+
|
30
|
+
response = post('/', :body => build_XML_request('Feeds.Feed.Get', session, options))
|
31
|
+
|
32
|
+
response_valid? response
|
33
|
+
xml_body = Nokogiri::XML response.body
|
34
|
+
xml_body.at_xpath '//rss'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,397 +1,399 @@
|
|
1
|
-
module YourMembership
|
2
|
-
# The member object provides a convenient abstraction that encapsulates the member methods and caches some basic
|
3
|
-
# details about the member.
|
4
|
-
#
|
5
|
-
# @attr_reader [String] id The API ID of the member.
|
6
|
-
# @attr_reader [String] website_id The WebsiteID of the member which is used to construct urls for member navigation.
|
7
|
-
# @attr_reader [String] full_name The COMPUTED full_name of the member. This is implemented through the full_name
|
8
|
-
# method so as to allow this method to be easily overridden if a different format is desired.
|
9
|
-
# @attr [String] first_name The First Name of the member.
|
10
|
-
# @attr [String] last_name The Last Name of the member.
|
11
|
-
# @attr [String] email The email address associated with the member.
|
12
|
-
# @attr [YourMembership::Session] session The Session object bound to this member through authentication.
|
13
|
-
# @attr [YourMembership::Profile] profile A session object bound to this member object. This must be set manually.
|
14
|
-
class Member < YourMembership::Base
|
15
|
-
attr_reader :id, :website_id
|
16
|
-
attr_accessor :first_name, :last_name, :email, :session, :profile
|
17
|
-
|
18
|
-
# Member Initializer - Use Member.create_from_session or Member.create_by_authentication to instantiate
|
19
|
-
# objects of this type.
|
20
|
-
#
|
21
|
-
# @note There is not yet a compelling reason to call Member.new() directly, however it can be done.
|
22
|
-
#
|
23
|
-
# @param [String] id The API ID of the member.
|
24
|
-
# @param [String] website_id The WebsiteID of the member which is used to construct urls for member navigation.
|
25
|
-
# @param [String] first_name The First Name of the member.
|
26
|
-
# @param [String] last_name The Last Name of the member.
|
27
|
-
# @param [String] email The email address associated with the member.
|
28
|
-
# @param [YourMembership::Session, Nil] session The Session object bound to this member through authentication.
|
29
|
-
def initialize(id, website_id, first_name, last_name, email, session = nil)
|
30
|
-
@id = id
|
31
|
-
@website_id = website_id
|
32
|
-
@first_name = first_name
|
33
|
-
@last_name = last_name
|
34
|
-
@email = email
|
35
|
-
@session = session
|
36
|
-
@profile = nil
|
37
|
-
end
|
38
|
-
|
39
|
-
# Format name parts in to a full name string.
|
40
|
-
# If you wish different behavior (perhaps 'last_name, first_name') this method should be overridden.
|
41
|
-
#
|
42
|
-
# @return [string] Returns a formatted name.
|
43
|
-
def full_name
|
44
|
-
@first_name + ' ' + @last_name
|
45
|
-
end
|
46
|
-
|
47
|
-
# Allow an instance to call all class methods (unless they are specifically restricted) and pass the session and
|
48
|
-
# arguments of the current object.
|
49
|
-
def method_missing(name, *args)
|
50
|
-
if [:create_by_authentication, :create_from_session].include? name
|
51
|
-
raise NoMethodError.new("Cannot call method #{name} on class #{self.class} because it is specifically denied.", 'Method Protected')
|
52
|
-
else
|
53
|
-
self.class.send(name, @session, *args)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Creates a new Member object through username and password authentication.
|
58
|
-
# @param [String] username The username in cleartext
|
59
|
-
# @param [String] password The password in cleartext
|
60
|
-
# @return [YourMembership::Member] Returns a new Member object with associated authenticated Session object
|
61
|
-
def self.create_by_authentication(username, password)
|
62
|
-
session = YourMembership::Session.create username, password
|
63
|
-
create_from_session(session)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Creates a new Member object from a previously authenticated Session object.
|
67
|
-
# @param [YourMembership::Session] session A previously authenticated Session.
|
68
|
-
# @return [YourMembership::Member] Returns a new Member object
|
69
|
-
def self.create_from_session(session)
|
70
|
-
profile = profile_getMini session
|
71
|
-
new(
|
72
|
-
profile['ID'],
|
73
|
-
profile['WebsiteID'],
|
74
|
-
profile['FirstName'],
|
75
|
-
profile['LastName'],
|
76
|
-
profile['EmailAddr'],
|
77
|
-
session
|
78
|
-
)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Returns a list of Certifications for the specified user.
|
82
|
-
#
|
83
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Certifications_Get.htm
|
84
|
-
#
|
85
|
-
# @param [YourMembership::Session] session
|
86
|
-
# @param [Hash] options
|
87
|
-
# @option options [Boolean] :IsArchived Include archived certification records in the returned result. Default: True
|
88
|
-
#
|
89
|
-
# @return [Array] An Array of Hashes representing the Certifications of the authenticated user.
|
90
|
-
def self.certifications_get(session, options = {})
|
91
|
-
response = post('/', :body => build_XML_request('Member.Certifications.Get', session, options))
|
92
|
-
|
93
|
-
response_valid? response
|
94
|
-
response_to_array_of_hashes response['YourMembership_Response']['Member.Certifications.Get'], ['Certification']
|
95
|
-
end
|
96
|
-
|
97
|
-
# Returns a list of Certification Journal Entries for the signed in user that may be optionally filterd by date,
|
98
|
-
# expiration, and paging.
|
99
|
-
#
|
100
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Certifications_Journal_Get.htm
|
101
|
-
#
|
102
|
-
# @param [YourMembership::Session] session
|
103
|
-
# @param [Hash] options
|
104
|
-
# @option options [Boolean] :ShowExpired Include expired journal entries in the returned result.
|
105
|
-
# @option options [DateTime] :StartDate Only include Journal Entries that are newer that the supplied date.
|
106
|
-
# @option options [Integer] :EntryID Filter the returned results by sequential EntryID. Only those Certification
|
107
|
-
# Journals which have an EntryID greater than the supplied integer will be returned.
|
108
|
-
# @option options [String] :CertificationID Filter the Journal Entries returned by the specified Certification ID.
|
109
|
-
# @option options [Integer] :PageSize The number of items that are returned per call of this method.
|
110
|
-
# Default is 200 entries.
|
111
|
-
# @option options [Integer] :PageNumber PageNumber can be used to retrieve multiple result sets.
|
112
|
-
# Page 1 is returned by default.
|
113
|
-
#
|
114
|
-
# @return [Array] An Array of Hashes representing the Certification Journal Entries of the authenticated user.
|
115
|
-
def self.certifications_journal_get(session, options = {})
|
116
|
-
response = post('/', :body => build_XML_request('Member.Certifications.Journal.Get', session, options))
|
117
|
-
|
118
|
-
response_valid? response
|
119
|
-
response_to_array_of_hashes response['YourMembership_Response']['Member.Certifications.Journal.Get'], ['Entry']
|
120
|
-
end
|
121
|
-
|
122
|
-
# Returns a list of order IDs for the authenticated user that may be optionally filtered by timestamp and status.
|
123
|
-
#
|
124
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Commerce_Store_GetOrderIDs.htm
|
125
|
-
#
|
126
|
-
# @param [YourMembership::Session] session
|
127
|
-
# @param [Hash] options
|
128
|
-
# @option options [DateTime] :Timestamp Filter the returned results by date/time. Only those orders which were
|
129
|
-
# placed after the supplied date/time will be returned.
|
130
|
-
# @option options [Symbol, Integer] :Status Filter the returned results by Status.
|
131
|
-
# (-1 = :Cancelled; 0 = :open; 1 = :processed; 2 = :shipped or :closed)
|
132
|
-
#
|
133
|
-
# @return [Array] A list of Invoice Id Strings for the authenticated user.
|
134
|
-
def self.commerce_store_getOrderIDs(session, options = {}) # rubocop:disable Style/MethodName
|
135
|
-
if options[:Status]
|
136
|
-
options[:Status] = YourMembership::Commerce.convert_order_status(options[:Status])
|
137
|
-
end
|
138
|
-
|
139
|
-
response = post('/', :body => build_XML_request('Member.Commerce.Store.GetOrderIDs', session, options))
|
140
|
-
|
141
|
-
response_valid? response
|
142
|
-
response_to_array response['YourMembership_Response']['Member.Commerce.Store.GetOrderIDs']['Orders'], ['Order'], 'InvoiceID'
|
143
|
-
end
|
144
|
-
|
145
|
-
# Returns the order details, including line items and products ordered, of a store order placed by the authenticated
|
146
|
-
# member.
|
147
|
-
#
|
148
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Commerce_Store_Order_Get.htm
|
149
|
-
#
|
150
|
-
# @param [YourMembership::Session] session
|
151
|
-
# @param [String] invoiceID The Invoice ID of the store order to be returned.
|
152
|
-
# @return [Hash] Returns a Hash representing a users order referenced by the invoiceID
|
153
|
-
#
|
154
|
-
# @note This method depends on the HTTParty Monkey Patch that HTML Decodes response bodies before parsing.
|
155
|
-
# YourMembership returns invalid XML when embedding <![CDATA] elements.
|
156
|
-
def self.commerce_store_order_get(session, invoiceID)
|
157
|
-
options = {}
|
158
|
-
options[:InvoiceID] = invoiceID
|
159
|
-
|
160
|
-
response = post('/', :body => build_XML_request('Member.Commerce.Store.Order.Get', session, options))
|
161
|
-
|
162
|
-
response_valid? response
|
163
|
-
response_to_array_of_hashes response['YourMembership_Response']['Member.Commerce.Store.Order.Get'], ['Order']
|
164
|
-
end
|
165
|
-
|
166
|
-
# Approves or declines a connection request.
|
167
|
-
#
|
168
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Connection_Approve.htm
|
169
|
-
#
|
170
|
-
# @param [YourMembership::Session] session
|
171
|
-
# @param [String] id ID or Profile ID of the member to approve/decline.
|
172
|
-
# @param [Boolean] approve 0 or 1 to decline or approve a connection 0 = Decline, 1 = Approve
|
173
|
-
def self.connection_approve(session, id, approve)
|
174
|
-
options = {}
|
175
|
-
options[:ID] = id
|
176
|
-
options[:Approve] = approve
|
177
|
-
response = post('/', :body => build_XML_request('Member.Connection.Approve', session, options))
|
178
|
-
response_valid? response
|
179
|
-
end
|
180
|
-
|
181
|
-
# Creates An XML Body for submission with a file to the authenticated member's media gallery.
|
182
|
-
# Valid files must be an RGB image in GIF, JPEG or PNG format.
|
183
|
-
# API requests must be submitted as multipart/form-data with the XML API request submitted in the named field value
|
184
|
-
# XMLMessage. This function returns a string that can be embedded as this field value.
|
185
|
-
#
|
186
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_MediaGallery_Upload.htm
|
187
|
-
#
|
188
|
-
# @param [YourMembership::Session] session
|
189
|
-
# @param [Hash] options
|
190
|
-
# @option options [Integer] :AlbumID AlbumID of the media gallery item to submit to.
|
191
|
-
# @option options [String] :Caption Caption to be associated with the media gallery item. (Limited to 150 Chars.)
|
192
|
-
# @option options [String] :AllowComments Setting for allowing comments. Available values are:
|
193
|
-
# :all = Comments are allowed
|
194
|
-
# :connections = Comments limited to a member's connections
|
195
|
-
# :none = Comments not allowed
|
196
|
-
# @option options [Boolean] :IsPublic Setting for allowing anonymous visitors to view uploaded photos for public
|
197
|
-
# member types. True makes the image visible to everyone, False makes the image only available to Members.
|
198
|
-
# @return [String] This string should be submitted as the XMLMessage field in a multipart/form-data post to
|
199
|
-
# https://api.yourmembership.com/
|
200
|
-
def self.mediaGallery_upload(session, options = {}) # rubocop:disable Style/MethodName
|
201
|
-
build_XML_request('Member.MediaGallery.Upload', session, options)
|
202
|
-
end
|
203
|
-
|
204
|
-
# Returns a list of messages from the authenticated member's Inbox. Returns a maximum of 100 records per request.
|
205
|
-
#
|
206
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Messages_GetInbox.htm
|
207
|
-
#
|
208
|
-
# @param [YourMembership::Session] session
|
209
|
-
# @param [Hash] options
|
210
|
-
# @option options [Integer] :PageSize The maximum number of records in the returned result set.
|
211
|
-
# @option options [Integer] :StartRecord The record number at which to start the returned result set.
|
212
|
-
# @return [Array] Returns an Array of Hashes representing a member's inbox messages
|
213
|
-
#
|
214
|
-
# @note BUG WORKAROUND: The API documentation indicates that GetInbox should return an <GetInbox> XML structure, but
|
215
|
-
# instead it returns <Get.Inbox>
|
216
|
-
def self.messages_getInbox(session, options = {}) # rubocop:disable Style/MethodName
|
217
|
-
response = post('/', :body => build_XML_request('Member.Messages.GetInbox', session, options))
|
218
|
-
|
219
|
-
response_valid? response
|
220
|
-
response_to_array_of_hashes response['YourMembership_Response']['Members.Messages.Get.Inbox'], ['Message']
|
221
|
-
end
|
222
|
-
|
223
|
-
# Returns a list of messages from the authenticated member's Sent folder, Returns a maximum of 100 records per
|
224
|
-
# request.
|
225
|
-
#
|
226
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Messages_GetSent.htm
|
227
|
-
#
|
228
|
-
# @param [YourMembership::Session] session
|
229
|
-
# @param [Hash] options
|
230
|
-
# @option options [Integer] :PageSize The maximum number of records in the returned result set.
|
231
|
-
# @option options [Integer] :StartRecord The record number at which to start the returned result set.
|
232
|
-
# @return [Array] Returns an Array of Hashes representing a member's sent messages
|
233
|
-
#
|
234
|
-
# @note BUG WORKAROUND: The API documentation indicates that GetInbox should return an <GetSent> XML structure, but
|
235
|
-
# instead it returns <Get.Sent>
|
236
|
-
def self.messages_getSent(session, options = {}) # rubocop:disable Style/MethodName
|
237
|
-
response = post('/', :body => build_XML_request('Member.Messages.GetSent', session, options))
|
238
|
-
|
239
|
-
response_valid? response
|
240
|
-
response_to_array_of_hashes response['YourMembership_Response']['Members.Messages.Get.Sent'], ['Message']
|
241
|
-
end
|
242
|
-
|
243
|
-
# Returns an individual message by MessageID and marks it as read.
|
244
|
-
#
|
245
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Messages_Message_Read.htm
|
246
|
-
#
|
247
|
-
# @param [YourMembership::Session] session
|
248
|
-
# @param [Integer] message_id The ID of the Message to be returned.
|
249
|
-
# @return [Hash] Returns a has of all of the message's fields.
|
250
|
-
def self.messages_message_read(session, message_id)
|
251
|
-
options = {}
|
252
|
-
options[:MessageID] = message_id
|
253
|
-
response = post('/', :body => build_XML_request('Member.Messages.Message.Read', session, options))
|
254
|
-
|
255
|
-
response_valid? response
|
256
|
-
# Note that the response key is not the same as the request key, this could just be a typo in the API
|
257
|
-
response['YourMembership_Response']['Members.Messages.Message.Read']['Message']
|
258
|
-
end
|
259
|
-
|
260
|
-
# Message a member.
|
261
|
-
#
|
262
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Messages_Message_Send.htm
|
263
|
-
#
|
264
|
-
# @param [YourMembership::Session] session
|
265
|
-
# @param [String] member_id ID or ProfileID of the member to send a message.
|
266
|
-
# @param [String] subject Subject line of the message.
|
267
|
-
# @param [String] body Body of the message.
|
268
|
-
# @return [Boolean] True if successful
|
269
|
-
def self.messages_message_send(session, member_id, subject, body)
|
270
|
-
options = {}
|
271
|
-
options[:ID] = member_id
|
272
|
-
options[:Subject] = subject
|
273
|
-
options[:Body] = body
|
274
|
-
response = post('/', :body => build_XML_request('Member.Messages.Message.Send', session, options))
|
275
|
-
response_valid? response
|
276
|
-
end
|
277
|
-
|
278
|
-
# Upon validating Username or Email Address given, sends an email to matching members with a link needed to reset
|
279
|
-
# their password. This method does not require authentication.
|
280
|
-
#
|
281
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Password_InitializeReset.htm
|
282
|
-
#
|
283
|
-
# @param [YourMembership::Session] session
|
284
|
-
# @param [Hash] options
|
285
|
-
# @option options [String] :Username Username of the member
|
286
|
-
# @option options [String] :EmailAddress Email Address of the member
|
287
|
-
# @return [Boolean] Returns True if successful
|
288
|
-
def self.password_initializeReset(session, options = {}) # rubocop:disable Style/MethodName
|
289
|
-
response = post('/', :body => build_XML_request('Member.Password.InitializeReset', session, options))
|
290
|
-
response_valid? response
|
291
|
-
end
|
292
|
-
|
293
|
-
# After validating ResetToken or CurrentPassword given, this method updates the associated member's password to the
|
294
|
-
# new value. This method requires Authentication only when passing in CurrentPassword parameter.
|
295
|
-
#
|
296
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Password_Update.htm
|
297
|
-
#
|
298
|
-
# @param [YourMembership::Session] session
|
299
|
-
# @param [String] new_password The new password to use.
|
300
|
-
# @param [Hash] options
|
301
|
-
# @option options [String] :CurrentPassword Member's current password. The API request must be Authenticated when
|
302
|
-
# using this parameter. Used when members are signed in, but want to change their password.
|
303
|
-
# @option options [String] :ResetToken Reset Token from the Password Reset email.
|
304
|
-
# @return [Boolean] Returns True if successful
|
305
|
-
def self.password_update(session, new_password, options = {})
|
306
|
-
options[:NewPassword] = new_password
|
307
|
-
response = post('/', :body => build_XML_request('Member.Password.Update', session, options))
|
308
|
-
response_valid? response
|
309
|
-
end
|
310
|
-
|
311
|
-
# Returns the authenticated member's profile data.
|
312
|
-
#
|
313
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Profile_Get.htm
|
314
|
-
#
|
315
|
-
# @param [YourMembership::Session] session
|
316
|
-
# @return [YourMembership::Profile] Returns a Profile object that represents the person's profile
|
317
|
-
def self.profile_get(session)
|
318
|
-
response = post('/', :body => build_XML_request('Member.Profile.Get', session))
|
319
|
-
|
320
|
-
response_valid? response
|
321
|
-
YourMembership::Profile.new response['YourMembership_Response']['Member.Profile.Get']
|
322
|
-
end
|
323
|
-
|
324
|
-
# Returns a subset of the authenticated member's profile data along with statistics and permissions for the purpose
|
325
|
-
# of creating a profile snapshot and navigation control.
|
326
|
-
#
|
327
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Profile_Get.htm
|
328
|
-
#
|
329
|
-
# @param [YourMembership::Session] session
|
330
|
-
# @return [Hash] Returns a Hash of details and permissions for the authenticated user.
|
331
|
-
def self.profile_getMini(session) # rubocop:disable Style/MethodName
|
332
|
-
response = post('/', :body => build_XML_request('Member.Profile.GetMini', session))
|
333
|
-
|
334
|
-
response_valid? response
|
335
|
-
response['YourMembership_Response']['Member.Profile.GetMini']
|
336
|
-
end
|
337
|
-
|
338
|
-
# Post to a member's wall.
|
339
|
-
#
|
340
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_Wall_Post.htm
|
341
|
-
#
|
342
|
-
# @param [YourMembership::Session] session
|
343
|
-
# @param [String] post_text Text to post on the member's wall.
|
344
|
-
# @param [String] id ID or ProfileID of any member that is connected to the authenticated member whose wall to post
|
345
|
-
# on. Omit this argument to post on the authenticated member's own wall.
|
346
|
-
# @return [Boolean] True if successful
|
347
|
-
def self.wall_post(session, post_text, id = nil)
|
348
|
-
options = {}
|
349
|
-
options[:ID] = id if id
|
350
|
-
options[:PostText] = post_text
|
351
|
-
response = post('/', :body => build_XML_request('Member.Wall.Post', session, options))
|
352
|
-
response_valid? response
|
353
|
-
end
|
354
|
-
|
355
|
-
# Validates that the current session has been authenticated by returning the authenticated member's ID.
|
356
|
-
#
|
357
|
-
# @see https://api.yourmembership.com/reference/2_00/Member_IsAuthenticated.htm
|
358
|
-
#
|
359
|
-
# @param [YourMembership::Session] session
|
360
|
-
# @return [String] if provided session is authenticated returns the members's ID
|
361
|
-
# @return [Nil] if provided session is not authenticated
|
362
|
-
# returns nil.
|
363
|
-
def self.isAuthenticated(session) # rubocop:disable Style/MethodName
|
364
|
-
response = post('/', :body => build_XML_request('Member.IsAuthenticated', session))
|
365
|
-
|
366
|
-
# Fail on HTTP Errors
|
367
|
-
raise HTTParty::ResponseError.new(response), 'Connection to YourMembership API failed.' unless response.success?
|
368
|
-
|
369
|
-
error_code = response['YourMembership_Response']['ErrCode']
|
370
|
-
|
371
|
-
# Error Code 202 means that the session itself has expired, we don't
|
372
|
-
# want to throw an exception for that, just return that the session is
|
373
|
-
# not authenticated.
|
374
|
-
return nil if error_code == '202'
|
375
|
-
|
376
|
-
# Error Code 403 means that the method requires Authentication, if the
|
377
|
-
# call is not authenticated then the session cannot be authenticated.
|
378
|
-
return nil if error_code == '403'
|
379
|
-
|
380
|
-
# All Error Codes
|
381
|
-
# we need to raise an exception for.
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
# The member object provides a convenient abstraction that encapsulates the member methods and caches some basic
|
3
|
+
# details about the member.
|
4
|
+
#
|
5
|
+
# @attr_reader [String] id The API ID of the member.
|
6
|
+
# @attr_reader [String] website_id The WebsiteID of the member which is used to construct urls for member navigation.
|
7
|
+
# @attr_reader [String] full_name The COMPUTED full_name of the member. This is implemented through the full_name
|
8
|
+
# method so as to allow this method to be easily overridden if a different format is desired.
|
9
|
+
# @attr [String] first_name The First Name of the member.
|
10
|
+
# @attr [String] last_name The Last Name of the member.
|
11
|
+
# @attr [String] email The email address associated with the member.
|
12
|
+
# @attr [YourMembership::Session] session The Session object bound to this member through authentication.
|
13
|
+
# @attr [YourMembership::Profile] profile A session object bound to this member object. This must be set manually.
|
14
|
+
class Member < YourMembership::Base
|
15
|
+
attr_reader :id, :website_id
|
16
|
+
attr_accessor :first_name, :last_name, :email, :session, :profile
|
17
|
+
|
18
|
+
# Member Initializer - Use Member.create_from_session or Member.create_by_authentication to instantiate
|
19
|
+
# objects of this type.
|
20
|
+
#
|
21
|
+
# @note There is not yet a compelling reason to call Member.new() directly, however it can be done.
|
22
|
+
#
|
23
|
+
# @param [String] id The API ID of the member.
|
24
|
+
# @param [String] website_id The WebsiteID of the member which is used to construct urls for member navigation.
|
25
|
+
# @param [String] first_name The First Name of the member.
|
26
|
+
# @param [String] last_name The Last Name of the member.
|
27
|
+
# @param [String] email The email address associated with the member.
|
28
|
+
# @param [YourMembership::Session, Nil] session The Session object bound to this member through authentication.
|
29
|
+
def initialize(id, website_id, first_name, last_name, email, session = nil)
|
30
|
+
@id = id
|
31
|
+
@website_id = website_id
|
32
|
+
@first_name = first_name
|
33
|
+
@last_name = last_name
|
34
|
+
@email = email
|
35
|
+
@session = session
|
36
|
+
@profile = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# Format name parts in to a full name string.
|
40
|
+
# If you wish different behavior (perhaps 'last_name, first_name') this method should be overridden.
|
41
|
+
#
|
42
|
+
# @return [string] Returns a formatted name.
|
43
|
+
def full_name
|
44
|
+
@first_name + ' ' + @last_name
|
45
|
+
end
|
46
|
+
|
47
|
+
# Allow an instance to call all class methods (unless they are specifically restricted) and pass the session and
|
48
|
+
# arguments of the current object.
|
49
|
+
def method_missing(name, *args)
|
50
|
+
if [:create_by_authentication, :create_from_session].include? name
|
51
|
+
raise NoMethodError.new("Cannot call method #{name} on class #{self.class} because it is specifically denied.", 'Method Protected')
|
52
|
+
else
|
53
|
+
self.class.send(name, @session, *args)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Creates a new Member object through username and password authentication.
|
58
|
+
# @param [String] username The username in cleartext
|
59
|
+
# @param [String] password The password in cleartext
|
60
|
+
# @return [YourMembership::Member] Returns a new Member object with associated authenticated Session object
|
61
|
+
def self.create_by_authentication(username, password)
|
62
|
+
session = YourMembership::Session.create username, password
|
63
|
+
create_from_session(session)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Creates a new Member object from a previously authenticated Session object.
|
67
|
+
# @param [YourMembership::Session] session A previously authenticated Session.
|
68
|
+
# @return [YourMembership::Member] Returns a new Member object
|
69
|
+
def self.create_from_session(session)
|
70
|
+
profile = profile_getMini session
|
71
|
+
new(
|
72
|
+
profile['ID'],
|
73
|
+
profile['WebsiteID'],
|
74
|
+
profile['FirstName'],
|
75
|
+
profile['LastName'],
|
76
|
+
profile['EmailAddr'],
|
77
|
+
session
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns a list of Certifications for the specified user.
|
82
|
+
#
|
83
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Certifications_Get.htm
|
84
|
+
#
|
85
|
+
# @param [YourMembership::Session] session
|
86
|
+
# @param [Hash] options
|
87
|
+
# @option options [Boolean] :IsArchived Include archived certification records in the returned result. Default: True
|
88
|
+
#
|
89
|
+
# @return [Array] An Array of Hashes representing the Certifications of the authenticated user.
|
90
|
+
def self.certifications_get(session, options = {})
|
91
|
+
response = post('/', :body => build_XML_request('Member.Certifications.Get', session, options))
|
92
|
+
|
93
|
+
response_valid? response
|
94
|
+
response_to_array_of_hashes response['YourMembership_Response']['Member.Certifications.Get'], ['Certification']
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns a list of Certification Journal Entries for the signed in user that may be optionally filterd by date,
|
98
|
+
# expiration, and paging.
|
99
|
+
#
|
100
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Certifications_Journal_Get.htm
|
101
|
+
#
|
102
|
+
# @param [YourMembership::Session] session
|
103
|
+
# @param [Hash] options
|
104
|
+
# @option options [Boolean] :ShowExpired Include expired journal entries in the returned result.
|
105
|
+
# @option options [DateTime] :StartDate Only include Journal Entries that are newer that the supplied date.
|
106
|
+
# @option options [Integer] :EntryID Filter the returned results by sequential EntryID. Only those Certification
|
107
|
+
# Journals which have an EntryID greater than the supplied integer will be returned.
|
108
|
+
# @option options [String] :CertificationID Filter the Journal Entries returned by the specified Certification ID.
|
109
|
+
# @option options [Integer] :PageSize The number of items that are returned per call of this method.
|
110
|
+
# Default is 200 entries.
|
111
|
+
# @option options [Integer] :PageNumber PageNumber can be used to retrieve multiple result sets.
|
112
|
+
# Page 1 is returned by default.
|
113
|
+
#
|
114
|
+
# @return [Array] An Array of Hashes representing the Certification Journal Entries of the authenticated user.
|
115
|
+
def self.certifications_journal_get(session, options = {})
|
116
|
+
response = post('/', :body => build_XML_request('Member.Certifications.Journal.Get', session, options))
|
117
|
+
|
118
|
+
response_valid? response
|
119
|
+
response_to_array_of_hashes response['YourMembership_Response']['Member.Certifications.Journal.Get'], ['Entry']
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns a list of order IDs for the authenticated user that may be optionally filtered by timestamp and status.
|
123
|
+
#
|
124
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Commerce_Store_GetOrderIDs.htm
|
125
|
+
#
|
126
|
+
# @param [YourMembership::Session] session
|
127
|
+
# @param [Hash] options
|
128
|
+
# @option options [DateTime] :Timestamp Filter the returned results by date/time. Only those orders which were
|
129
|
+
# placed after the supplied date/time will be returned.
|
130
|
+
# @option options [Symbol, Integer] :Status Filter the returned results by Status.
|
131
|
+
# (-1 = :Cancelled; 0 = :open; 1 = :processed; 2 = :shipped or :closed)
|
132
|
+
#
|
133
|
+
# @return [Array] A list of Invoice Id Strings for the authenticated user.
|
134
|
+
def self.commerce_store_getOrderIDs(session, options = {}) # rubocop:disable Style/MethodName
|
135
|
+
if options[:Status]
|
136
|
+
options[:Status] = YourMembership::Commerce.convert_order_status(options[:Status])
|
137
|
+
end
|
138
|
+
|
139
|
+
response = post('/', :body => build_XML_request('Member.Commerce.Store.GetOrderIDs', session, options))
|
140
|
+
|
141
|
+
response_valid? response
|
142
|
+
response_to_array response['YourMembership_Response']['Member.Commerce.Store.GetOrderIDs']['Orders'], ['Order'], 'InvoiceID'
|
143
|
+
end
|
144
|
+
|
145
|
+
# Returns the order details, including line items and products ordered, of a store order placed by the authenticated
|
146
|
+
# member.
|
147
|
+
#
|
148
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Commerce_Store_Order_Get.htm
|
149
|
+
#
|
150
|
+
# @param [YourMembership::Session] session
|
151
|
+
# @param [String] invoiceID The Invoice ID of the store order to be returned.
|
152
|
+
# @return [Hash] Returns a Hash representing a users order referenced by the invoiceID
|
153
|
+
#
|
154
|
+
# @note This method depends on the HTTParty Monkey Patch that HTML Decodes response bodies before parsing.
|
155
|
+
# YourMembership returns invalid XML when embedding <![CDATA] elements.
|
156
|
+
def self.commerce_store_order_get(session, invoiceID)
|
157
|
+
options = {}
|
158
|
+
options[:InvoiceID] = invoiceID
|
159
|
+
|
160
|
+
response = post('/', :body => build_XML_request('Member.Commerce.Store.Order.Get', session, options))
|
161
|
+
|
162
|
+
response_valid? response
|
163
|
+
response_to_array_of_hashes response['YourMembership_Response']['Member.Commerce.Store.Order.Get'], ['Order']
|
164
|
+
end
|
165
|
+
|
166
|
+
# Approves or declines a connection request.
|
167
|
+
#
|
168
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Connection_Approve.htm
|
169
|
+
#
|
170
|
+
# @param [YourMembership::Session] session
|
171
|
+
# @param [String] id ID or Profile ID of the member to approve/decline.
|
172
|
+
# @param [Boolean] approve 0 or 1 to decline or approve a connection 0 = Decline, 1 = Approve
|
173
|
+
def self.connection_approve(session, id, approve)
|
174
|
+
options = {}
|
175
|
+
options[:ID] = id
|
176
|
+
options[:Approve] = approve
|
177
|
+
response = post('/', :body => build_XML_request('Member.Connection.Approve', session, options))
|
178
|
+
response_valid? response
|
179
|
+
end
|
180
|
+
|
181
|
+
# Creates An XML Body for submission with a file to the authenticated member's media gallery.
|
182
|
+
# Valid files must be an RGB image in GIF, JPEG or PNG format.
|
183
|
+
# API requests must be submitted as multipart/form-data with the XML API request submitted in the named field value
|
184
|
+
# XMLMessage. This function returns a string that can be embedded as this field value.
|
185
|
+
#
|
186
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_MediaGallery_Upload.htm
|
187
|
+
#
|
188
|
+
# @param [YourMembership::Session] session
|
189
|
+
# @param [Hash] options
|
190
|
+
# @option options [Integer] :AlbumID AlbumID of the media gallery item to submit to.
|
191
|
+
# @option options [String] :Caption Caption to be associated with the media gallery item. (Limited to 150 Chars.)
|
192
|
+
# @option options [String] :AllowComments Setting for allowing comments. Available values are:
|
193
|
+
# :all = Comments are allowed
|
194
|
+
# :connections = Comments limited to a member's connections
|
195
|
+
# :none = Comments not allowed
|
196
|
+
# @option options [Boolean] :IsPublic Setting for allowing anonymous visitors to view uploaded photos for public
|
197
|
+
# member types. True makes the image visible to everyone, False makes the image only available to Members.
|
198
|
+
# @return [String] This string should be submitted as the XMLMessage field in a multipart/form-data post to
|
199
|
+
# https://api.yourmembership.com/
|
200
|
+
def self.mediaGallery_upload(session, options = {}) # rubocop:disable Style/MethodName
|
201
|
+
build_XML_request('Member.MediaGallery.Upload', session, options)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Returns a list of messages from the authenticated member's Inbox. Returns a maximum of 100 records per request.
|
205
|
+
#
|
206
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Messages_GetInbox.htm
|
207
|
+
#
|
208
|
+
# @param [YourMembership::Session] session
|
209
|
+
# @param [Hash] options
|
210
|
+
# @option options [Integer] :PageSize The maximum number of records in the returned result set.
|
211
|
+
# @option options [Integer] :StartRecord The record number at which to start the returned result set.
|
212
|
+
# @return [Array] Returns an Array of Hashes representing a member's inbox messages
|
213
|
+
#
|
214
|
+
# @note BUG WORKAROUND: The API documentation indicates that GetInbox should return an <GetInbox> XML structure, but
|
215
|
+
# instead it returns <Get.Inbox>
|
216
|
+
def self.messages_getInbox(session, options = {}) # rubocop:disable Style/MethodName
|
217
|
+
response = post('/', :body => build_XML_request('Member.Messages.GetInbox', session, options))
|
218
|
+
|
219
|
+
response_valid? response
|
220
|
+
response_to_array_of_hashes response['YourMembership_Response']['Members.Messages.Get.Inbox'], ['Message']
|
221
|
+
end
|
222
|
+
|
223
|
+
# Returns a list of messages from the authenticated member's Sent folder, Returns a maximum of 100 records per
|
224
|
+
# request.
|
225
|
+
#
|
226
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Messages_GetSent.htm
|
227
|
+
#
|
228
|
+
# @param [YourMembership::Session] session
|
229
|
+
# @param [Hash] options
|
230
|
+
# @option options [Integer] :PageSize The maximum number of records in the returned result set.
|
231
|
+
# @option options [Integer] :StartRecord The record number at which to start the returned result set.
|
232
|
+
# @return [Array] Returns an Array of Hashes representing a member's sent messages
|
233
|
+
#
|
234
|
+
# @note BUG WORKAROUND: The API documentation indicates that GetInbox should return an <GetSent> XML structure, but
|
235
|
+
# instead it returns <Get.Sent>
|
236
|
+
def self.messages_getSent(session, options = {}) # rubocop:disable Style/MethodName
|
237
|
+
response = post('/', :body => build_XML_request('Member.Messages.GetSent', session, options))
|
238
|
+
|
239
|
+
response_valid? response
|
240
|
+
response_to_array_of_hashes response['YourMembership_Response']['Members.Messages.Get.Sent'], ['Message']
|
241
|
+
end
|
242
|
+
|
243
|
+
# Returns an individual message by MessageID and marks it as read.
|
244
|
+
#
|
245
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Messages_Message_Read.htm
|
246
|
+
#
|
247
|
+
# @param [YourMembership::Session] session
|
248
|
+
# @param [Integer] message_id The ID of the Message to be returned.
|
249
|
+
# @return [Hash] Returns a has of all of the message's fields.
|
250
|
+
def self.messages_message_read(session, message_id)
|
251
|
+
options = {}
|
252
|
+
options[:MessageID] = message_id
|
253
|
+
response = post('/', :body => build_XML_request('Member.Messages.Message.Read', session, options))
|
254
|
+
|
255
|
+
response_valid? response
|
256
|
+
# Note that the response key is not the same as the request key, this could just be a typo in the API
|
257
|
+
response['YourMembership_Response']['Members.Messages.Message.Read']['Message']
|
258
|
+
end
|
259
|
+
|
260
|
+
# Message a member.
|
261
|
+
#
|
262
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Messages_Message_Send.htm
|
263
|
+
#
|
264
|
+
# @param [YourMembership::Session] session
|
265
|
+
# @param [String] member_id ID or ProfileID of the member to send a message.
|
266
|
+
# @param [String] subject Subject line of the message.
|
267
|
+
# @param [String] body Body of the message.
|
268
|
+
# @return [Boolean] True if successful
|
269
|
+
def self.messages_message_send(session, member_id, subject, body)
|
270
|
+
options = {}
|
271
|
+
options[:ID] = member_id
|
272
|
+
options[:Subject] = subject
|
273
|
+
options[:Body] = body
|
274
|
+
response = post('/', :body => build_XML_request('Member.Messages.Message.Send', session, options))
|
275
|
+
response_valid? response
|
276
|
+
end
|
277
|
+
|
278
|
+
# Upon validating Username or Email Address given, sends an email to matching members with a link needed to reset
|
279
|
+
# their password. This method does not require authentication.
|
280
|
+
#
|
281
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Password_InitializeReset.htm
|
282
|
+
#
|
283
|
+
# @param [YourMembership::Session] session
|
284
|
+
# @param [Hash] options
|
285
|
+
# @option options [String] :Username Username of the member
|
286
|
+
# @option options [String] :EmailAddress Email Address of the member
|
287
|
+
# @return [Boolean] Returns True if successful
|
288
|
+
def self.password_initializeReset(session, options = {}) # rubocop:disable Style/MethodName
|
289
|
+
response = post('/', :body => build_XML_request('Member.Password.InitializeReset', session, options))
|
290
|
+
response_valid? response
|
291
|
+
end
|
292
|
+
|
293
|
+
# After validating ResetToken or CurrentPassword given, this method updates the associated member's password to the
|
294
|
+
# new value. This method requires Authentication only when passing in CurrentPassword parameter.
|
295
|
+
#
|
296
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Password_Update.htm
|
297
|
+
#
|
298
|
+
# @param [YourMembership::Session] session
|
299
|
+
# @param [String] new_password The new password to use.
|
300
|
+
# @param [Hash] options
|
301
|
+
# @option options [String] :CurrentPassword Member's current password. The API request must be Authenticated when
|
302
|
+
# using this parameter. Used when members are signed in, but want to change their password.
|
303
|
+
# @option options [String] :ResetToken Reset Token from the Password Reset email.
|
304
|
+
# @return [Boolean] Returns True if successful
|
305
|
+
def self.password_update(session, new_password, options = {})
|
306
|
+
options[:NewPassword] = new_password
|
307
|
+
response = post('/', :body => build_XML_request('Member.Password.Update', session, options))
|
308
|
+
response_valid? response
|
309
|
+
end
|
310
|
+
|
311
|
+
# Returns the authenticated member's profile data.
|
312
|
+
#
|
313
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Profile_Get.htm
|
314
|
+
#
|
315
|
+
# @param [YourMembership::Session] session
|
316
|
+
# @return [YourMembership::Profile] Returns a Profile object that represents the person's profile
|
317
|
+
def self.profile_get(session)
|
318
|
+
response = post('/', :body => build_XML_request('Member.Profile.Get', session))
|
319
|
+
|
320
|
+
response_valid? response
|
321
|
+
YourMembership::Profile.new response['YourMembership_Response']['Member.Profile.Get']
|
322
|
+
end
|
323
|
+
|
324
|
+
# Returns a subset of the authenticated member's profile data along with statistics and permissions for the purpose
|
325
|
+
# of creating a profile snapshot and navigation control.
|
326
|
+
#
|
327
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Profile_Get.htm
|
328
|
+
#
|
329
|
+
# @param [YourMembership::Session] session
|
330
|
+
# @return [Hash] Returns a Hash of details and permissions for the authenticated user.
|
331
|
+
def self.profile_getMini(session) # rubocop:disable Style/MethodName
|
332
|
+
response = post('/', :body => build_XML_request('Member.Profile.GetMini', session))
|
333
|
+
|
334
|
+
response_valid? response
|
335
|
+
response['YourMembership_Response']['Member.Profile.GetMini']
|
336
|
+
end
|
337
|
+
|
338
|
+
# Post to a member's wall.
|
339
|
+
#
|
340
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_Wall_Post.htm
|
341
|
+
#
|
342
|
+
# @param [YourMembership::Session] session
|
343
|
+
# @param [String] post_text Text to post on the member's wall.
|
344
|
+
# @param [String] id ID or ProfileID of any member that is connected to the authenticated member whose wall to post
|
345
|
+
# on. Omit this argument to post on the authenticated member's own wall.
|
346
|
+
# @return [Boolean] True if successful
|
347
|
+
def self.wall_post(session, post_text, id = nil)
|
348
|
+
options = {}
|
349
|
+
options[:ID] = id if id
|
350
|
+
options[:PostText] = post_text
|
351
|
+
response = post('/', :body => build_XML_request('Member.Wall.Post', session, options))
|
352
|
+
response_valid? response
|
353
|
+
end
|
354
|
+
|
355
|
+
# Validates that the current session has been authenticated by returning the authenticated member's ID.
|
356
|
+
#
|
357
|
+
# @see https://api.yourmembership.com/reference/2_00/Member_IsAuthenticated.htm
|
358
|
+
#
|
359
|
+
# @param [YourMembership::Session] session
|
360
|
+
# @return [String] if provided session is authenticated returns the members's ID
|
361
|
+
# @return [Nil] if provided session is not authenticated
|
362
|
+
# returns nil.
|
363
|
+
def self.isAuthenticated(session) # rubocop:disable Style/MethodName
|
364
|
+
response = post('/', :body => build_XML_request('Member.IsAuthenticated', session))
|
365
|
+
|
366
|
+
# Fail on HTTP Errors
|
367
|
+
raise HTTParty::ResponseError.new(response), 'Connection to YourMembership API failed.' unless response.success?
|
368
|
+
|
369
|
+
error_code = response['YourMembership_Response']['ErrCode']
|
370
|
+
|
371
|
+
# Error Code 202 means that the session itself has expired, we don't
|
372
|
+
# want to throw an exception for that, just return that the session is
|
373
|
+
# not authenticated.
|
374
|
+
return nil if error_code == '202'
|
375
|
+
|
376
|
+
# Error Code 403 means that the method requires Authentication, if the
|
377
|
+
# call is not authenticated then the session cannot be authenticated.
|
378
|
+
return nil if error_code == '403'
|
379
|
+
|
380
|
+
# All other non-zero Error Codes indicate an unrecoverable issue that
|
381
|
+
# we need to raise an exception for.
|
382
|
+
if error_code != '0'
|
383
|
+
raise YourMembership::Error.new(
|
384
|
+
response['YourMembership_Response']['ErrCode'],
|
385
|
+
response['YourMembership_Response']['ErrDesc']
|
386
|
+
)
|
387
|
+
end
|
388
|
+
|
389
|
+
if response['YourMembership_Response']['Member.IsAuthenticated']
|
390
|
+
# If everything is ok retun the authenticated users ID
|
391
|
+
return response['YourMembership_Response']['Member.IsAuthenticated']['ID']
|
392
|
+
else
|
393
|
+
# If there is no ID in the data returned then the session is not
|
394
|
+
# authenticated.
|
395
|
+
nil
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|