campminder 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module CampMinder
2
+ VERSION = "1.0.0" unless defined?(CampMinder::VERSION)
3
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ # Set up the VCR and record some stuff.
4
+ VCR.configure do |c|
5
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
6
+ c.hook_into :webmock
7
+ c.allow_http_connections_when_no_cassette = true
8
+ end
9
+
10
+ describe 'CampMinder API' do
11
+
12
+ let(:camp_id) { 0 }
13
+ let(:token) { 'xxxxxxxx-yyyy-aaaa-bbbb-112233445566' }
14
+
15
+ let(:household1) { { "Parent1" => { "FirstName" => 'John', "LastName" => "Doe", "LoginEmail" => "john.doe@test.com" }, "Phone" => "555-555-1212" } }
16
+ let(:household2) { { "Parent1" => { "FirstName" => 'Jane', "LastName" => "Doe", "LoginEmail" => "jane.doe@test.com" } } }
17
+ let(:camper) { "Needs example data" }
18
+ let(:lead_date) { "Needs example data" }
19
+ let(:lead_source) { "Google and Testing" }
20
+ let(:email) { 'elliott@websitesthatdostuff.com' }
21
+
22
+ let(:username) { 'test@testing.com' }
23
+ let(:password) { 'alternatePW' }
24
+
25
+ let!(:campminder) { CampMinder::CampMinder.new(camp_id, token) }
26
+
27
+ it '#initialize' do
28
+ expect(campminder.camp_id).to be(camp_id)
29
+ expect(campminder.token).to be(token)
30
+ end
31
+
32
+ it '#return_api_key' do
33
+ key = campminder.return_api_key
34
+ expect(key).not_to be_nil
35
+ end
36
+
37
+ context 'authentication' do
38
+ it '#login' do
39
+ VCR.use_cassette('login', :match_requests_on => [:path]) do
40
+ login = campminder.login(username, password)
41
+ expect(login["Success"]).to equal(true)
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'when adding a lead' do
47
+ it '#add_new_lead' do
48
+ VCR.use_cassette('add_new_lead_simple') do
49
+ lead = campminder.add_new_lead(household1, {}, {}, "", lead_source)
50
+ expect(lead["Success"]).to equal(true)
51
+ end
52
+ end
53
+
54
+ it '#add_custom_field_data for lead' do
55
+ VCR.use_cassette('add_custom_field_data') do
56
+ custom_fields = campminder.add_custom_field_data(5423669, [{"FieldID" => 63021, "Value" => "Both"}])
57
+ expect(custom_fields.first["Success"]).to equal(true)
58
+ end
59
+ end
60
+ end
61
+
62
+ context 'when getting Telegraph reports' do
63
+ it '#get_telegraph_reports' do
64
+ VCR.use_cassette('get_telegraph_reports', :match_requests_on => [:path]) do
65
+ reports = campminder.get_telegraph_reports
66
+ expect(reports["Success"]).to equal(true)
67
+ expect(reports["Result"].size).to be > 0
68
+ end
69
+ end
70
+
71
+ it '#get_telegraph_reports with invalid token' do
72
+ VCR.use_cassette('get_telegraph_reports_invalid_token', :match_requests_on => [:path]) do
73
+ campminder.token = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
74
+ reports = campminder.get_telegraph_reports
75
+ expect(reports).to equal(nil)
76
+ end
77
+ end
78
+ end
79
+
80
+ context 'when running reports' do
81
+ it '#run_report' do
82
+ VCR.use_cassette('run_report', :match_requests_on => [:path]) do
83
+ report_data = campminder.run_report(101010)
84
+
85
+ expect(report_data["Success"]).to equal(true)
86
+ expect(report_data["Result"].length).to be > 0
87
+ end
88
+ end
89
+
90
+ it '#run_report for invalid report ID' do
91
+ VCR.use_cassette('run_report_invalid_id', :match_requests_on => [:path]) do
92
+ report_data = campminder.run_report(111000)
93
+
94
+ expect(report_data["Success"]).to equal(false)
95
+ end
96
+ end
97
+
98
+ it '#run_report with invalid token' do
99
+ VCR.use_cassette('run_report_invalid_token', :match_requests_on => [:path]) do
100
+ campminder.token = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
101
+ report_data = campminder.run_report(101010)
102
+
103
+ expect(report_data).to equal(nil)
104
+ end
105
+ end
106
+ end
107
+
108
+ context 'when retrieving a user by email' do
109
+ it '#retrieve_person_id for a valid email' do
110
+ VCR.use_cassette('retrieve_user_id', :match_requests_on => [:path]) do
111
+ response = campminder.retrieve_person_id(email)
112
+
113
+ expect(response["Success"]).to be true
114
+ expect(response["Result"]).to eq 6825481
115
+ end
116
+ end
117
+
118
+ it '#retrieve_person_id for an invalid email' do
119
+ VCR.use_cassette('retrieve_user_id_invalid_email', :match_requests_on => [:path]) do
120
+ response = campminder.retrieve_person_id('nobody-at-this-address@gmail.com')
121
+
122
+ expect(response["Success"]).to be true
123
+ expect(response["Result"]).to be 0
124
+ end
125
+ end
126
+
127
+ it '#retrieve_person_id with an invalid token' do
128
+ VCR.use_cassette('retrieve_user_id_invalid_token', :match_requests_on => [:path]) do
129
+ campminder.token = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
130
+ response = campminder.retrieve_person_id(email)
131
+
132
+ expect(response).to eq nil
133
+ end
134
+ end
135
+
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://webapi.campminder.com/api/entity/customfield/modifyentitydatafields
6
+ body:
7
+ encoding: UTF-8
8
+ string: '[{"Data":[{"FieldID":11122,"Value":"Both"}],"EntityTypeID":1,"ObjectID":1122334}]'
9
+ headers:
10
+ Authorization-Token:
11
+ - 1502014-07-21T21:33:10.393Zd8c1d9dbd36dd4be0cc7a8dd27b61208735c3f51
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Cache-Control:
20
+ - no-cache
21
+ Pragma:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Expires:
26
+ - "-1"
27
+ Server:
28
+ - Microsoft-IIS/7.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ X-Powered-By:
32
+ - ASP.NET
33
+ Date:
34
+ - Mon, 21 Jul 2014 21:33:10 GMT
35
+ Connection:
36
+ - close
37
+ Content-Length:
38
+ - '98'
39
+ body:
40
+ encoding: UTF-8
41
+ string: '[{"Result":{"ObjectID":1122334,"EntityTypeID":1,"FieldID":11122},"Success":true,"ErrorText":null}]'
42
+ http_version:
43
+ recorded_at: Mon, 21 Jul 2014 21:33:10 GMT
44
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://webapi.campminder.com/api/entity/person/camper/camper/addnewcamper
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"Household1":{"Parent1":{"FirstName":"John","LastName":"Doe","LoginEmail":"john.doe@test.com"},"Phone":"555-555-1212"},"Household2":{},"Camper":{},"LeadDate":"","LeadSource":"Google and Testing"}'
9
+ headers:
10
+ Authorization-Token:
11
+ - 02014-07-21T21:35:05.716Z66911c274233d13246e1cc1e6a45175bff0c1a0d
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Cache-Control:
20
+ - no-cache
21
+ Pragma:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Expires:
26
+ - "-1"
27
+ Server:
28
+ - Microsoft-IIS/7.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ X-Powered-By:
32
+ - ASP.NET
33
+ Date:
34
+ - Mon, 21 Jul 2014 21:35:05 GMT
35
+ Connection:
36
+ - close
37
+ Content-Length:
38
+ - '146'
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"Result":{"Household1":{"ID":1122334,"Parent1ID":1122333,"Parent2ID":null},"Household2":null,"CamperID":2233445},"Success":true,"ErrorText":null}'
42
+ http_version:
43
+ recorded_at: Mon, 21 Jul 2014 21:35:06 GMT
44
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://webapi.campminder.com/api/customdata/telegraph/getsavedreports
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization-Token:
11
+ - 92014-08-05T15:04:13.008Z0857f3c431965e0b9d07ec176203f5a390ca113b
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Cache-Control:
20
+ - no-cache
21
+ Pragma:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Expires:
26
+ - "-1"
27
+ Server:
28
+ - Microsoft-IIS/7.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ X-Powered-By:
32
+ - ASP.NET
33
+ Date:
34
+ - Fri, 05 Sep 2014 15:04:12 GMT
35
+ Connection:
36
+ - close
37
+ Content-Length:
38
+ - '95'
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"Result":[{"ID":101010,"Name":"CamperAlpha","Type":"camper"}],"Success":true,"ErrorText":null}'
42
+ http_version:
43
+ recorded_at: Fri, 05 Sep 2014 15:04:13 GMT
44
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://webapi.campminder.com/api/customdata/telegraph/getsavedreports
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization-Token:
11
+ - 12014-07-05T15:04:12.690Z712a55d3d84cd9d0674f800cc39bd39d4bb3c8a8
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 403
17
+ message: Forbidden
18
+ headers:
19
+ Cache-Control:
20
+ - no-cache
21
+ Pragma:
22
+ - no-cache
23
+ Expires:
24
+ - "-1"
25
+ Server:
26
+ - Microsoft-IIS/7.5
27
+ X-Aspnet-Version:
28
+ - 4.0.30319
29
+ X-Powered-By:
30
+ - ASP.NET
31
+ Date:
32
+ - Fri, 05 Sep 2014 15:04:12 GMT
33
+ Connection:
34
+ - close
35
+ Content-Length:
36
+ - '0'
37
+ body:
38
+ encoding: UTF-8
39
+ string: ''
40
+ http_version:
41
+ recorded_at: Fri, 05 Sep 2014 15:04:13 GMT
42
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://webapi.campminder.com/api/security/user/GetRemoteLoginRedirect?apikey=12014-07-21T20:48:16.950Z6f2deb679b508a4ce7308bb653f1f9fb4e9d2d41&c=2&callback=a&i=test@testing.com&p=alternatePW
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/javascript
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Cache-Control:
18
+ - no-cache
19
+ Pragma:
20
+ - no-cache
21
+ Content-Type:
22
+ - application/javascript; charset=utf-8
23
+ Expires:
24
+ - "-1"
25
+ Server:
26
+ - Microsoft-IIS/7.5
27
+ X-Aspnet-Version:
28
+ - 4.0.30319
29
+ X-Powered-By:
30
+ - ASP.NET
31
+ Date:
32
+ - Mon, 21 Jul 2014 20:48:17 GMT
33
+ Connection:
34
+ - close
35
+ Content-Length:
36
+ - '200'
37
+ body:
38
+ encoding: UTF-8
39
+ string: a({"Result":{"ClientID":351,"PersonID":1518131,"RedirectUrl":"https://boulder.campintouch.com/v2/login/apitokenlogin.aspx?token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"},"Success":true,"ErrorText":null})
40
+ http_version:
41
+ recorded_at: Mon, 21 Jul 2014 20:48:17 GMT
42
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://webapi.campminder.com/api/entity/person/getpersonidfromemail?email=elliott@websitesthatdostuff.com
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization-Token:
11
+ - 1952015-08-07T13:00:35.081Zf69b515044138c9816cc770183d61e38151d4176
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Cache-Control:
20
+ - no-cache
21
+ Pragma:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Expires:
26
+ - "-1"
27
+ Server:
28
+ - Microsoft-IIS/7.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ Srv:
32
+ - spruce
33
+ Date:
34
+ - Fri, 07 Aug 2015 13:00:31 GMT
35
+ Connection:
36
+ - close
37
+ Content-Length:
38
+ - '50'
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"Result":6825481,"Success":true,"ErrorText":null}'
42
+ http_version:
43
+ recorded_at: Fri, 07 Aug 2015 13:00:35 GMT
44
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://beta-webapi.campminder.com/api/entity/person/getpersonidfromemail?email=nobody-at-this-address@gmail.com
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization-Token:
11
+ - 1952015-07-20T18:49:50.000Zde0a0c2694419d626127034089e62bf01891c593
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Cache-Control:
20
+ - no-cache
21
+ Pragma:
22
+ - no-cache
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Expires:
26
+ - "-1"
27
+ Server:
28
+ - Microsoft-IIS/7.5
29
+ X-Aspnet-Version:
30
+ - 4.0.30319
31
+ X-Powered-By:
32
+ - ASP.NET
33
+ Date:
34
+ - Mon, 20 Jul 2015 18:49:49 GMT
35
+ Connection:
36
+ - close
37
+ Content-Length:
38
+ - '44'
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"Result":0,"Success":true,"ErrorText":null}'
42
+ http_version:
43
+ recorded_at: Mon, 20 Jul 2015 18:49:50 GMT
44
+ recorded_with: VCR 2.9.3