appboy 0.0.1 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/README.md +165 -21
- data/appboy.gemspec +18 -10
- data/lib/appboy.rb +5 -3
- data/lib/appboy/api.rb +27 -30
- data/lib/appboy/deprecated.rb +19 -0
- data/lib/appboy/endpoints/delete_users.rb +15 -0
- data/lib/appboy/endpoints/email_status.rb +13 -0
- data/lib/appboy/endpoints/list_canvas.rb +15 -0
- data/lib/appboy/endpoints/schedule_messages.rb +15 -0
- data/lib/appboy/endpoints/send_messages.rb +15 -0
- data/lib/appboy/endpoints/track_users.rb +29 -0
- data/lib/appboy/endpoints/trigger_campaign.rb +15 -0
- data/lib/appboy/endpoints/trigger_canvas.rb +15 -0
- data/lib/appboy/http.rb +32 -0
- data/lib/appboy/rest.rb +11 -0
- data/lib/appboy/rest/base.rb +15 -0
- data/lib/appboy/rest/delete_users.rb +21 -0
- data/lib/appboy/rest/email_status.rb +21 -0
- data/lib/appboy/rest/export_users.rb +27 -0
- data/lib/appboy/rest/list_canvas.rb +21 -0
- data/lib/appboy/rest/list_segments.rb +11 -0
- data/lib/appboy/rest/schedule_messages.rb +25 -0
- data/lib/appboy/rest/send_messages.rb +23 -0
- data/lib/appboy/rest/track_users.rb +14 -0
- data/lib/appboy/rest/trigger_campaign.rb +30 -0
- data/lib/appboy/rest/trigger_canvas.rb +28 -0
- data/lib/appboy/version.rb +1 -1
- data/spec/appboy/api_spec.rb +4 -0
- data/spec/appboy/endpoints/track_users_spec.rb +72 -0
- data/spec/appboy/endpoints/trigger_campaigns_spec.rb +47 -0
- data/spec/appboy/endpoints/trigger_canvas_spec.rb +47 -0
- data/spec/appboy/http_spec.rb +19 -0
- data/spec/appboy/rest/delete_users_spec.rb +23 -0
- data/spec/appboy/rest/email_status_spec.rb +19 -0
- data/spec/appboy/rest/export_users_spec.rb +20 -0
- data/spec/appboy/rest/list_canvas_spec.rb +23 -0
- data/spec/appboy/rest/schedule_messages_spec.rb +34 -0
- data/spec/appboy/rest/send_messages_spec.rb +36 -0
- data/spec/appboy/rest/track_users_spec.rb +24 -0
- data/spec/appboy/rest/trigger_campaign_spec.rb +50 -0
- data/spec/appboy/rest/trigger_canvas_spec.rb +47 -0
- data/spec/factories.rb +44 -0
- data/spec/fixtures/responses/delete_users/unauthorized/responds_with_unauthorized.yml +58 -0
- data/spec/fixtures/responses/delete_users/with_success/responds_with_created.yml +58 -0
- data/spec/fixtures/responses/delete_users/with_success/responds_with_success_message.yml +58 -0
- data/spec/fixtures/responses/email_status/existing_email/responds_with_created.yml +54 -0
- data/spec/fixtures/responses/email_status/existing_email/responds_with_success_message.yml +54 -0
- data/spec/fixtures/responses/email_status/unknown_email/responds_with_bad_request.yml +52 -0
- data/spec/fixtures/responses/email_status/unknown_email/responds_with_error_message.yml +52 -0
- data/spec/fixtures/responses/export_users/by_ids/with_success/responds_with_created.yml +56 -0
- data/spec/fixtures/responses/export_users/by_segment/with_success/responds_with_created.yml +54 -0
- data/spec/fixtures/responses/list_canvas/with_success/responds_with_a_list_of_segments.yml +67 -0
- data/spec/fixtures/responses/list_canvas/with_success/responds_with_success.yml +67 -0
- data/spec/fixtures/responses/list_segments/with_success/responds_with_a_list_of_segments.yml +58 -0
- data/spec/fixtures/responses/list_segments/with_success/responds_with_success.yml +58 -0
- data/spec/fixtures/responses/schedule_messages/unauthorized/responds_with_unauthorize.yml +53 -0
- data/spec/fixtures/responses/schedule_messages/with_success/responds_with_created.yml +55 -0
- data/spec/fixtures/responses/schedule_messages/with_success/responds_with_success_message.yml +55 -0
- data/spec/fixtures/responses/send_messages/unauthorized/responds_with_unauthorized.yml +52 -0
- data/spec/fixtures/responses/send_messages/with_success/responds_with_created.yml +54 -0
- data/spec/fixtures/responses/send_messages/with_success/responds_with_success_message.yml +54 -0
- data/spec/fixtures/responses/track_users/unauthorized/responds_with_unauthorized.yml +54 -0
- data/spec/fixtures/responses/track_users/with_success/responds_with_created.yml +56 -0
- data/spec/fixtures/responses/track_users/with_success/responds_with_success_message.yml +56 -0
- data/spec/integrations/delete_users_spec.rb +30 -0
- data/spec/integrations/email_status_spec.rb +36 -0
- data/spec/integrations/export_users_spec.rb +27 -0
- data/spec/integrations/list_canvas_spec.rb +21 -0
- data/spec/integrations/list_segments_spec.rb +21 -0
- data/spec/integrations/schedule_messages_spec.rb +31 -0
- data/spec/integrations/send_messages_spec.rb +30 -0
- data/spec/integrations/track_users_spec.rb +35 -0
- data/spec/spec_helper.rb +10 -1
- data/spec/support/factory_girl.rb +10 -0
- data/spec/support/integrations.rb +19 -0
- data/spec/support/vcr.rb +17 -0
- metadata +248 -19
- data/spec/api_spec.rb +0 -60
@@ -0,0 +1,15 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Endpoints
|
3
|
+
module SendMessages
|
4
|
+
def send_messages(**payload)
|
5
|
+
send_messages_service.new(app_group_id, payload).perform
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def send_messages_service
|
11
|
+
Appboy::REST::SendMessages
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Endpoints
|
3
|
+
module TrackUsers
|
4
|
+
attr_writer :track_users_service
|
5
|
+
|
6
|
+
def track_users(**payload)
|
7
|
+
track_users_service.perform(app_group_id, payload)
|
8
|
+
end
|
9
|
+
|
10
|
+
def track_purchase(payload)
|
11
|
+
track_users(purchases: [payload])
|
12
|
+
end
|
13
|
+
|
14
|
+
def track_event(payload)
|
15
|
+
track_users(events: [payload])
|
16
|
+
end
|
17
|
+
|
18
|
+
def track_attribute(payload)
|
19
|
+
track_users(attributes: [payload])
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def track_users_service
|
25
|
+
@track_users_service ||= Appboy::REST::TrackUsers.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Endpoints
|
3
|
+
module TriggerCampaign
|
4
|
+
def trigger_campaign(**payload)
|
5
|
+
trigger_campaign_service.new(app_group_id, payload).perform
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def trigger_campaign_service
|
11
|
+
Appboy::REST::TriggerCampaign
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Endpoints
|
3
|
+
module TriggerCanvas
|
4
|
+
def trigger_canvas(**payload)
|
5
|
+
trigger_canvas_service.new(app_group_id, payload).perform
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def trigger_canvas_service
|
11
|
+
Appboy::REST::TriggerCanvas
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/appboy/http.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Appboy
|
5
|
+
class HTTP
|
6
|
+
def post(path, payload)
|
7
|
+
connection.post path do |request|
|
8
|
+
request.body = payload
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(path, query)
|
13
|
+
connection.get path, query
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection
|
17
|
+
@connection ||= Faraday.new(url: api_host) do |connection|
|
18
|
+
connection.request :json
|
19
|
+
|
20
|
+
connection.response :logger if ENV['APPBOY_DEBUG']
|
21
|
+
|
22
|
+
connection.adapter Faraday.default_adapter
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def api_host
|
29
|
+
@api_host ||= ENV.fetch('APPBOY_REST_BASE_URL', 'https://api.appboy.com')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/appboy/rest.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'appboy/rest/base'
|
2
|
+
require 'appboy/rest/track_users'
|
3
|
+
require 'appboy/rest/delete_users'
|
4
|
+
require 'appboy/rest/send_messages'
|
5
|
+
require 'appboy/rest/schedule_messages'
|
6
|
+
require 'appboy/rest/email_status'
|
7
|
+
require 'appboy/rest/export_users'
|
8
|
+
require 'appboy/rest/list_segments'
|
9
|
+
require 'appboy/rest/trigger_campaign'
|
10
|
+
require 'appboy/rest/trigger_canvas'
|
11
|
+
require 'appboy/rest/list_canvas'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Appboy
|
2
|
+
module REST
|
3
|
+
class DeleteUsers < Base
|
4
|
+
attr_reader :app_group_id, :external_ids, :appboy_ids
|
5
|
+
|
6
|
+
def initialize(app_group_id, external_ids: [], appboy_ids: [])
|
7
|
+
@app_group_id = app_group_id
|
8
|
+
@external_ids = external_ids
|
9
|
+
@appboy_ids = appboy_ids
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform
|
13
|
+
http.post '/users/delete', {
|
14
|
+
app_group_id: app_group_id,
|
15
|
+
external_ids: external_ids,
|
16
|
+
appboy_ids: appboy_ids
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -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,21 @@
|
|
1
|
+
module Appboy
|
2
|
+
module REST
|
3
|
+
class ListCanvas < Base
|
4
|
+
attr_reader :app_group_id, :sort_direction, :include_archived
|
5
|
+
|
6
|
+
def initialize(app_group_id, options = {})
|
7
|
+
@app_group_id = app_group_id
|
8
|
+
@sort_direction = options[:sort_direction]
|
9
|
+
@include_archived = options[:include_archived]
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform
|
13
|
+
http.get '/canvas/list', {
|
14
|
+
app_group_id: app_group_id,
|
15
|
+
sort_direction: sort_direction,
|
16
|
+
include_archived: include_archived
|
17
|
+
}.compact
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
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
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Appboy
|
2
|
+
module REST
|
3
|
+
class TriggerCampaign < Base
|
4
|
+
attr_reader :api_key, :audience, :broadcast, :campaign_id,
|
5
|
+
:recipients, :send_id, :trigger_properties
|
6
|
+
|
7
|
+
def initialize(api_key, options = {})
|
8
|
+
@api_key = api_key
|
9
|
+
@audience = options[:audience]
|
10
|
+
@broadcast = options[:broadcast] || false
|
11
|
+
@campaign_id = options[:campaign_id]
|
12
|
+
@recipients = options[:recipients]
|
13
|
+
@send_id = options[:send_id]
|
14
|
+
@trigger_properties = options[:trigger_properties]
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform
|
18
|
+
http.post '/campaigns/trigger/send', {
|
19
|
+
api_key: api_key,
|
20
|
+
audience: audience,
|
21
|
+
broadcast: broadcast,
|
22
|
+
campaign_id: campaign_id,
|
23
|
+
recipients: recipients,
|
24
|
+
send_id: send_id,
|
25
|
+
trigger_properties: trigger_properties
|
26
|
+
}.compact
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Appboy
|
2
|
+
module REST
|
3
|
+
class TriggerCanvas < Base
|
4
|
+
attr_reader :api_key, :audience, :broadcast, :canvas_id,
|
5
|
+
:canvas_entry_properties, :recipients
|
6
|
+
|
7
|
+
def initialize(app_group_id, options = {})
|
8
|
+
@api_key = app_group_id
|
9
|
+
@audience = options[:audience]
|
10
|
+
@broadcast = options[:broadcast] || false
|
11
|
+
@canvas_entry_properties = options[:canvas_entry_properties]
|
12
|
+
@canvas_id = options[:canvas_id]
|
13
|
+
@recipients = options[:recipients]
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform
|
17
|
+
http.post '/canvas/trigger/send', {
|
18
|
+
api_key: api_key,
|
19
|
+
audience: audience,
|
20
|
+
broadcast: broadcast,
|
21
|
+
canvas_entry_properties: canvas_entry_properties,
|
22
|
+
canvas_id: canvas_id,
|
23
|
+
recipients: recipients
|
24
|
+
}.compact
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/appboy/version.rb
CHANGED
@@ -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
|