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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.env +5 -0
  3. data/.gitignore +1 -0
  4. data/.rspec +1 -0
  5. data/CHANGELOG.md +10 -0
  6. data/README.md +12 -10
  7. data/lib/httparty/patch.rb +33 -33
  8. data/lib/your_membership/base.rb +197 -197
  9. data/lib/your_membership/commerce.rb +25 -25
  10. data/lib/your_membership/config.rb +41 -41
  11. data/lib/your_membership/convert.rb +24 -24
  12. data/lib/your_membership/error.rb +21 -21
  13. data/lib/your_membership/events.rb +60 -60
  14. data/lib/your_membership/feeds.rb +37 -37
  15. data/lib/your_membership/member.rb +399 -397
  16. data/lib/your_membership/members.rb +124 -124
  17. data/lib/your_membership/people.rb +38 -38
  18. data/lib/your_membership/profile.rb +92 -85
  19. data/lib/your_membership/sa.rb +6 -6
  20. data/lib/your_membership/sa_auth.rb +34 -34
  21. data/lib/your_membership/sa_certifications.rb +22 -22
  22. data/lib/your_membership/sa_commerce.rb +22 -22
  23. data/lib/your_membership/sa_events.rb +66 -66
  24. data/lib/your_membership/sa_export.rb +195 -195
  25. data/lib/your_membership/sa_groups.rb +30 -30
  26. data/lib/your_membership/sa_member.rb +49 -49
  27. data/lib/your_membership/sa_members.rb +180 -179
  28. data/lib/your_membership/sa_nonmembers.rb +41 -41
  29. data/lib/your_membership/sa_people.rb +92 -92
  30. data/lib/your_membership/session.rb +148 -152
  31. data/lib/your_membership/version.rb +1 -1
  32. data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_multiple.yml +51 -0
  33. data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_none.yml +51 -0
  34. data/spec/fixtures/vcr_cassettes/sa_members_all_getids_timestamp_single.yml +51 -0
  35. data/spec/lib/{profile_spec.rb → your_membership/profile_spec.rb} +232 -197
  36. data/spec/lib/your_membership/sa_members_spec.rb +38 -0
  37. data/spec/spec_helper.rb +101 -78
  38. data/your_membership.gemspec +4 -0
  39. metadata +85 -19
@@ -1,3 +1,3 @@
1
1
  module YourMembership
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.yourmembership.com/
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0" encoding="UTF-8"?>
10
+ <YourMembership>
11
+ <Version>2.00</Version>
12
+ <ApiKey><PRIVATE_KEY></ApiKey>
13
+ <SaPasscode><SA_PASSCODE></SaPasscode>
14
+ <CallID>10000</CallID>
15
+ <Call Method="Sa.Members.All.GetIDs">
16
+ <Timestamp>2015-12-02 15:54:11</Timestamp>
17
+ </Call>
18
+ </YourMembership>
19
+ headers:
20
+ Accept-Encoding:
21
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
22
+ Accept:
23
+ - "*/*"
24
+ User-Agent:
25
+ - Ruby
26
+ response:
27
+ status:
28
+ code: 200
29
+ message: OK
30
+ headers:
31
+ Cache-Control:
32
+ - private
33
+ Content-Length:
34
+ - '24051'
35
+ Content-Type:
36
+ - text/xml; Charset=utf-8
37
+ Set-Cookie:
38
+ - "<ASP_SESSION_ID>"
39
+ X-Powered-By:
40
+ - ASP.NET
41
+ Date:
42
+ - Wed, 16 Dec 2015 20:54:12 GMT
43
+ Connection:
44
+ - Keep-alive
45
+ body:
46
+ encoding: UTF-8
47
+ string: "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n<YourMembership_Response>\r\n<ErrCode>0</ErrCode>\r\n<ExtendedErrorInfo></ExtendedErrorInfo>\r\n<Sa.Members.All.GetIDs>\r\n<ServerGmtBias>-5</ServerGmtBias>\r\n<ServerTime>2015-12-16
48
+ 15:54:12</ServerTime>\r\n<Members>\r\n<ID>57EEB598-CB44-4D85-B0D6-377F393AF5B4</ID>\r\n<ID>1C0CE647-FAA5-4EB0-ADF0-5B669B36378E</ID>\r\n</Members>\r\n</Sa.Members.All.GetIDs>\r\n</YourMembership_Response>\r\n"
49
+ http_version:
50
+ recorded_at: Wed, 16 Dec 2015 20:54:12 GMT
51
+ recorded_with: VCR 3.0.0
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.yourmembership.com/
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0" encoding="UTF-8"?>
10
+ <YourMembership>
11
+ <Version>2.00</Version>
12
+ <ApiKey><PRIVATE_KEY></ApiKey>
13
+ <SaPasscode><SA_PASSCODE></SaPasscode>
14
+ <CallID>10001</CallID>
15
+ <Call Method="Sa.Members.All.GetIDs">
16
+ <Timestamp>2015-12-16 15:54:12</Timestamp>
17
+ </Call>
18
+ </YourMembership>
19
+ headers:
20
+ Accept-Encoding:
21
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
22
+ Accept:
23
+ - "*/*"
24
+ User-Agent:
25
+ - Ruby
26
+ response:
27
+ status:
28
+ code: 200
29
+ message: OK
30
+ headers:
31
+ Cache-Control:
32
+ - private
33
+ Content-Length:
34
+ - '314'
35
+ Content-Type:
36
+ - text/xml; Charset=utf-8
37
+ Set-Cookie:
38
+ - "<ASP_SESSION_ID>"
39
+ X-Powered-By:
40
+ - ASP.NET
41
+ Date:
42
+ - Wed, 16 Dec 2015 20:54:12 GMT
43
+ Connection:
44
+ - Keep-alive
45
+ body:
46
+ encoding: UTF-8
47
+ string: "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n<YourMembership_Response>\r\n<ErrCode>0</ErrCode>\r\n<ExtendedErrorInfo></ExtendedErrorInfo>\r\n<Sa.Members.All.GetIDs>\r\n<ServerGmtBias>-5</ServerGmtBias>\r\n<ServerTime>2015-12-16
48
+ 15:54:13</ServerTime>\r\n<Members></Members>\r\n</Sa.Members.All.GetIDs>\r\n</YourMembership_Response>\r\n"
49
+ http_version:
50
+ recorded_at: Wed, 16 Dec 2015 20:54:12 GMT
51
+ recorded_with: VCR 3.0.0
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.yourmembership.com/
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0" encoding="UTF-8"?>
10
+ <YourMembership>
11
+ <Version>2.00</Version>
12
+ <ApiKey><PRIVATE_KEY></ApiKey>
13
+ <SaPasscode><SA_PASSCODE></SaPasscode>
14
+ <CallID>10002</CallID>
15
+ <Call Method="Sa.Members.All.GetIDs">
16
+ <Timestamp>2015-12-06 15:54:12</Timestamp>
17
+ </Call>
18
+ </YourMembership>
19
+ headers:
20
+ Accept-Encoding:
21
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
22
+ Accept:
23
+ - "*/*"
24
+ User-Agent:
25
+ - Ruby
26
+ response:
27
+ status:
28
+ code: 200
29
+ message: OK
30
+ headers:
31
+ Cache-Control:
32
+ - private
33
+ Content-Length:
34
+ - '363'
35
+ Content-Type:
36
+ - text/xml; Charset=utf-8
37
+ Set-Cookie:
38
+ - "<ASP_SESSION_ID>"
39
+ X-Powered-By:
40
+ - ASP.NET
41
+ Date:
42
+ - Wed, 16 Dec 2015 20:54:12 GMT
43
+ Connection:
44
+ - Keep-alive
45
+ body:
46
+ encoding: UTF-8
47
+ string: "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n<YourMembership_Response>\r\n<ErrCode>0</ErrCode>\r\n<ExtendedErrorInfo></ExtendedErrorInfo>\r\n<Sa.Members.All.GetIDs>\r\n<ServerGmtBias>-5</ServerGmtBias>\r\n<ServerTime>2015-12-16
48
+ 15:54:13</ServerTime>\r\n<Members>\r\n<ID>F185B3A5-2ED9-424E-82AF-D918B4E604E4</ID>\r\n</Members>\r\n</Sa.Members.All.GetIDs>\r\n</YourMembership_Response>\r\n"
49
+ http_version:
50
+ recorded_at: Wed, 16 Dec 2015 20:54:13 GMT
51
+ recorded_with: VCR 3.0.0
@@ -1,197 +1,232 @@
1
- require "spec_helper"
2
- require "profile"
3
-
4
- describe YourMembership::Profile do
5
- before do
6
- @sample_profile = {
7
- "ID"=>"F8C2BEFD-GF37-5CBC-B750-487162B95CDF",
8
- "WebsiteID"=>"16273406",
9
- "PrimaryGroupCode"=>nil,
10
- "IsMember"=>"1",
11
- "IsNonMember"=>"0",
12
- "Registered"=>"2014-06-12 14:53:30",
13
- "LastUpdated"=>"2014-08-07 14:31:34",
14
- "ImportID"=>"YM-40539-798958-4242",
15
- "ConstituentID"=>nil,
16
- "EmailAddr"=>"nflood@echonet.org",
17
- "EmailBounced"=>"0",
18
- "NamePrefix"=>"Mr",
19
- "FirstName"=>"Nate",
20
- "MiddleName"=>nil,
21
- "LastName"=>"Flood",
22
- "NameSuffix"=>nil,
23
- "Nickname"=>"Nate Flood",
24
- "Gender"=>"M",
25
- "Birthdate"=>nil,
26
- "MaritalStatus"=>nil,
27
- "MaidenName"=>nil,
28
- "SpouseName"=>nil,
29
- "AnniversaryDate"=>nil,
30
- "Employer"=>"ECHO INC.",
31
- "Title"=>"Digital Media Specialist",
32
- "Profession"=>nil,
33
- "Membership"=>"ECHO Interns and Current Staff",
34
- "MembershipExpiry"=>nil,
35
- "MemberTypeCode"=>"ECHOstaff",
36
- "Approved"=>"1",
37
- "Suspended"=>"0",
38
- "Username"=>"nflood",
39
- "PasswordHash"=>"1E10A122BDB35AN022FEJF617BE14527E72KA26E",
40
- "AltEmailAddr"=>nil,
41
- "HomeAddrLines"=>nil,
42
- "HomeCity"=>nil,
43
- "HomeLocation"=>nil,
44
- "HomePostalCode"=>nil,
45
- "HomeCountry"=>nil,
46
- "Website"=>nil,
47
- "HomePhAreaCode"=>nil,
48
- "HomePhone"=>nil,
49
- "MobileAreaCode"=>nil,
50
- "Mobile"=>nil,
51
- "EmpAddrLines"=>"17391 Durrance Road",
52
- "EmpCity"=>"North Fort Myers",
53
- "EmpLocation"=>"Florida",
54
- "EmpPostalCode"=>"33917",
55
- "EmpCountry"=>"United States",
56
- "BusinessWebsite"=>nil,
57
- "EmpPhAreaCode"=>"239",
58
- "EmpPhone"=>"567-3355",
59
- "EmpFaxAreaCode"=>nil,
60
- "EmpFax"=>nil,
61
- "LastRenewalReminderSent"=>nil,
62
- "GamificationPoints"=>"198",
63
- "HeadshotImageURI"=>"http://c.yourmembership.com/sites/echocommunity.site-ym.com/photos/alumni/20140725_144857_16292.jpg",
64
- "MasterID"=>nil,
65
- "LastRenewalDate"=>"2014-06-12 14:53:00",
66
- "ApprovalDate"=>"6/12/2014 2:54:19 PM",
67
- "LastModifiedDate"=>"2014-08-07 14:31:34",
68
- "QueuedForDelete"=>"0",
69
- "QueuedForDeleteDate"=>nil,
70
- "Latitude"=>"0",
71
- "Longitude"=>"0",
72
- "CustomFieldResponses"=>{
73
- "CustomFieldResponse"=>[
74
- {"Values"=>{"Value"=>"USA"}, "FieldCode"=>"Workingcountry", "Visibility"=>""},
75
- {"Values"=>{"Value"=>"other"}, "FieldCode"=>"UserType", "Visibility"=>""},
76
- {"Values"=>{"Value"=>"North America"}, "FieldCode"=>"region", "Visibility"=>""},
77
- {"Values"=>{"Value"=>["North","South"]}, "FieldCode"=>"PCVenddate", "Visibility"=>""} ]
78
- }
79
- }
80
- end
81
- it "accepts and sets required parameters for new profiles" do
82
- profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'ausername', 'apassword')
83
- profile.data['FirstName'].should == 'afirstname'
84
- profile.data['LastName'].should == 'alastname'
85
- profile.data['MemberTypeCode'].should == 'amembertypecode'
86
- profile.data['Username'].should == 'ausername'
87
- profile.data['Password'].should == 'apassword'
88
- end
89
-
90
- it "adds arbitrary keys when creating new profiles" do
91
- profile_hash = {'foo' => 'bar'}
92
- profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'ausername', nil, profile_hash)
93
- profile.data.should include 'foo'
94
- profile.data['foo'].should == 'bar'
95
- end
96
-
97
- it "adds arbitrary custom keys when creating new profiles" do
98
- profile_custom_hash = {'foo' => 'bar'}
99
- profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'ausername', nil, {}, profile_custom_hash)
100
- profile.custom_data.should include 'foo'
101
- profile.custom_data['foo'].should == 'bar'
102
- end
103
-
104
- it "creates an object based on a profile hash" do
105
- profile = YourMembership::Profile.new(@sample_profile)
106
- profile.data.should include 'FirstName'
107
- end
108
-
109
- it "adds arbitrary keys when creating based on a profile hash" do
110
- profile_hash = {'foo' => 'bar'}
111
- profile = YourMembership::Profile.new(profile_hash)
112
- profile.data.should include 'foo'
113
- profile.data['foo'].should == 'bar'
114
- end
115
-
116
- it "returns the output hash when asked" do
117
- profile_hash = {'foo' => 'bar'}
118
- profile = YourMembership::Profile.new(profile_hash)
119
- profile.to_h.should be_a(Hash)
120
- profile.to_h.should include 'foo'
121
- end
122
-
123
- it "does not return nil values in the output hash" do
124
- profile_hash = {'foo' => 'bar', 'far' => nil}
125
- profile = YourMembership::Profile.new(profile_hash)
126
- profile.to_h.should include 'foo'
127
- profile.to_h.should_not include 'far'
128
- end
129
-
130
- it "can be manipulated directly through the data attribute" do
131
- profile_hash = {'foo' => 'bar'}
132
- profile = YourMembership::Profile.new(profile_hash)
133
- expect {profile.data['foo'] = 'baz'}.to change{profile.data['foo']}.from('bar').to('baz')
134
- end
135
-
136
- it "has a custom_data attribute" do
137
- profile = YourMembership::Profile.new
138
- expect profile.should respond_to 'custom_data'
139
- end
140
-
141
- it "can be manipulated directly through the custom data attribute" do
142
- profile = YourMembership::Profile.new
143
- profile.custom_data['foo'] = 'bar'
144
- expect profile.custom_data.should include 'foo'
145
- expect profile.custom_data['foo'].should == 'bar'
146
- expect {profile.custom_data['foo'] = 'baz'}.to change{profile.custom_data['foo']}.from('bar').to('baz')
147
- end
148
-
149
- it "adds a 'CustomFieldResponses' key as a hash" do
150
- profile_hash = {'foo' => 'bar'}
151
- profile = YourMembership::Profile.new(profile_hash)
152
- expect profile.to_h.should include 'CustomFieldResponses'
153
- expect profile.to_h['CustomFieldResponses'].should be_a(Hash)
154
- end
155
-
156
- it "contains custom_data in the 'CustomFieldResponses' key hash" do
157
- profile = YourMembership::Profile.new
158
- profile.custom_data['foo'] = 'bar'
159
- expect profile.to_h['CustomFieldResponses'].should include 'foo'
160
- expect profile.to_h['CustomFieldResponses']['foo'].should == 'bar'
161
- end
162
-
163
- it "accepts strings as custom data" do
164
- profile = YourMembership::Profile.new
165
- profile.custom_data['foo'] = 'bar'
166
- expect profile.to_h['CustomFieldResponses']['foo'].should be_a(String)
167
- end
168
-
169
- it "accepts arrays as custom data" do
170
- profile = YourMembership::Profile.new
171
- profile.custom_data['foo'] = ['bar', 'bat', 'baz']
172
- expect profile.to_h['CustomFieldResponses']['foo'].should be_a(Array)
173
- expect profile.to_h['CustomFieldResponses']['foo'].should include 'baz'
174
- end
175
-
176
- it "does not contain nil keys in the 'CustomFieldResponses'" do
177
- profile = YourMembership::Profile.new
178
- profile.custom_data['foo'] = nil
179
- expect profile.to_h['CustomFieldResponses'].should_not include 'foo'
180
- end
181
-
182
- it "does not include 'CustomFieldResponses' in the data hash when creating from a profile hash" do
183
- profile = YourMembership::Profile.new(@sample_profile)
184
- profile.data.should_not include 'CustomFieldResponses'
185
- end
186
-
187
- it "puts 'CustomFieldResponses' into the custom_data hash when creating from a profile hash" do
188
- profile = YourMembership::Profile.new(@sample_profile)
189
- profile.custom_data.should include 'Workingcountry'
190
- end
191
-
192
- it "converts 'CustomFieldResponse' values to strings or arrays" do
193
- profile = YourMembership::Profile.new(@sample_profile)
194
- profile.custom_data.should include 'Workingcountry'
195
- profile.custom_data['Workingcountry'].should == "USA"
196
- end
197
- end
1
+ require "spec_helper"
2
+
3
+ describe YourMembership::Profile do
4
+ before do
5
+ @sample_profile = {
6
+ "ID"=>"F8C2BEFD-GF37-5CBC-B750-487162B95CDF",
7
+ "WebsiteID"=>"16273406",
8
+ "PrimaryGroupCode"=>nil,
9
+ "IsMember"=>"1",
10
+ "IsNonMember"=>"0",
11
+ "Registered"=>"2014-06-12 14:53:30",
12
+ "LastUpdated"=>"2014-08-07 14:31:34",
13
+ "ImportID"=>"YM-40539-798958-4242",
14
+ "ConstituentID"=>nil,
15
+ "EmailAddr"=>"nflood@echonet.org",
16
+ "EmailBounced"=>"0",
17
+ "NamePrefix"=>"Mr",
18
+ "FirstName"=>"Nate",
19
+ "MiddleName"=>nil,
20
+ "LastName"=>"Flood",
21
+ "NameSuffix"=>nil,
22
+ "Nickname"=>"Nate Flood",
23
+ "Gender"=>"M",
24
+ "Birthdate"=>nil,
25
+ "MaritalStatus"=>nil,
26
+ "MaidenName"=>nil,
27
+ "SpouseName"=>nil,
28
+ "AnniversaryDate"=>nil,
29
+ "Employer"=>"ECHO INC.",
30
+ "Title"=>"Digital Media Specialist",
31
+ "Profession"=>nil,
32
+ "Membership"=>"ECHO Interns and Current Staff",
33
+ "MembershipExpiry"=>nil,
34
+ "MemberTypeCode"=>"ECHOstaff",
35
+ "Approved"=>"1",
36
+ "Suspended"=>"0",
37
+ "Username"=>"nflood",
38
+ "PasswordHash"=>"1E10A122BDB35AN022FEJF617BE14527E72KA26E",
39
+ "AltEmailAddr"=>nil,
40
+ "HomeAddrLines"=>nil,
41
+ "HomeCity"=>nil,
42
+ "HomeLocation"=>nil,
43
+ "HomePostalCode"=>nil,
44
+ "HomeCountry"=>nil,
45
+ "Website"=>nil,
46
+ "HomePhAreaCode"=>nil,
47
+ "HomePhone"=>nil,
48
+ "MobileAreaCode"=>nil,
49
+ "Mobile"=>nil,
50
+ "EmpAddrLines"=>"17391 Durrance Road",
51
+ "EmpCity"=>"North Fort Myers",
52
+ "EmpLocation"=>"Florida",
53
+ "EmpPostalCode"=>"33917",
54
+ "EmpCountry"=>"United States",
55
+ "BusinessWebsite"=>nil,
56
+ "EmpPhAreaCode"=>"239",
57
+ "EmpPhone"=>"567-3355",
58
+ "EmpFaxAreaCode"=>nil,
59
+ "EmpFax"=>nil,
60
+ "LastRenewalReminderSent"=>nil,
61
+ "GamificationPoints"=>"198",
62
+ "HeadshotImageURI"=>"http://c.yourmembership.com/sites/echocommunity.site-ym.com/photos/alumni/20140725_144857_16292.jpg",
63
+ "MasterID"=>nil,
64
+ "LastRenewalDate"=>"2014-06-12 14:53:00",
65
+ "ApprovalDate"=>"6/12/2014 2:54:19 PM",
66
+ "LastModifiedDate"=>"2014-08-07 14:31:34",
67
+ "QueuedForDelete"=>"0",
68
+ "QueuedForDeleteDate"=>nil,
69
+ "Latitude"=>"0",
70
+ "Longitude"=>"0",
71
+ "CustomFieldResponses"=>{
72
+ "CustomFieldResponse"=>[
73
+ {"Values"=>{"Value"=>"USA"}, "FieldCode"=>"Workingcountry", "Visibility"=>""},
74
+ {"Values"=>{"Value"=>"other"}, "FieldCode"=>"UserType", "Visibility"=>""},
75
+ {"Values"=>{"Value"=>"North America"}, "FieldCode"=>"region", "Visibility"=>""},
76
+ {"Values"=>{"Value"=>["North","South"]}, "FieldCode"=>"PCVenddate", "Visibility"=>""} ]
77
+ }
78
+ }
79
+ end
80
+ it "accepts and sets required parameters for new profiles" do
81
+ profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'aemail', 'ausername', 'apassword', {})
82
+ profile.data['FirstName'].should == 'afirstname'
83
+ profile.data['LastName'].should == 'alastname'
84
+ profile.data['MemberTypeCode'].should == 'amembertypecode'
85
+ profile.data['EmailAddr'].should == 'aemail'
86
+ profile.data['Username'].should == 'ausername'
87
+ profile.data['Password'].should == 'apassword'
88
+ end
89
+
90
+ it "adds arbitrary keys when creating new profiles" do
91
+ profile_hash = {'foo' => 'bar'}
92
+ profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'aemail', 'ausername', nil, profile_hash)
93
+ profile.data.should include 'foo'
94
+ profile.data['foo'].should == 'bar'
95
+ end
96
+
97
+ it "adds arbitrary custom keys when creating new profiles" do
98
+ profile_hash = {
99
+ 'CustomFieldResponses' => {
100
+ 'CustomFieldResponse' => [{
101
+ 'FieldCode' => 'foo',
102
+ 'Values' => {
103
+ 'Value' => 'bar'
104
+ }
105
+ }]
106
+ }
107
+ }
108
+ profile = YourMembership::Profile.create_new('afirstname', 'alastname', 'amembertypecode', 'aemail', 'ausername', nil, profile_hash)
109
+ profile.custom_data.should include 'foo'
110
+ profile.custom_data['foo'].should == 'bar'
111
+ end
112
+
113
+ it "creates an object based on a profile hash" do
114
+ profile = YourMembership::Profile.new(@sample_profile)
115
+ profile.data.should include 'FirstName'
116
+ end
117
+
118
+ it "adds arbitrary keys when creating based on a profile hash" do
119
+ profile_hash = {'foo' => 'bar'}
120
+ profile = YourMembership::Profile.new(profile_hash)
121
+ profile.data.should include 'foo'
122
+ profile.data['foo'].should == 'bar'
123
+ end
124
+
125
+ it "returns the output hash when asked" do
126
+ profile_hash = {'foo' => 'bar'}
127
+ profile = YourMembership::Profile.new(profile_hash)
128
+ profile.to_h.should be_a(Hash)
129
+ profile.to_h.should include 'foo'
130
+ end
131
+
132
+ it "does not return nil values in the output hash" do
133
+ profile_hash = {'foo' => 'bar', 'far' => nil}
134
+ profile = YourMembership::Profile.new(profile_hash)
135
+ profile.to_h.should include 'foo'
136
+ profile.to_h.should_not include 'far'
137
+ end
138
+
139
+ it "can be manipulated directly through the data attribute" do
140
+ profile_hash = {'foo' => 'bar'}
141
+ profile = YourMembership::Profile.new(profile_hash)
142
+ expect {profile.data['foo'] = 'baz'}.to change{profile.data['foo']}.from('bar').to('baz')
143
+ end
144
+
145
+ it "has a custom_data attribute" do
146
+ profile = YourMembership::Profile.new
147
+ expect profile.should respond_to 'custom_data'
148
+ end
149
+
150
+ it "can be manipulated directly through the custom data attribute" do
151
+ profile = YourMembership::Profile.new
152
+ profile.custom_data['foo'] = 'bar'
153
+ expect profile.custom_data.should include 'foo'
154
+ expect profile.custom_data['foo'].should == 'bar'
155
+ expect {profile.custom_data['foo'] = 'baz'}.to change{profile.custom_data['foo']}.from('bar').to('baz')
156
+ end
157
+
158
+ it "adds a 'CustomFieldResponses' key as a hash" do
159
+ profile_hash = {'foo' => 'bar'}
160
+ profile = YourMembership::Profile.new(profile_hash)
161
+ expect profile.to_h.should include 'CustomFieldResponses'
162
+ expect profile.to_h['CustomFieldResponses'].should be_a(Hash)
163
+ end
164
+
165
+ it "contains custom_data in the 'CustomFieldResponses' key hash" do
166
+ profile = YourMembership::Profile.new
167
+ profile.custom_data['foo'] = 'bar'
168
+ expect profile.to_h['CustomFieldResponses'].should include 'foo'
169
+ expect profile.to_h['CustomFieldResponses']['foo'].should == 'bar'
170
+ end
171
+
172
+ it "accepts strings as custom data" do
173
+ profile = YourMembership::Profile.new
174
+ profile.custom_data['foo'] = 'bar'
175
+ expect profile.to_h['CustomFieldResponses']['foo'].should be_a(String)
176
+ end
177
+
178
+ it "accepts arrays as custom data" do
179
+ profile = YourMembership::Profile.new
180
+ profile.custom_data['foo'] = ['bar', 'bat', 'baz']
181
+ expect profile.to_h['CustomFieldResponses']['foo'].should be_a(Array)
182
+ expect profile.to_h['CustomFieldResponses']['foo'].should include 'baz'
183
+ end
184
+
185
+ it "does not contain nil keys in the 'CustomFieldResponses'" do
186
+ profile = YourMembership::Profile.new
187
+ profile.custom_data['foo'] = nil
188
+ expect profile.to_h['CustomFieldResponses'].should_not include 'foo'
189
+ end
190
+
191
+ it "does not include 'CustomFieldResponses' in the data hash when creating from a profile hash" do
192
+ profile = YourMembership::Profile.new(@sample_profile)
193
+ profile.data.should_not include 'CustomFieldResponses'
194
+ end
195
+
196
+ it "puts 'CustomFieldResponses' into the custom_data hash when creating from a profile hash" do
197
+ profile = YourMembership::Profile.new(@sample_profile)
198
+ profile.custom_data.should include 'Workingcountry'
199
+ end
200
+
201
+ it "converts 'CustomFieldResponse' values to strings or arrays" do
202
+ profile = YourMembership::Profile.new(@sample_profile)
203
+ profile.custom_data.should include 'Workingcountry'
204
+ profile.custom_data['Workingcountry'].should == "USA"
205
+ end
206
+
207
+ describe 'when there is a single CustomFieldResponse' do
208
+ it 'parses correctly' do
209
+ odd_data = @sample_profile.clone
210
+ odd_data['CustomFieldResponses'] = {
211
+ "CustomFieldResponse" => {
212
+ "Values" => {
213
+ "Value" => "None"
214
+ },
215
+ "FieldCode" => "Foundation",
216
+ "Visibility" => ""
217
+ }
218
+ }
219
+ profile = YourMembership::Profile.new(odd_data)
220
+ expect(profile.custom_data['Foundation']).to eq('None')
221
+ end
222
+ end
223
+
224
+ describe 'when there is a single CustomFieldResponse' do
225
+ it 'parses correctly' do
226
+ data = @sample_profile.clone
227
+ data['CustomFieldResponses'] = nil
228
+ profile = YourMembership::Profile.new(data)
229
+ expect(profile.custom_data).to be_empty
230
+ end
231
+ end
232
+ end