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,21 @@
1
+ module Appboy
2
+ module REST
3
+ class EmailStatus < Base
4
+ attr_reader :app_group_id, :email, :status
5
+
6
+ def initialize(app_group_id, email:, status:)
7
+ @app_group_id = app_group_id
8
+ @email = email
9
+ @status = status
10
+ end
11
+
12
+ def perform
13
+ http.post '/email/status', {
14
+ app_group_id: app_group_id,
15
+ email: email,
16
+ subscription_state: status
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module Appboy
2
+ module REST
3
+ class ExportUsers < Base
4
+ def perform(app_group_id, external_ids: nil, segment_id: nil, **options)
5
+ return export_users_by_ids(app_group_id, external_ids) if external_ids
6
+
7
+ export_users_by_segment(app_group_id, segment_id, options) if segment_id
8
+ end
9
+
10
+ private
11
+
12
+ def export_users_by_ids(app_group_id, external_ids)
13
+ http.post '/users/export/ids', {
14
+ app_group_id: app_group_id,
15
+ external_ids: external_ids
16
+ }
17
+ end
18
+
19
+ def export_users_by_segment(app_group_id, segment_id, options)
20
+ http.post '/users/export/segment', {
21
+ app_group_id: app_group_id,
22
+ segment_id: segment_id
23
+ }.merge(options)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Appboy
2
+ module REST
3
+ class ListSegments < Base
4
+ def perform(app_group_id)
5
+ http.get '/segments/list', {
6
+ app_group_id: app_group_id
7
+ }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module Appboy
2
+ module REST
3
+ class ScheduleMessages < Base
4
+ attr_reader :app_group_id, :send_at, :messages, :segment_id, :local_timezone
5
+
6
+ def initialize(app_group_id, send_at:, messages: [], segment_id: nil, local_timezone: false)
7
+ @app_group_id = app_group_id
8
+ @send_at = send_at
9
+ @messages = messages
10
+ @segment_id = segment_id
11
+ @local_timezone = local_timezone
12
+ end
13
+
14
+ def perform
15
+ http.post '/messages/schedule', {
16
+ app_group_id: app_group_id,
17
+ segment_ids: [segment_id],
18
+ send_at: send_at,
19
+ deliver_in_local_timezone: local_timezone,
20
+ messages: messages
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ module Appboy
2
+ module REST
3
+ class SendMessages < Base
4
+ attr_reader :app_group_id, :messages, :external_user_ids, :segment_id
5
+
6
+ def initialize(app_group_id, messages: [], external_user_ids: [], segment_id: nil)
7
+ @app_group_id = app_group_id
8
+ @messages = messages
9
+ @external_user_ids = external_user_ids
10
+ @segment_id = segment_id
11
+ end
12
+
13
+ def perform
14
+ http.post '/messages/send', {
15
+ app_group_id: app_group_id,
16
+ messages: messages,
17
+ external_user_ids: external_user_ids,
18
+ segment_ids: [segment_id].compact
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module Appboy
2
+ module REST
3
+ class TrackUsers < Base
4
+ def perform(app_group_id, attributes: [], events: [], purchases: [])
5
+ http.post '/users/track', {
6
+ app_group_id: app_group_id,
7
+ attributes: attributes,
8
+ events: events,
9
+ purchases: purchases
10
+ }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Appboy
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.2'
3
3
  end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Appboy::API do
4
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ class API
4
+ include Appboy::Endpoints::TrackUsers
5
+
6
+ def app_group_id
7
+ :app_group_id
8
+ end
9
+ end
10
+
11
+ describe Appboy::Endpoints::TrackUsers do
12
+ let(:api) { API.new }
13
+ let(:track_users_service) { double(:track_users_service) }
14
+
15
+ before { api.track_users_service = track_users_service }
16
+
17
+ describe '#track_users' do
18
+ let(:payload) {{
19
+ attributes: [build(:attribute)],
20
+ events: [build(:event)],
21
+ purchases: [build(:purchase)]
22
+ }}
23
+
24
+ subject(:track_users!) { api.track_users(payload) }
25
+
26
+ it 'tracks attributes, events and purchases' do
27
+ expect(track_users_service).to receive(:perform)
28
+ .with(:app_group_id, payload)
29
+
30
+ track_users!
31
+ end
32
+ end
33
+
34
+ describe '#track_purchase' do
35
+ let(:payload) { build(:purchase) }
36
+
37
+ subject(:track_purchase!) { api.track_purchase(payload) }
38
+
39
+ it 'tracks a single purchase' do
40
+ expect(track_users_service).to receive(:perform)
41
+ .with(:app_group_id, purchases: [payload])
42
+
43
+ track_purchase!
44
+ end
45
+ end
46
+
47
+ describe '#track_event' do
48
+ let(:payload) { build(:event) }
49
+
50
+ subject(:track_event!) { api.track_event(payload) }
51
+
52
+ it 'tracks a single purchase' do
53
+ expect(track_users_service).to receive(:perform)
54
+ .with(:app_group_id, events: [payload])
55
+
56
+ track_event!
57
+ end
58
+ end
59
+
60
+ describe '#track_attribute' do
61
+ let(:payload) { build(:attribute) }
62
+
63
+ subject(:track_attribute!) { api.track_attribute(payload) }
64
+
65
+ it 'tracks a single purchase' do
66
+ expect(track_users_service).to receive(:perform)
67
+ .with(:app_group_id, attributes: [payload])
68
+
69
+ track_attribute!
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Appboy::REST::EmailStatus do
4
+ let(:http) { double(:http) }
5
+
6
+ before { subject.http = http }
7
+
8
+ subject { described_class.new(:app_group_id, email: :email, status: :status) }
9
+
10
+ it 'makes an http call to the email status endpoint' do
11
+ expect(http).to receive(:post).with '/email/status', {
12
+ app_group_id: :app_group_id,
13
+ email: :email,
14
+ subscription_state: :status
15
+ }
16
+
17
+ subject.perform
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Appboy::REST::ExportUsers do
4
+ let(:http) { double(:http) }
5
+
6
+ let(:payload) {{ external_ids: :external_ids }}
7
+
8
+ let(:app_group_id) { :app_group_id }
9
+
10
+ subject { described_class.new }
11
+
12
+ before { subject.http = http }
13
+
14
+ it 'makes an http call to the track user endpoint' do
15
+ expect(http).to receive(:post).with '/users/export/ids',
16
+ payload.merge({ app_group_id: :app_group_id })
17
+
18
+ subject.perform(app_group_id, payload)
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Appboy::REST::ScheduleMessages do
4
+ let(:http) { double(:http) }
5
+
6
+ let(:payload) {{
7
+ send_at: :send_at,
8
+ segment_id: :segment_id,
9
+ local_timezone: :local_timezone,
10
+ messages: :messages
11
+ }}
12
+
13
+ let(:app_group_id) { :app_group_id }
14
+
15
+ subject { described_class.new(app_group_id, payload) }
16
+
17
+ before { subject.http = http }
18
+
19
+ it 'makes an http call to the schedule messages endpoint' do
20
+ expect_schedule_messages_http_call
21
+
22
+ subject.perform
23
+ end
24
+
25
+ def expect_schedule_messages_http_call
26
+ expect(http).to receive(:post).with '/messages/schedule', {
27
+ app_group_id: app_group_id,
28
+ segment_ids: [:segment_id],
29
+ send_at: :send_at,
30
+ deliver_in_local_timezone: :local_timezone,
31
+ messages: :messages
32
+ }
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Appboy::REST::SendMessages do
4
+ let(:http) { double(:http) }
5
+
6
+ let(:payload) {{
7
+ messages: :messages,
8
+ external_user_ids: :external_user_ids,
9
+ segment_id: :segment_id
10
+ }}
11
+
12
+ let(:app_group_id) { :app_group_id }
13
+
14
+ subject { described_class.new(app_group_id,
15
+ messages: :messages,
16
+ external_user_ids: :external_user_ids,
17
+ segment_id: :segment_id
18
+ ) }
19
+
20
+ before { subject.http = http }
21
+
22
+ it 'makes an http call to the send messages endpoint' do
23
+ expect_send_messages_http_call
24
+
25
+ subject.perform
26
+ end
27
+
28
+ def expect_send_messages_http_call
29
+ expect(http).to receive(:post).with '/messages/send', {
30
+ app_group_id: :app_group_id,
31
+ messages: :messages,
32
+ external_user_ids: :external_user_ids,
33
+ segment_ids: [:segment_id]
34
+ }
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Appboy::REST::TrackUsers do
4
+ let(:http) { double(:http) }
5
+
6
+ let(:payload) {{
7
+ attributes: :attributes,
8
+ events: :events,
9
+ purchases: :purchases
10
+ }}
11
+
12
+ let(:app_group_id) { :app_group_id }
13
+
14
+ subject { described_class.new }
15
+
16
+ before { subject.http = http }
17
+
18
+ it 'makes an http call to the track user endpoint' do
19
+ expect(http).to receive(:post).with '/users/track',
20
+ payload.merge({ app_group_id: :app_group_id })
21
+
22
+ subject.perform(app_group_id, payload)
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ FactoryGirl.define do
2
+ factory :attribute, class: Hash do
3
+ external_id 1
4
+ foo :bar
5
+
6
+ initialize_with { attributes }
7
+ end
8
+
9
+ factory :event, class: Hash do
10
+ external_id 1
11
+ name :baz
12
+ time Time.now
13
+
14
+ initialize_with { attributes }
15
+ end
16
+
17
+ factory :purchase, class: Hash do
18
+ external_id 1
19
+ product_id 1
20
+ time Time.now
21
+ currency 'CAD'
22
+ price 1.0
23
+
24
+ initialize_with { attributes }
25
+ end
26
+
27
+ factory :messages, class: Hash do
28
+ apple_push({ alert: :hello })
29
+
30
+ initialize_with { attributes }
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.appboy.com/email/status
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"<APPBOY_GROUP_ID>","email":"john@example.com","subscription_state":"unsubscribed"}'
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
+ - Thu, 19 Feb 2015 20:42:25 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
+ - 664ec9e1c8bf8666cadff79ee1a56434
45
+ X-Runtime:
46
+ - '0.024496'
47
+ Vary:
48
+ - Accept-Encoding
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"message":"success"}'
52
+ http_version:
53
+ recorded_at: Thu, 19 Feb 2015 20:42:24 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/email/status
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"app_group_id":"<APPBOY_GROUP_ID>","email":"john@example.com","subscription_state":"unsubscribed"}'
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
+ - Thu, 19 Feb 2015 20:42:25 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
+ - 0854d9c1be11939007bace0da4e264ac
45
+ X-Runtime:
46
+ - '0.025690'
47
+ Vary:
48
+ - Accept-Encoding
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"message":"success"}'
52
+ http_version:
53
+ recorded_at: Thu, 19 Feb 2015 20:42:25 GMT
54
+ recorded_with: VCR 2.9.2