appboy 0.0.1 → 0.1.2

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -0
  4. data/README.md +111 -21
  5. data/appboy.gemspec +18 -10
  6. data/lib/appboy.rb +5 -3
  7. data/lib/appboy/api.rb +18 -30
  8. data/lib/appboy/deprecated.rb +19 -0
  9. data/lib/appboy/endpoints/email_status.rb +13 -0
  10. data/lib/appboy/endpoints/schedule_messages.rb +15 -0
  11. data/lib/appboy/endpoints/send_messages.rb +15 -0
  12. data/lib/appboy/endpoints/track_users.rb +29 -0
  13. data/lib/appboy/http.rb +24 -0
  14. data/lib/appboy/rest.rb +7 -0
  15. data/lib/appboy/rest/base.rb +15 -0
  16. data/lib/appboy/rest/email_status.rb +21 -0
  17. data/lib/appboy/rest/export_users.rb +27 -0
  18. data/lib/appboy/rest/list_segments.rb +11 -0
  19. data/lib/appboy/rest/schedule_messages.rb +25 -0
  20. data/lib/appboy/rest/send_messages.rb +23 -0
  21. data/lib/appboy/rest/track_users.rb +14 -0
  22. data/lib/appboy/version.rb +1 -1
  23. data/spec/appboy/api_spec.rb +4 -0
  24. data/spec/appboy/endpoints/track_users_spec.rb +72 -0
  25. data/spec/appboy/rest/email_status_spec.rb +19 -0
  26. data/spec/appboy/rest/export_users_spec.rb +20 -0
  27. data/spec/appboy/rest/schedule_messages_spec.rb +34 -0
  28. data/spec/appboy/rest/send_messages_spec.rb +36 -0
  29. data/spec/appboy/rest/track_users_spec.rb +24 -0
  30. data/spec/factories.rb +32 -0
  31. data/spec/fixtures/responses/email_status/existing_email/responds_with_created.yml +54 -0
  32. data/spec/fixtures/responses/email_status/existing_email/responds_with_success_message.yml +54 -0
  33. data/spec/fixtures/responses/email_status/unknown_email/responds_with_bad_request.yml +52 -0
  34. data/spec/fixtures/responses/email_status/unknown_email/responds_with_error_message.yml +52 -0
  35. data/spec/fixtures/responses/export_users/by_ids/with_success/responds_with_created.yml +56 -0
  36. data/spec/fixtures/responses/export_users/by_segment/with_success/responds_with_created.yml +54 -0
  37. data/spec/fixtures/responses/list_segments/with_success/responds_with_a_list_of_segments.yml +58 -0
  38. data/spec/fixtures/responses/list_segments/with_success/responds_with_success.yml +58 -0
  39. data/spec/fixtures/responses/schedule_messages/unauthorized/responds_with_unauthorize.yml +53 -0
  40. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_created.yml +55 -0
  41. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_success_message.yml +55 -0
  42. data/spec/fixtures/responses/send_messages/unauthorized/responds_with_unauthorized.yml +52 -0
  43. data/spec/fixtures/responses/send_messages/with_success/responds_with_created.yml +54 -0
  44. data/spec/fixtures/responses/send_messages/with_success/responds_with_success_message.yml +54 -0
  45. data/spec/fixtures/responses/track_users/unauthorized/responds_with_unauthorized.yml +54 -0
  46. data/spec/fixtures/responses/track_users/with_success/responds_with_created.yml +56 -0
  47. data/spec/fixtures/responses/track_users/with_success/responds_with_success_message.yml +56 -0
  48. data/spec/integrations/email_status_spec.rb +36 -0
  49. data/spec/integrations/export_users_spec.rb +27 -0
  50. data/spec/integrations/list_segments_spec.rb +21 -0
  51. data/spec/integrations/schedule_messages_spec.rb +31 -0
  52. data/spec/integrations/send_messages_spec.rb +30 -0
  53. data/spec/integrations/track_users_spec.rb +35 -0
  54. data/spec/spec_helper.rb +10 -1
  55. data/spec/support/factory_girl.rb +10 -0
  56. data/spec/support/integrations.rb +19 -0
  57. data/spec/support/vcr.rb +17 -0
  58. metadata +212 -18
  59. data/spec/api_spec.rb +0 -60
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.appboy.com/messages/schedule
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"<APPBOY_GROUP_ID>","segment_ids":["<APPBOY_TEST_SEGMENT>"],"send_at":"2015-02-15
9
+ 00:00:00 -0500","deliver_in_local_timezone":false,"messages":{"apple_push":{"alert":"hello"}}}'
10
+ headers:
11
+ User-Agent:
12
+ - Faraday v0.9.1
13
+ Content-Type:
14
+ - application/json
15
+ Accept-Encoding:
16
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
17
+ Accept:
18
+ - "*/*"
19
+ response:
20
+ status:
21
+ code: 201
22
+ message: Created
23
+ headers:
24
+ Server:
25
+ - nginx/1.6.2
26
+ Date:
27
+ - Mon, 16 Feb 2015 02:04:31 GMT
28
+ Content-Type:
29
+ - application/json
30
+ Transfer-Encoding:
31
+ - chunked
32
+ Connection:
33
+ - keep-alive
34
+ Status:
35
+ - 201 Created
36
+ Strict-Transport-Security:
37
+ - max-age=31536000
38
+ X-Ua-Compatible:
39
+ - IE=Edge,chrome=1
40
+ Etag:
41
+ - '"8736cdfe08480bca66cffeee06268705"'
42
+ Cache-Control:
43
+ - max-age=0, private, must-revalidate
44
+ X-Request-Id:
45
+ - 87445394eda38e6726c16d401e2ddd20
46
+ X-Runtime:
47
+ - '0.010460'
48
+ Vary:
49
+ - Accept-Encoding
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"message":"success"}'
53
+ http_version:
54
+ recorded_at: Mon, 16 Feb 2015 02:04:31 GMT
55
+ recorded_with: VCR 2.9.2
@@ -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,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