your_membership 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,41 +1,41 @@
|
|
1
|
-
module YourMembership
|
2
|
-
module Sa
|
3
|
-
# YourMembership System Administrator Members Namespace
|
4
|
-
class NonMembers < YourMembership::Base
|
5
|
-
# Returns a list of non-member IDs that may be optionally filtered by timestamp. This method is provided for data
|
6
|
-
# synchronization purposes and will return a maximum of 10,000 results. It would typically be used in conjunction
|
7
|
-
# with subsequent calls to Sa.People.Profile.Get for each ID returned.
|
8
|
-
#
|
9
|
-
# @see https://api.yourmembership.com/reference/2_00/Sa_NonMembers_All_GetIDs.htm
|
10
|
-
#
|
11
|
-
# @param [Hash] options
|
12
|
-
# @option options [DateTime] :Timestamp Only accounts created after the this time will be returned
|
13
|
-
# @option options [String] :WebsiteID Filter the returned results by sequential WebsiteID.
|
14
|
-
# @option options [Array] :Groups Filter the returned results by group membership. [key, value] will translate to
|
15
|
-
# <key>value</key>
|
16
|
-
#
|
17
|
-
# @return [Array] A list of API IDs for non-members in your community.
|
18
|
-
def self.all_getIDs(options = {}) # rubocop:disable Style/MethodName
|
19
|
-
response = post('/', :body => build_XML_request('Sa.NonMembers.All.GetIDs', nil, options))
|
20
|
-
response_valid? response
|
21
|
-
response['YourMembership_Response']['Sa.NonMembers.All.GetIDs']['NonMembers']['ID']
|
22
|
-
end
|
23
|
-
|
24
|
-
# Creates a new non-member profile and returns the new non-member's ID and WebsiteID. The returned ID must be
|
25
|
-
# supplied when performing future updates to the non-member's profile. The returned WebsiteID represents the
|
26
|
-
# numeric identifier used by the YourMembership.com application for navigation purposes.
|
27
|
-
#
|
28
|
-
# @see https://api.yourmembership.com/reference/2_00/Sa_NonMembers_Profile_Create.htm
|
29
|
-
#
|
30
|
-
# @param [YourMembership::Profile] profile
|
31
|
-
# @return [Hash] The ID and WebsiteID of the nonmember created
|
32
|
-
def self.profile_create(profile)
|
33
|
-
options = {}
|
34
|
-
options['profile'] = profile
|
35
|
-
response = post('/', :body => build_XML_request('Sa.NonMembers.Profile.Create', nil, options))
|
36
|
-
response_valid? response
|
37
|
-
response['YourMembership_Response']['Sa.NonMembers.Profile.Create']
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
module Sa
|
3
|
+
# YourMembership System Administrator Members Namespace
|
4
|
+
class NonMembers < YourMembership::Base
|
5
|
+
# Returns a list of non-member IDs that may be optionally filtered by timestamp. This method is provided for data
|
6
|
+
# synchronization purposes and will return a maximum of 10,000 results. It would typically be used in conjunction
|
7
|
+
# with subsequent calls to Sa.People.Profile.Get for each ID returned.
|
8
|
+
#
|
9
|
+
# @see https://api.yourmembership.com/reference/2_00/Sa_NonMembers_All_GetIDs.htm
|
10
|
+
#
|
11
|
+
# @param [Hash] options
|
12
|
+
# @option options [DateTime] :Timestamp Only accounts created after the this time will be returned
|
13
|
+
# @option options [String] :WebsiteID Filter the returned results by sequential WebsiteID.
|
14
|
+
# @option options [Array] :Groups Filter the returned results by group membership. [key, value] will translate to
|
15
|
+
# <key>value</key>
|
16
|
+
#
|
17
|
+
# @return [Array] A list of API IDs for non-members in your community.
|
18
|
+
def self.all_getIDs(options = {}) # rubocop:disable Style/MethodName
|
19
|
+
response = post('/', :body => build_XML_request('Sa.NonMembers.All.GetIDs', nil, options))
|
20
|
+
response_valid? response
|
21
|
+
response['YourMembership_Response']['Sa.NonMembers.All.GetIDs']['NonMembers']['ID']
|
22
|
+
end
|
23
|
+
|
24
|
+
# Creates a new non-member profile and returns the new non-member's ID and WebsiteID. The returned ID must be
|
25
|
+
# supplied when performing future updates to the non-member's profile. The returned WebsiteID represents the
|
26
|
+
# numeric identifier used by the YourMembership.com application for navigation purposes.
|
27
|
+
#
|
28
|
+
# @see https://api.yourmembership.com/reference/2_00/Sa_NonMembers_Profile_Create.htm
|
29
|
+
#
|
30
|
+
# @param [YourMembership::Profile] profile
|
31
|
+
# @return [Hash] The ID and WebsiteID of the nonmember created
|
32
|
+
def self.profile_create(profile)
|
33
|
+
options = {}
|
34
|
+
options['profile'] = profile
|
35
|
+
response = post('/', :body => build_XML_request('Sa.NonMembers.Profile.Create', nil, options))
|
36
|
+
response_valid? response
|
37
|
+
response['YourMembership_Response']['Sa.NonMembers.Profile.Create']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,92 +1,92 @@
|
|
1
|
-
module YourMembership
|
2
|
-
module Sa
|
3
|
-
# YourMembership System Administrator Members Namespace
|
4
|
-
class People < YourMembership::Base
|
5
|
-
# Returns a list of member and non-member IDs that may be optionally filtered by timestamp. This method is
|
6
|
-
# provided for data synchronization purposes and will return a maximum of 10,000 results. It would typically be
|
7
|
-
# used in conjunction with subsequent calls to Sa.People.Profile.Get for each ID returned
|
8
|
-
#
|
9
|
-
# @see https://api.yourmembership.com/reference/2_00/Sa_People_All_GetIDs.htm
|
10
|
-
#
|
11
|
-
# @param [Hash] options
|
12
|
-
# @option options [DateTime] :Timestamp Only accounts created after the this time will be returned
|
13
|
-
# @option options [String] :WebsiteID Filter the returned results by sequential WebsiteID.
|
14
|
-
# @option options [Array] :Groups Filter the returned results by group membership. [key, value] will translate to
|
15
|
-
# <key>value</key>
|
16
|
-
#
|
17
|
-
# @return [Array] A list of API IDs for non-members in your community.
|
18
|
-
def self.all_getIDs(options = {}) # rubocop:disable Style/MethodName
|
19
|
-
response = post('/', :body => build_XML_request('Sa.People.All.GetIDs', nil, options))
|
20
|
-
response_valid? response
|
21
|
-
response['YourMembership_Response']['Sa.People.All.GetIDs']['People']['ID']
|
22
|
-
end
|
23
|
-
|
24
|
-
# Finds and returns a member or non-member <ID> using Import ID, Constituent ID or Website/Profile ID as criteria.
|
25
|
-
# If a single ID cannot be uniquely identified based on the criteria supplied then error code 406 is returned.
|
26
|
-
#
|
27
|
-
# @see https://api.yourmembership.com/reference/2_00/Sa_People_Profile_FindID.htm
|
28
|
-
#
|
29
|
-
# @param [Hash] options
|
30
|
-
# @option options [String] :ImportID Import ID of the person whose ID you are trying to find.
|
31
|
-
# @option options [String] :ConstituentID Constituent ID of the person whose ID you are trying to find.
|
32
|
-
# @option options [Integer] :WebsiteID Website/Profile ID of the person whose ID you are trying to find.
|
33
|
-
# @option options [String] :Username Username of the person whose ID you are trying to find.
|
34
|
-
# @option options [String] :Email Email Address of the person whose <ID> you are trying to find.
|
35
|
-
# May return multiple <ID>'s as Email Address is not unique.
|
36
|
-
#
|
37
|
-
# @return [String] if a single record is found (normal for all calls except for :Email)
|
38
|
-
# @return [Array] if multiple records are found (possible only for :Email searches)
|
39
|
-
def self.profile_findID(options = {}) # rubocop:disable Style/MethodName
|
40
|
-
response = post('/', :body => build_XML_request('Sa.People.Profile.FindID', nil, options))
|
41
|
-
response_valid? response
|
42
|
-
response['YourMembership_Response']['Sa.People.Profile.FindID']['ID']
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns a person's profile data.
|
46
|
-
#
|
47
|
-
# @see https://api.yourmembership.com/reference/2_00/Sa_People_Profile_Get.htm
|
48
|
-
#
|
49
|
-
# @param [String] id ID of the person whose profile data to return.
|
50
|
-
# @return [YourMembership::Profile] Returns a Profile object that represents the person's profile
|
51
|
-
def self.profile_get(id)
|
52
|
-
options = {}
|
53
|
-
options[:ID] = id
|
54
|
-
response = post('/', :body => build_XML_request('Sa.People.Profile.Get', nil, options))
|
55
|
-
response_valid? response
|
56
|
-
YourMembership::Profile.new response['YourMembership_Response']['Sa.People.Profile.Get']
|
57
|
-
end
|
58
|
-
|
59
|
-
# Returns a person's group relationship data. There are three types of relationships that members may have with
|
60
|
-
# particular groups; "Administrator", "Member" and "Representative". Groups are listed within nodes respective
|
61
|
-
# of their relationship type.
|
62
|
-
#
|
63
|
-
# @see https://api.yourmembership.com/reference/2_00/Sa_People_Profile_Groups_Get.htm
|
64
|
-
#
|
65
|
-
# @param [String] id ID of the person whose profile data to return.
|
66
|
-
# @return [Hash] Returns a Hash that represents the person's group relationships
|
67
|
-
def self.profile_groups_get(id)
|
68
|
-
options = {}
|
69
|
-
options[:ID] = id
|
70
|
-
response = post('/', :body => build_XML_request('Sa.People.Profile.Groups.Get', nil, options))
|
71
|
-
|
72
|
-
response_valid? response
|
73
|
-
response['YourMembership_Response']['Sa.People.Profile.Groups.Get']
|
74
|
-
end
|
75
|
-
|
76
|
-
# Updates an existing person's profile.
|
77
|
-
#
|
78
|
-
# @see https://api.yourmembership.com/reference/2_00/Sa_People_Profile_Update.htm
|
79
|
-
#
|
80
|
-
# @param [String] id ID of the person whose profile is to be updated.
|
81
|
-
# @param [YourMembership::Profile] profile The profile object containing the fields to be updated
|
82
|
-
# @return [Boolean] Will raise and exception or return TRUE
|
83
|
-
def self.profile_update(id, profile)
|
84
|
-
options = {}
|
85
|
-
options['ID'] = id
|
86
|
-
options['profile'] = profile
|
87
|
-
response = post('/', :body => build_XML_request('Sa.People.Profile.Update', nil, options))
|
88
|
-
response_valid? response
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
module Sa
|
3
|
+
# YourMembership System Administrator Members Namespace
|
4
|
+
class People < YourMembership::Base
|
5
|
+
# Returns a list of member and non-member IDs that may be optionally filtered by timestamp. This method is
|
6
|
+
# provided for data synchronization purposes and will return a maximum of 10,000 results. It would typically be
|
7
|
+
# used in conjunction with subsequent calls to Sa.People.Profile.Get for each ID returned
|
8
|
+
#
|
9
|
+
# @see https://api.yourmembership.com/reference/2_00/Sa_People_All_GetIDs.htm
|
10
|
+
#
|
11
|
+
# @param [Hash] options
|
12
|
+
# @option options [DateTime] :Timestamp Only accounts created after the this time will be returned
|
13
|
+
# @option options [String] :WebsiteID Filter the returned results by sequential WebsiteID.
|
14
|
+
# @option options [Array] :Groups Filter the returned results by group membership. [key, value] will translate to
|
15
|
+
# <key>value</key>
|
16
|
+
#
|
17
|
+
# @return [Array] A list of API IDs for non-members in your community.
|
18
|
+
def self.all_getIDs(options = {}) # rubocop:disable Style/MethodName
|
19
|
+
response = post('/', :body => build_XML_request('Sa.People.All.GetIDs', nil, options))
|
20
|
+
response_valid? response
|
21
|
+
response['YourMembership_Response']['Sa.People.All.GetIDs']['People']['ID']
|
22
|
+
end
|
23
|
+
|
24
|
+
# Finds and returns a member or non-member <ID> using Import ID, Constituent ID or Website/Profile ID as criteria.
|
25
|
+
# If a single ID cannot be uniquely identified based on the criteria supplied then error code 406 is returned.
|
26
|
+
#
|
27
|
+
# @see https://api.yourmembership.com/reference/2_00/Sa_People_Profile_FindID.htm
|
28
|
+
#
|
29
|
+
# @param [Hash] options
|
30
|
+
# @option options [String] :ImportID Import ID of the person whose ID you are trying to find.
|
31
|
+
# @option options [String] :ConstituentID Constituent ID of the person whose ID you are trying to find.
|
32
|
+
# @option options [Integer] :WebsiteID Website/Profile ID of the person whose ID you are trying to find.
|
33
|
+
# @option options [String] :Username Username of the person whose ID you are trying to find.
|
34
|
+
# @option options [String] :Email Email Address of the person whose <ID> you are trying to find.
|
35
|
+
# May return multiple <ID>'s as Email Address is not unique.
|
36
|
+
#
|
37
|
+
# @return [String] if a single record is found (normal for all calls except for :Email)
|
38
|
+
# @return [Array] if multiple records are found (possible only for :Email searches)
|
39
|
+
def self.profile_findID(options = {}) # rubocop:disable Style/MethodName
|
40
|
+
response = post('/', :body => build_XML_request('Sa.People.Profile.FindID', nil, options))
|
41
|
+
response_valid? response
|
42
|
+
response['YourMembership_Response']['Sa.People.Profile.FindID']['ID']
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns a person's profile data.
|
46
|
+
#
|
47
|
+
# @see https://api.yourmembership.com/reference/2_00/Sa_People_Profile_Get.htm
|
48
|
+
#
|
49
|
+
# @param [String] id ID of the person whose profile data to return.
|
50
|
+
# @return [YourMembership::Profile] Returns a Profile object that represents the person's profile
|
51
|
+
def self.profile_get(id)
|
52
|
+
options = {}
|
53
|
+
options[:ID] = id
|
54
|
+
response = post('/', :body => build_XML_request('Sa.People.Profile.Get', nil, options))
|
55
|
+
response_valid? response
|
56
|
+
YourMembership::Profile.new response['YourMembership_Response']['Sa.People.Profile.Get']
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns a person's group relationship data. There are three types of relationships that members may have with
|
60
|
+
# particular groups; "Administrator", "Member" and "Representative". Groups are listed within nodes respective
|
61
|
+
# of their relationship type.
|
62
|
+
#
|
63
|
+
# @see https://api.yourmembership.com/reference/2_00/Sa_People_Profile_Groups_Get.htm
|
64
|
+
#
|
65
|
+
# @param [String] id ID of the person whose profile data to return.
|
66
|
+
# @return [Hash] Returns a Hash that represents the person's group relationships
|
67
|
+
def self.profile_groups_get(id)
|
68
|
+
options = {}
|
69
|
+
options[:ID] = id
|
70
|
+
response = post('/', :body => build_XML_request('Sa.People.Profile.Groups.Get', nil, options))
|
71
|
+
|
72
|
+
response_valid? response
|
73
|
+
response['YourMembership_Response']['Sa.People.Profile.Groups.Get']
|
74
|
+
end
|
75
|
+
|
76
|
+
# Updates an existing person's profile.
|
77
|
+
#
|
78
|
+
# @see https://api.yourmembership.com/reference/2_00/Sa_People_Profile_Update.htm
|
79
|
+
#
|
80
|
+
# @param [String] id ID of the person whose profile is to be updated.
|
81
|
+
# @param [YourMembership::Profile] profile The profile object containing the fields to be updated
|
82
|
+
# @return [Boolean] Will raise and exception or return TRUE
|
83
|
+
def self.profile_update(id, profile)
|
84
|
+
options = {}
|
85
|
+
options['ID'] = id
|
86
|
+
options['profile'] = profile
|
87
|
+
response = post('/', :body => build_XML_request('Sa.People.Profile.Update', nil, options))
|
88
|
+
response_valid? response
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -1,152 +1,148 @@
|
|
1
|
-
module YourMembership
|
2
|
-
# YourMembership Session Object
|
3
|
-
#
|
4
|
-
# Session objects encapsulate the creation, storage, authentication, maintenance, and destruction of sessions in the
|
5
|
-
# YourMembership.com API.
|
6
|
-
#
|
7
|
-
# @note It is important to note that the Auth Namespace has been consumed by Sessions in the SDK as sessions and
|
8
|
-
# authentication are inextricably linked.
|
9
|
-
#
|
10
|
-
# Sessions can be *generic* (unauthenticated), *authenticated*, or *abandoned*.
|
11
|
-
#
|
12
|
-
# * *Generic sessions* are used extensively whenever the scope of a specific user is not necessary.
|
13
|
-
# * *Authenticated sessions* are used when the called method requires the scope of a specific user.
|
14
|
-
# * *Abandoned sessions* are no longer usable and are essentially the same as logging out.
|
15
|
-
#
|
16
|
-
# @example Generic (unauthenticated) Session
|
17
|
-
# session = YourMembership::Session.create # => <YourMembership::Session>
|
18
|
-
# @example Authenticated Session
|
19
|
-
# auth_session = YourMembership::Session.create 'username', 'password' # => <YourMembership::Session>
|
20
|
-
#
|
21
|
-
# @attr_reader [String] session_id The unique session identifier provided by the API
|
22
|
-
# @attr_reader [String, Nil] user_id The user id of the user bound to the session, if one exists.
|
23
|
-
class Session < YourMembership::Base
|
24
|
-
attr_reader :session_id, :user_id, :call_id
|
25
|
-
|
26
|
-
# Generates an empty session
|
27
|
-
def initialize(session_id = nil, call_id = 1, user_id = nil)
|
28
|
-
@session_id = session_id
|
29
|
-
@call_id = call_id
|
30
|
-
@user_id = user_id
|
31
|
-
end
|
32
|
-
|
33
|
-
# @see https://api.yourmembership.com/reference/2_00/Session_Create.htm
|
34
|
-
# @param user_name [String] Constructor takes optional parameters of user_name and password. If supplied then the
|
35
|
-
# session will be automatically authenticated upon instantiation.
|
36
|
-
# @param password [String]
|
37
|
-
def self.create(user_name = nil, password = nil)
|
38
|
-
response = post('/', :body => build_XML_request('Session.Create'))
|
39
|
-
|
40
|
-
if response_valid? response
|
41
|
-
session = new response['YourMembership_Response']['Session.Create']['SessionID']
|
42
|
-
end
|
43
|
-
|
44
|
-
session.authenticate user_name, password if user_name
|
45
|
-
session
|
46
|
-
end
|
47
|
-
|
48
|
-
# @return [Integer] Auto Increments ad returns the call_id for the session as required by the YourMembership.com API
|
49
|
-
def call_id
|
50
|
-
@call_id += 1
|
51
|
-
end
|
52
|
-
|
53
|
-
# @return [String] Returns the session_id
|
54
|
-
def to_s
|
55
|
-
@session_id
|
56
|
-
end
|
57
|
-
|
58
|
-
# Destroys an API session, thus preventing any further calls against it.
|
59
|
-
#
|
60
|
-
# @see https://api.yourmembership.com/reference/2_00/Session_Abandon.htm
|
61
|
-
#
|
62
|
-
# @return [Boolean] Returns true if the session was alive and successfully abandoned.
|
63
|
-
def abandon
|
64
|
-
response = self.class.post('/', :body => self.class.build_XML_request('Session.Abandon', self))
|
65
|
-
self.class.response_valid? response
|
66
|
-
end
|
67
|
-
|
68
|
-
# When called at intervals of less than 20 minutes, this method acts as an API session keep-alive.
|
69
|
-
#
|
70
|
-
# @see https://api.yourmembership.com/reference/2_00/Session_Ping.htm
|
71
|
-
#
|
72
|
-
# @return [Boolean] Returns true if the session is still alive.
|
73
|
-
def ping
|
74
|
-
response = self.class.post('/', :body => self.class.build_XML_request('Session.Ping', self))
|
75
|
-
self.class.response_valid? response
|
76
|
-
response['YourMembership_Response']['Session.Ping'] == '1'
|
77
|
-
end
|
78
|
-
|
79
|
-
# Convenience method for ping.
|
80
|
-
def valid?
|
81
|
-
ping
|
82
|
-
end
|
83
|
-
|
84
|
-
# Authenticates a member's username and password and binds them to the current API session.
|
85
|
-
#
|
86
|
-
# @see https://api.yourmembership.com/reference/2_00/Auth_Authenticate.htm
|
87
|
-
#
|
88
|
-
# @param user_name [String] The username of the member that is being authenticated.
|
89
|
-
# @param password [String] The clear text password of the member that is being authenticated.
|
90
|
-
#
|
91
|
-
# @return [Hash] Returns the member's ID and WebsiteID. The returned WebsiteID represents the numeric identifier
|
92
|
-
# used by the YourMembership.com application for navigation purposes. It may be used to provide direct navigation to
|
93
|
-
# a member's profile, photo gallery, personal blog, etc.
|
94
|
-
def authenticate(user_name, password)
|
95
|
-
options = {}
|
96
|
-
options[:Username] = user_name
|
97
|
-
options[:Password] = password
|
98
|
-
|
99
|
-
response = self.class.post('/', :body => self.class.build_XML_request('Auth.Authenticate', self, options))
|
100
|
-
|
101
|
-
self.class.response_valid? response
|
102
|
-
if response['YourMembership_Response']['Auth.Authenticate']
|
103
|
-
get_authenticated_user
|
104
|
-
else
|
105
|
-
false
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# Creates an AuthToken that is bound to the current session. The returned token must be supplied to the Sign-In
|
110
|
-
# form during member authentication in order to bind a member to their API session. The sign-in URL, which will
|
111
|
-
# include the new AuthToken in its query-string, is returned by this method as GoToUrl. Tokens expire after a short
|
112
|
-
# period of time, so it is suggested that the user be immediately redirected the returned GoToUrl after creating an
|
113
|
-
# authentication token.
|
114
|
-
#
|
115
|
-
# @see https://api.yourmembership.com/reference/2_00/Auth_CreateToken.htm
|
116
|
-
#
|
117
|
-
# @param options [Hash]
|
118
|
-
# @option options [String] :RetUrl After authentication the browser will be redirected to this URL
|
119
|
-
# @option options [String] :Username The user can optionally be logged in automatically if :Username and :Password
|
120
|
-
# are supplied in cleartext.
|
121
|
-
# @option options [String] :Password The user's password
|
122
|
-
# @option options [Boolean] :Persist Supplying this value is only necessary when also providing user credentials for
|
123
|
-
# automated authentication. The purpose of enabling persistence is to extend an authenticated user's browsing
|
124
|
-
# session beyond its normal inactivity threshold of 20 minutes.
|
125
|
-
#
|
126
|
-
# @return [Hash] Contains the token String and a URL that will authenticate the session based on that token.
|
127
|
-
def createToken(options = {}) # rubocop:disable Style/MethodName
|
128
|
-
# Options inlclude: :RetUrl(String), :Username(String),
|
129
|
-
# :Password(String), :Persist(Boolean)
|
130
|
-
|
131
|
-
response = self.class.post('/', :body => self.class.build_XML_request('Auth.CreateToken', self, options))
|
132
|
-
|
133
|
-
self.class.response_valid? response
|
134
|
-
response['YourMembership_Response']['Auth.CreateToken']
|
135
|
-
end
|
136
|
-
|
137
|
-
# Indicates whether the session is bound to a user.
|
138
|
-
def authenticated?
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
@user_id = YourMembership::Member.isAuthenticated(self)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
1
|
+
module YourMembership
|
2
|
+
# YourMembership Session Object
|
3
|
+
#
|
4
|
+
# Session objects encapsulate the creation, storage, authentication, maintenance, and destruction of sessions in the
|
5
|
+
# YourMembership.com API.
|
6
|
+
#
|
7
|
+
# @note It is important to note that the Auth Namespace has been consumed by Sessions in the SDK as sessions and
|
8
|
+
# authentication are inextricably linked.
|
9
|
+
#
|
10
|
+
# Sessions can be *generic* (unauthenticated), *authenticated*, or *abandoned*.
|
11
|
+
#
|
12
|
+
# * *Generic sessions* are used extensively whenever the scope of a specific user is not necessary.
|
13
|
+
# * *Authenticated sessions* are used when the called method requires the scope of a specific user.
|
14
|
+
# * *Abandoned sessions* are no longer usable and are essentially the same as logging out.
|
15
|
+
#
|
16
|
+
# @example Generic (unauthenticated) Session
|
17
|
+
# session = YourMembership::Session.create # => <YourMembership::Session>
|
18
|
+
# @example Authenticated Session
|
19
|
+
# auth_session = YourMembership::Session.create 'username', 'password' # => <YourMembership::Session>
|
20
|
+
#
|
21
|
+
# @attr_reader [String] session_id The unique session identifier provided by the API
|
22
|
+
# @attr_reader [String, Nil] user_id The user id of the user bound to the session, if one exists.
|
23
|
+
class Session < YourMembership::Base
|
24
|
+
attr_reader :session_id, :user_id, :call_id
|
25
|
+
|
26
|
+
# Generates an empty session
|
27
|
+
def initialize(session_id = nil, call_id = 1, user_id = nil)
|
28
|
+
@session_id = session_id
|
29
|
+
@call_id = call_id
|
30
|
+
@user_id = user_id
|
31
|
+
end
|
32
|
+
|
33
|
+
# @see https://api.yourmembership.com/reference/2_00/Session_Create.htm
|
34
|
+
# @param user_name [String] Constructor takes optional parameters of user_name and password. If supplied then the
|
35
|
+
# session will be automatically authenticated upon instantiation.
|
36
|
+
# @param password [String]
|
37
|
+
def self.create(user_name = nil, password = nil)
|
38
|
+
response = post('/', :body => build_XML_request('Session.Create'))
|
39
|
+
|
40
|
+
if response_valid? response
|
41
|
+
session = new response['YourMembership_Response']['Session.Create']['SessionID']
|
42
|
+
end
|
43
|
+
|
44
|
+
session.authenticate user_name, password if user_name
|
45
|
+
session
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Integer] Auto Increments ad returns the call_id for the session as required by the YourMembership.com API
|
49
|
+
def call_id
|
50
|
+
@call_id += 1
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [String] Returns the session_id
|
54
|
+
def to_s
|
55
|
+
@session_id
|
56
|
+
end
|
57
|
+
|
58
|
+
# Destroys an API session, thus preventing any further calls against it.
|
59
|
+
#
|
60
|
+
# @see https://api.yourmembership.com/reference/2_00/Session_Abandon.htm
|
61
|
+
#
|
62
|
+
# @return [Boolean] Returns true if the session was alive and successfully abandoned.
|
63
|
+
def abandon
|
64
|
+
response = self.class.post('/', :body => self.class.build_XML_request('Session.Abandon', self))
|
65
|
+
self.class.response_valid? response
|
66
|
+
end
|
67
|
+
|
68
|
+
# When called at intervals of less than 20 minutes, this method acts as an API session keep-alive.
|
69
|
+
#
|
70
|
+
# @see https://api.yourmembership.com/reference/2_00/Session_Ping.htm
|
71
|
+
#
|
72
|
+
# @return [Boolean] Returns true if the session is still alive.
|
73
|
+
def ping
|
74
|
+
response = self.class.post('/', :body => self.class.build_XML_request('Session.Ping', self))
|
75
|
+
self.class.response_valid? response
|
76
|
+
response['YourMembership_Response']['Session.Ping'] == '1'
|
77
|
+
end
|
78
|
+
|
79
|
+
# Convenience method for ping.
|
80
|
+
def valid?
|
81
|
+
ping
|
82
|
+
end
|
83
|
+
|
84
|
+
# Authenticates a member's username and password and binds them to the current API session.
|
85
|
+
#
|
86
|
+
# @see https://api.yourmembership.com/reference/2_00/Auth_Authenticate.htm
|
87
|
+
#
|
88
|
+
# @param user_name [String] The username of the member that is being authenticated.
|
89
|
+
# @param password [String] The clear text password of the member that is being authenticated.
|
90
|
+
#
|
91
|
+
# @return [Hash] Returns the member's ID and WebsiteID. The returned WebsiteID represents the numeric identifier
|
92
|
+
# used by the YourMembership.com application for navigation purposes. It may be used to provide direct navigation to
|
93
|
+
# a member's profile, photo gallery, personal blog, etc.
|
94
|
+
def authenticate(user_name, password)
|
95
|
+
options = {}
|
96
|
+
options[:Username] = user_name
|
97
|
+
options[:Password] = password
|
98
|
+
|
99
|
+
response = self.class.post('/', :body => self.class.build_XML_request('Auth.Authenticate', self, options))
|
100
|
+
|
101
|
+
self.class.response_valid? response
|
102
|
+
if response['YourMembership_Response']['Auth.Authenticate']
|
103
|
+
get_authenticated_user
|
104
|
+
else
|
105
|
+
false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Creates an AuthToken that is bound to the current session. The returned token must be supplied to the Sign-In
|
110
|
+
# form during member authentication in order to bind a member to their API session. The sign-in URL, which will
|
111
|
+
# include the new AuthToken in its query-string, is returned by this method as GoToUrl. Tokens expire after a short
|
112
|
+
# period of time, so it is suggested that the user be immediately redirected the returned GoToUrl after creating an
|
113
|
+
# authentication token.
|
114
|
+
#
|
115
|
+
# @see https://api.yourmembership.com/reference/2_00/Auth_CreateToken.htm
|
116
|
+
#
|
117
|
+
# @param options [Hash]
|
118
|
+
# @option options [String] :RetUrl After authentication the browser will be redirected to this URL
|
119
|
+
# @option options [String] :Username The user can optionally be logged in automatically if :Username and :Password
|
120
|
+
# are supplied in cleartext.
|
121
|
+
# @option options [String] :Password The user's password
|
122
|
+
# @option options [Boolean] :Persist Supplying this value is only necessary when also providing user credentials for
|
123
|
+
# automated authentication. The purpose of enabling persistence is to extend an authenticated user's browsing
|
124
|
+
# session beyond its normal inactivity threshold of 20 minutes.
|
125
|
+
#
|
126
|
+
# @return [Hash] Contains the token String and a URL that will authenticate the session based on that token.
|
127
|
+
def createToken(options = {}) # rubocop:disable Style/MethodName
|
128
|
+
# Options inlclude: :RetUrl(String), :Username(String),
|
129
|
+
# :Password(String), :Persist(Boolean)
|
130
|
+
|
131
|
+
response = self.class.post('/', :body => self.class.build_XML_request('Auth.CreateToken', self, options))
|
132
|
+
|
133
|
+
self.class.response_valid? response
|
134
|
+
response['YourMembership_Response']['Auth.CreateToken']
|
135
|
+
end
|
136
|
+
|
137
|
+
# Indicates whether the session is bound to a user.
|
138
|
+
def authenticated?
|
139
|
+
valid? && !get_authenticated_user.nil?
|
140
|
+
end
|
141
|
+
|
142
|
+
# Get the ID of the currently authenticated user bound to this session.
|
143
|
+
# @return [String, Nil] The API ID of the currently authenticated user
|
144
|
+
def get_authenticated_user # rubocop:disable Style/AccessorMethodName
|
145
|
+
@user_id = YourMembership::Member.isAuthenticated(self)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|