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,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'appboy/endpoints/trigger_campaign'
|
3
|
+
|
4
|
+
class API
|
5
|
+
include Appboy::Endpoints::TriggerCampaign
|
6
|
+
|
7
|
+
def app_group_id
|
8
|
+
:api_key
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'Appboy::Endpoints::TriggerCampaign' do
|
13
|
+
let(:api) { API.new }
|
14
|
+
let(:performer) do
|
15
|
+
instance_double 'Appboy::REST::TriggerCampaign'
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
allow(api.send(:trigger_campaign_service))
|
20
|
+
.to receive(:new).and_return(performer)
|
21
|
+
allow(performer).to receive(:perform).and_return true
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#trigger_campaign_service', vcr: true do
|
25
|
+
let(:payload) do
|
26
|
+
{
|
27
|
+
audience: :audience,
|
28
|
+
broadcast: :broadcast,
|
29
|
+
campaign_id: :campaign_id,
|
30
|
+
recipients: :recipients,
|
31
|
+
send_id: :send_id,
|
32
|
+
trigger_properties: :trigger_properties
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
subject(:trigger_campaign!) do
|
37
|
+
api.trigger_campaign(payload)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sends a campaign message with recipients' do
|
41
|
+
expect(api.send(:trigger_campaign_service))
|
42
|
+
.to receive(:new).with(:api_key, payload)
|
43
|
+
|
44
|
+
trigger_campaign!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'appboy/endpoints/trigger_canvas'
|
3
|
+
|
4
|
+
class API
|
5
|
+
include Appboy::Endpoints::TriggerCanvas
|
6
|
+
|
7
|
+
def app_group_id
|
8
|
+
:api_key
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Appboy::Endpoints::TriggerCanvas do
|
13
|
+
let(:api) { API.new }
|
14
|
+
let(:performer) do
|
15
|
+
instance_double "Appboy::REST::TriggerCanvas"
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
allow(api.send(:trigger_canvas_service))
|
20
|
+
.to receive(:new).and_return(performer)
|
21
|
+
allow(performer).to receive(:perform).and_return true
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#trigger_canvas_service', vcr: true do
|
25
|
+
let(:payload) do
|
26
|
+
{
|
27
|
+
audience: :audience,
|
28
|
+
broadcast: :broadcast,
|
29
|
+
canvas_entry_properties: :canvas_entry_properties,
|
30
|
+
canvas_id: :canvas_id,
|
31
|
+
recipients: :recipients,
|
32
|
+
send_id: :send_id
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
subject(:trigger_canvas!) do
|
37
|
+
api.trigger_canvas(payload)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sends a canvas message with recipients' do
|
41
|
+
expect(api.send(:trigger_canvas_service))
|
42
|
+
.to receive(:new).with(:api_key, payload)
|
43
|
+
|
44
|
+
trigger_canvas!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'appboy/http'
|
3
|
+
|
4
|
+
describe Appboy::HTTP do
|
5
|
+
describe '#connection' do
|
6
|
+
it 'sets the default url prefix' do
|
7
|
+
expect(subject.connection.url_prefix.to_s).to eql "https://api.appboy.com/"
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when the env contains `APPBOY_REST_BASE_URL` env variable' do
|
11
|
+
before { ENV['APPBOY_REST_BASE_URL'] = "https://new.braze.com" }
|
12
|
+
after { ENV.delete('APPBOY_REST_BASE_URL') }
|
13
|
+
|
14
|
+
it 'initializes the connection with it' do
|
15
|
+
expect(subject.connection.url_prefix.to_s).to eql "https://new.braze.com/"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Appboy::REST::DeleteUsers do
|
4
|
+
let(:http) { double(:http) }
|
5
|
+
|
6
|
+
let(:payload) {{
|
7
|
+
external_ids: :external_ids,
|
8
|
+
appboy_ids: :appboy_ids
|
9
|
+
}}
|
10
|
+
|
11
|
+
let(:app_group_id) { :app_group_id }
|
12
|
+
|
13
|
+
subject { described_class.new(:app_group_id, external_ids: :external_ids, appboy_ids: :appboy_ids) }
|
14
|
+
|
15
|
+
before { subject.http = http }
|
16
|
+
|
17
|
+
it 'makes an http call to the track user endpoint' do
|
18
|
+
expect(http).to receive(:post).with '/users/delete',
|
19
|
+
payload.merge({ app_group_id: :app_group_id })
|
20
|
+
|
21
|
+
subject.perform
|
22
|
+
end
|
23
|
+
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,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Appboy::REST::ListCanvas do
|
4
|
+
let(:http) { double(:http) }
|
5
|
+
|
6
|
+
let(:payload) {{
|
7
|
+
sort_direction: "desc",
|
8
|
+
include_archived: false
|
9
|
+
}}
|
10
|
+
|
11
|
+
let(:app_group_id) { :app_group_id }
|
12
|
+
|
13
|
+
subject { described_class.new(:app_group_id, sort_direction: "desc", include_archived: false) }
|
14
|
+
|
15
|
+
before { subject.http = http }
|
16
|
+
|
17
|
+
it 'makes an http call to the list canvas endpoint' do
|
18
|
+
expect(http).to receive(:get).with '/canvas/list',
|
19
|
+
payload.merge({ app_group_id: :app_group_id })
|
20
|
+
|
21
|
+
subject.perform
|
22
|
+
end
|
23
|
+
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,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Appboy::REST::TriggerCampaign do
|
4
|
+
let(:http) { double(:http) }
|
5
|
+
|
6
|
+
let(:payload) do
|
7
|
+
{
|
8
|
+
audience: :audience,
|
9
|
+
broadcast: :broadcast,
|
10
|
+
campaign_id: :campaign_id,
|
11
|
+
recipients: :recipients,
|
12
|
+
send_id: :send_id,
|
13
|
+
trigger_properties: :trigger_properties
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:api_key) { :api_key }
|
18
|
+
|
19
|
+
subject do
|
20
|
+
described_class.new(
|
21
|
+
api_key,
|
22
|
+
audience: :audience,
|
23
|
+
broadcast: :broadcast,
|
24
|
+
campaign_id: :campaign_id,
|
25
|
+
recipients: :recipients,
|
26
|
+
send_id: :send_id,
|
27
|
+
trigger_properties: :trigger_properties
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
before { subject.http = http }
|
32
|
+
|
33
|
+
it 'makes an http call to the send messages endpoint' do
|
34
|
+
expect_send_messages_http_call
|
35
|
+
|
36
|
+
subject.perform
|
37
|
+
end
|
38
|
+
|
39
|
+
def expect_send_messages_http_call
|
40
|
+
expect(http).to receive(:post).with '/campaigns/trigger/send', {
|
41
|
+
api_key: :api_key,
|
42
|
+
audience: :audience,
|
43
|
+
broadcast: :broadcast,
|
44
|
+
campaign_id: :campaign_id,
|
45
|
+
recipients: :recipients,
|
46
|
+
send_id: :send_id,
|
47
|
+
trigger_properties: :trigger_properties
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Appboy::REST::TriggerCanvas do
|
4
|
+
let(:http) { double(:http) }
|
5
|
+
|
6
|
+
let(:payload) do
|
7
|
+
{
|
8
|
+
audience: :audience,
|
9
|
+
broadcast: :broadcast,
|
10
|
+
canvas_id: :canvas_id,
|
11
|
+
canvas_entry_properties: :canvas_entry_properties,
|
12
|
+
recipients: :recipients
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:api_key) { :api_key }
|
17
|
+
|
18
|
+
subject do
|
19
|
+
described_class.new(
|
20
|
+
api_key,
|
21
|
+
audience: :audience,
|
22
|
+
broadcast: :broadcast,
|
23
|
+
canvas_id: :canvas_id,
|
24
|
+
canvas_entry_properties: :canvas_entry_properties,
|
25
|
+
recipients: :recipients
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
before { subject.http = http }
|
30
|
+
|
31
|
+
it 'makes an http call to the send messages endpoint' do
|
32
|
+
expect_send_messages_http_call
|
33
|
+
|
34
|
+
subject.perform
|
35
|
+
end
|
36
|
+
|
37
|
+
def expect_send_messages_http_call
|
38
|
+
expect(http).to receive(:post).with '/canvas/trigger/send', {
|
39
|
+
api_key: :api_key,
|
40
|
+
audience: :audience,
|
41
|
+
broadcast: :broadcast,
|
42
|
+
canvas_id: :canvas_id,
|
43
|
+
canvas_entry_properties: :canvas_entry_properties,
|
44
|
+
recipients: :recipients
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
data/spec/factories.rb
ADDED
@@ -0,0 +1,44 @@
|
|
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
|
+
|
33
|
+
factory :recipients, class: Array do
|
34
|
+
sequence(:external_user_id)
|
35
|
+
|
36
|
+
initialize_with { attributes }
|
37
|
+
end
|
38
|
+
|
39
|
+
factory :external_ids, class: Hash do
|
40
|
+
external_ids { [1,2] }
|
41
|
+
|
42
|
+
initialize_with { attributes }
|
43
|
+
end
|
44
|
+
end
|