appboy 0.0.1 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -0
  4. data/README.md +165 -21
  5. data/appboy.gemspec +18 -10
  6. data/lib/appboy.rb +5 -3
  7. data/lib/appboy/api.rb +27 -30
  8. data/lib/appboy/deprecated.rb +19 -0
  9. data/lib/appboy/endpoints/delete_users.rb +15 -0
  10. data/lib/appboy/endpoints/email_status.rb +13 -0
  11. data/lib/appboy/endpoints/list_canvas.rb +15 -0
  12. data/lib/appboy/endpoints/schedule_messages.rb +15 -0
  13. data/lib/appboy/endpoints/send_messages.rb +15 -0
  14. data/lib/appboy/endpoints/track_users.rb +29 -0
  15. data/lib/appboy/endpoints/trigger_campaign.rb +15 -0
  16. data/lib/appboy/endpoints/trigger_canvas.rb +15 -0
  17. data/lib/appboy/http.rb +32 -0
  18. data/lib/appboy/rest.rb +11 -0
  19. data/lib/appboy/rest/base.rb +15 -0
  20. data/lib/appboy/rest/delete_users.rb +21 -0
  21. data/lib/appboy/rest/email_status.rb +21 -0
  22. data/lib/appboy/rest/export_users.rb +27 -0
  23. data/lib/appboy/rest/list_canvas.rb +21 -0
  24. data/lib/appboy/rest/list_segments.rb +11 -0
  25. data/lib/appboy/rest/schedule_messages.rb +25 -0
  26. data/lib/appboy/rest/send_messages.rb +23 -0
  27. data/lib/appboy/rest/track_users.rb +14 -0
  28. data/lib/appboy/rest/trigger_campaign.rb +30 -0
  29. data/lib/appboy/rest/trigger_canvas.rb +28 -0
  30. data/lib/appboy/version.rb +1 -1
  31. data/spec/appboy/api_spec.rb +4 -0
  32. data/spec/appboy/endpoints/track_users_spec.rb +72 -0
  33. data/spec/appboy/endpoints/trigger_campaigns_spec.rb +47 -0
  34. data/spec/appboy/endpoints/trigger_canvas_spec.rb +47 -0
  35. data/spec/appboy/http_spec.rb +19 -0
  36. data/spec/appboy/rest/delete_users_spec.rb +23 -0
  37. data/spec/appboy/rest/email_status_spec.rb +19 -0
  38. data/spec/appboy/rest/export_users_spec.rb +20 -0
  39. data/spec/appboy/rest/list_canvas_spec.rb +23 -0
  40. data/spec/appboy/rest/schedule_messages_spec.rb +34 -0
  41. data/spec/appboy/rest/send_messages_spec.rb +36 -0
  42. data/spec/appboy/rest/track_users_spec.rb +24 -0
  43. data/spec/appboy/rest/trigger_campaign_spec.rb +50 -0
  44. data/spec/appboy/rest/trigger_canvas_spec.rb +47 -0
  45. data/spec/factories.rb +44 -0
  46. data/spec/fixtures/responses/delete_users/unauthorized/responds_with_unauthorized.yml +58 -0
  47. data/spec/fixtures/responses/delete_users/with_success/responds_with_created.yml +58 -0
  48. data/spec/fixtures/responses/delete_users/with_success/responds_with_success_message.yml +58 -0
  49. data/spec/fixtures/responses/email_status/existing_email/responds_with_created.yml +54 -0
  50. data/spec/fixtures/responses/email_status/existing_email/responds_with_success_message.yml +54 -0
  51. data/spec/fixtures/responses/email_status/unknown_email/responds_with_bad_request.yml +52 -0
  52. data/spec/fixtures/responses/email_status/unknown_email/responds_with_error_message.yml +52 -0
  53. data/spec/fixtures/responses/export_users/by_ids/with_success/responds_with_created.yml +56 -0
  54. data/spec/fixtures/responses/export_users/by_segment/with_success/responds_with_created.yml +54 -0
  55. data/spec/fixtures/responses/list_canvas/with_success/responds_with_a_list_of_segments.yml +67 -0
  56. data/spec/fixtures/responses/list_canvas/with_success/responds_with_success.yml +67 -0
  57. data/spec/fixtures/responses/list_segments/with_success/responds_with_a_list_of_segments.yml +58 -0
  58. data/spec/fixtures/responses/list_segments/with_success/responds_with_success.yml +58 -0
  59. data/spec/fixtures/responses/schedule_messages/unauthorized/responds_with_unauthorize.yml +53 -0
  60. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_created.yml +55 -0
  61. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_success_message.yml +55 -0
  62. data/spec/fixtures/responses/send_messages/unauthorized/responds_with_unauthorized.yml +52 -0
  63. data/spec/fixtures/responses/send_messages/with_success/responds_with_created.yml +54 -0
  64. data/spec/fixtures/responses/send_messages/with_success/responds_with_success_message.yml +54 -0
  65. data/spec/fixtures/responses/track_users/unauthorized/responds_with_unauthorized.yml +54 -0
  66. data/spec/fixtures/responses/track_users/with_success/responds_with_created.yml +56 -0
  67. data/spec/fixtures/responses/track_users/with_success/responds_with_success_message.yml +56 -0
  68. data/spec/integrations/delete_users_spec.rb +30 -0
  69. data/spec/integrations/email_status_spec.rb +36 -0
  70. data/spec/integrations/export_users_spec.rb +27 -0
  71. data/spec/integrations/list_canvas_spec.rb +21 -0
  72. data/spec/integrations/list_segments_spec.rb +21 -0
  73. data/spec/integrations/schedule_messages_spec.rb +31 -0
  74. data/spec/integrations/send_messages_spec.rb +30 -0
  75. data/spec/integrations/track_users_spec.rb +35 -0
  76. data/spec/spec_helper.rb +10 -1
  77. data/spec/support/factory_girl.rb +10 -0
  78. data/spec/support/integrations.rb +19 -0
  79. data/spec/support/vcr.rb +17 -0
  80. metadata +248 -19
  81. data/spec/api_spec.rb +0 -60
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.appboy.com/messages/send
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"non-existent","messages":{"apple_push":{"alert":"hello"}},"external_user_ids":[1],"segment_ids":[]}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Content-Type:
13
+ - application/json
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 401
21
+ message: Unauthorized
22
+ headers:
23
+ Server:
24
+ - nginx/1.6.2
25
+ Date:
26
+ - Mon, 16 Feb 2015 02:04:32 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ X-Cnection:
32
+ - close
33
+ Status:
34
+ - 401 Unauthorized
35
+ Strict-Transport-Security:
36
+ - max-age=31536000
37
+ X-Ua-Compatible:
38
+ - IE=Edge,chrome=1
39
+ Cache-Control:
40
+ - no-cache
41
+ X-Request-Id:
42
+ - 6084cafff4e655159039431f6fa925e7
43
+ X-Runtime:
44
+ - '0.017868'
45
+ Vary:
46
+ - Accept-Encoding
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"message":"Invalid or missing App Group API Identifier: non-existent"}'
50
+ http_version:
51
+ recorded_at: Mon, 16 Feb 2015 02:04:32 GMT
52
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.appboy.com/messages/send
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"<APPBOY_GROUP_ID>","messages":{"apple_push":{"alert":"hello"}},"external_user_ids":[1],"segment_ids":[]}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Content-Type:
13
+ - application/json
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 201
21
+ message: Created
22
+ headers:
23
+ Server:
24
+ - nginx/1.6.2
25
+ Date:
26
+ - Mon, 16 Feb 2015 02:04:32 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 201 Created
35
+ Strict-Transport-Security:
36
+ - max-age=31536000
37
+ X-Ua-Compatible:
38
+ - IE=Edge,chrome=1
39
+ Etag:
40
+ - '"8736cdfe08480bca66cffeee06268705"'
41
+ Cache-Control:
42
+ - max-age=0, private, must-revalidate
43
+ X-Request-Id:
44
+ - dafade35dada6bc0693c1e8b39153078
45
+ X-Runtime:
46
+ - '0.007953'
47
+ Vary:
48
+ - Accept-Encoding
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"message":"success"}'
52
+ http_version:
53
+ recorded_at: Mon, 16 Feb 2015 02:04:32 GMT
54
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.appboy.com/messages/send
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"<APPBOY_GROUP_ID>","messages":{"apple_push":{"alert":"hello"}},"external_user_ids":[1],"segment_ids":[]}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Content-Type:
13
+ - application/json
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 201
21
+ message: Created
22
+ headers:
23
+ Server:
24
+ - nginx/1.6.2
25
+ Date:
26
+ - Mon, 16 Feb 2015 02:04:32 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 201 Created
35
+ Strict-Transport-Security:
36
+ - max-age=31536000
37
+ X-Ua-Compatible:
38
+ - IE=Edge,chrome=1
39
+ Etag:
40
+ - '"8736cdfe08480bca66cffeee06268705"'
41
+ Cache-Control:
42
+ - max-age=0, private, must-revalidate
43
+ X-Request-Id:
44
+ - f55537eeed57f01f6fa0a6aca87c23a0
45
+ X-Runtime:
46
+ - '0.007894'
47
+ Vary:
48
+ - Accept-Encoding
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"message":"success"}'
52
+ http_version:
53
+ recorded_at: Mon, 16 Feb 2015 02:04:32 GMT
54
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.appboy.com/users/track
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"non-existent","attributes":[{"external_id":1,"foo":"bar"}],"events":[{"external_id":1,"name":"baz","time":"2015-02-15
9
+ 00:00:00 -0500"}],"purchases":[{"external_id":1,"product_id":1,"time":"2015-02-15
10
+ 00:00:00 -0500","currency":"CAD","price":1.0}]}'
11
+ headers:
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 401
23
+ message: Unauthorized
24
+ headers:
25
+ Server:
26
+ - nginx/1.6.2
27
+ Date:
28
+ - Mon, 16 Feb 2015 02:04:33 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Status:
36
+ - 401 Unauthorized
37
+ Strict-Transport-Security:
38
+ - max-age=31536000
39
+ X-Ua-Compatible:
40
+ - IE=Edge,chrome=1
41
+ Cache-Control:
42
+ - no-cache
43
+ X-Request-Id:
44
+ - e002507637bca77d75747d5ce4eb2eab
45
+ X-Runtime:
46
+ - '0.018230'
47
+ Vary:
48
+ - Accept-Encoding
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"message":"Invalid or missing App Group API Identifier: non-existent"}'
52
+ http_version:
53
+ recorded_at: Mon, 16 Feb 2015 02:04:33 GMT
54
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.appboy.com/users/track
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"<APPBOY_GROUP_ID>","attributes":[{"external_id":1,"foo":"bar"}],"events":[{"external_id":1,"name":"baz","time":"2015-02-15
9
+ 00:00:00 -0500"}],"purchases":[{"external_id":1,"product_id":1,"time":"2015-02-15
10
+ 00:00:00 -0500","currency":"CAD","price":1.0}]}'
11
+ headers:
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Server:
26
+ - nginx/1.6.2
27
+ Date:
28
+ - Mon, 16 Feb 2015 02:04:32 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Status:
36
+ - 201 Created
37
+ Strict-Transport-Security:
38
+ - max-age=31536000
39
+ X-Ua-Compatible:
40
+ - IE=Edge,chrome=1
41
+ Etag:
42
+ - '"79557eda34d1dfcacc80cdd626202b9a"'
43
+ Cache-Control:
44
+ - max-age=0, private, must-revalidate
45
+ X-Request-Id:
46
+ - 68c4d37952f3f900cd83820409e74696
47
+ X-Runtime:
48
+ - '0.008458'
49
+ Vary:
50
+ - Accept-Encoding
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"attributes_processed":1,"events_processed":1,"purchases_processed":1,"message":"success"}'
54
+ http_version:
55
+ recorded_at: Mon, 16 Feb 2015 02:04:32 GMT
56
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.appboy.com/users/track
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"<APPBOY_GROUP_ID>","attributes":[{"external_id":1,"foo":"bar"}],"events":[{"external_id":1,"name":"baz","time":"2015-02-15
9
+ 00:00:00 -0500"}],"purchases":[{"external_id":1,"product_id":1,"time":"2015-02-15
10
+ 00:00:00 -0500","currency":"CAD","price":1.0}]}'
11
+ headers:
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Server:
26
+ - nginx/1.6.2
27
+ Date:
28
+ - Mon, 16 Feb 2015 02:04:33 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Status:
36
+ - 201 Created
37
+ Strict-Transport-Security:
38
+ - max-age=31536000
39
+ X-Ua-Compatible:
40
+ - IE=Edge,chrome=1
41
+ Etag:
42
+ - '"79557eda34d1dfcacc80cdd626202b9a"'
43
+ Cache-Control:
44
+ - max-age=0, private, must-revalidate
45
+ X-Request-Id:
46
+ - 5a25265723e1309578e13dc0d22e6edb
47
+ X-Runtime:
48
+ - '0.007930'
49
+ Vary:
50
+ - Accept-Encoding
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"attributes_processed":1,"events_processed":1,"purchases_processed":1,"message":"success"}'
54
+ http_version:
55
+ recorded_at: Mon, 16 Feb 2015 02:04:32 GMT
56
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'delete users' do
4
+ let(:external_ids) { build(:external_ids) }
5
+
6
+ subject(:delete_users) do
7
+ api.delete_users(external_ids)
8
+ end
9
+
10
+ context 'with success', vcr: true do
11
+ it 'responds with created' do
12
+ expect(delete_users.status).to be 201
13
+ end
14
+
15
+ it 'responds with success message' do
16
+ expect(JSON.parse(delete_users.body)).to eq(
17
+ 'deleted' => 2,
18
+ 'message' => 'success'
19
+ )
20
+ end
21
+ end
22
+
23
+ context 'unauthorized', vcr: true do
24
+ let(:app_group_id) { 'non-existent' }
25
+
26
+ it 'responds with unauthorized' do
27
+ expect(delete_users.status).to be 401
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'email status' do
4
+ let(:email) { 'john@example.com' }
5
+ let(:status) { :unsubscribed }
6
+
7
+ subject do
8
+ api.email_status(email: email, status: status)
9
+ end
10
+
11
+ context 'existing email', vcr: true do
12
+ it 'responds with created' do
13
+ expect(subject.status).to be 201
14
+ end
15
+
16
+ it 'responds with success message' do
17
+ expect(JSON.parse(subject.body)).to eq(
18
+ 'message' => 'success'
19
+ )
20
+ end
21
+ end
22
+
23
+ context 'unknown email', vcr: true do
24
+ let(:email) { 'doesntexist@example.com' }
25
+
26
+ it 'responds with bad request' do
27
+ expect(subject.status).to be 400
28
+ end
29
+
30
+ it 'responds with error message' do
31
+ expect(JSON.parse(subject.body)).to eq(
32
+ 'message' => 'There is no user with the provided email'
33
+ )
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'export users' do
4
+ context 'by ids' do
5
+ subject(:export_users) { api.export_users(external_ids: [1]) }
6
+
7
+ context 'with success', :vcr do
8
+ it 'responds with created' do
9
+ expect(export_users).to be_success
10
+ end
11
+ end
12
+ end
13
+
14
+ context 'by segment' do
15
+ context 'with success', :vcr do
16
+ let(:segment_id) { ENV.fetch('APPBOY_TEST_SEGMENT') }
17
+
18
+ subject(:export_users) do
19
+ api.export_users(segment_id: segment_id, callback_endpoint: 'https://example.com')
20
+ end
21
+
22
+ it 'responds with created' do
23
+ expect(export_users).to be_success
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'list canvas' do
4
+ subject(:list_canvas) { api.list_canvas }
5
+
6
+ context 'with success', :vcr do
7
+ it 'responds with success' do
8
+ expect(list_canvas).to be_success
9
+ end
10
+
11
+ it 'responds with a list of segments' do
12
+ expect(canvases.count).to be 4
13
+
14
+ expect(canvases.first['name']).to eq 'ONBOARDING_NEW SUBSCRIBERS'
15
+ end
16
+
17
+ def canvases
18
+ JSON.parse(list_canvas.body)['canvases']
19
+ end
20
+ end
21
+ end