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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 96b1b915bc01148105219d0aa25762991883ac33ecdfbc42afc2d05703bd4084
|
4
|
+
data.tar.gz: 23b7079dbcf8fa2dc7c095bcce30766dd542b9580d21b8eba3044275e313ba74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5636f61473d6f7c854e8086a695af8364429387b1fc710542805fe250fef63ff709265620dcc23c4eefb8cc8da394d4d5a87bbeec2830622f4c09503b1ca1781
|
7
|
+
data.tar.gz: e61ef8f59d13886bcc8dd62e854fa7137bde95b786599a9a7bf5f57e74d9d8a5ee9e40a443e31a31938a8b7ebd8134e6e9b981d902195f7c4ea6ea5f999c4ddd
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Appboy
|
2
2
|
|
3
|
-
A wrapper for the Appboy REST API
|
3
|
+
A wrapper for the Appboy REST API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -21,49 +21,193 @@ Or install it yourself as:
|
|
21
21
|
### Initializing API
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
api = Appboy::API.new('<
|
24
|
+
api = Appboy::API.new('<app-group-id>')
|
25
25
|
```
|
26
26
|
|
27
|
-
|
27
|
+
By default Appboy will be using 'https://api.appboy.com' as the default REST API base url, but you can override this base url by setting the env variable `APPBOY_REST_BASE_URL`. E.G.
|
28
|
+
|
29
|
+
```
|
30
|
+
APPBOY_REST_BASE_URL="https://rest.iad-01.braze.com"
|
31
|
+
```
|
32
|
+
|
33
|
+
### Track User Attributes
|
34
|
+
|
35
|
+
See: [User Attributes Object Specification](https://www.braze.com/documentation/REST_API/#user-attributes-object-specification)
|
28
36
|
|
29
37
|
```ruby
|
30
|
-
api.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
api.track_users(attributes: [{
|
39
|
+
external_id: 123,
|
40
|
+
first_name: 'John',
|
41
|
+
last_name: 'Smith',
|
42
|
+
gender: 'male',
|
43
|
+
email: 'jsmith@example.com'
|
44
|
+
}])
|
45
|
+
```
|
46
|
+
|
47
|
+
##### Track Attributes for Single User
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
api.track_attribute(external_id: 123, first_name: 'John', ...)
|
35
51
|
```
|
36
52
|
|
37
53
|
### Track Event
|
38
54
|
|
55
|
+
See: [Event Object Specification](https://www.braze.com/documentation/REST_API/#event-object-specification)
|
56
|
+
|
39
57
|
```ruby
|
40
|
-
events
|
41
|
-
|
42
|
-
|
43
|
-
|
58
|
+
api.track_users(events: [{
|
59
|
+
external_id: 123,
|
60
|
+
name: 'add-to-cart',
|
61
|
+
time: Time.now
|
62
|
+
}])
|
63
|
+
```
|
64
|
+
|
65
|
+
##### Track Events for Single User
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
api.track_event(external_id: 123, name: 'Event', ...)
|
44
69
|
```
|
45
70
|
|
46
71
|
### Track Purchase
|
72
|
+
|
73
|
+
See: [Purchase Object Specfication](https://www.braze.com/documentation/REST_API/#purchase-object-specification)
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
api.track_users(purchases: [{
|
77
|
+
external_id: 123,
|
78
|
+
product_id: 456,
|
79
|
+
currency: 'CAD',
|
80
|
+
price: 1.99,
|
81
|
+
time: Time.now
|
82
|
+
}])
|
83
|
+
```
|
84
|
+
|
85
|
+
##### Track Purchases for Single User
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
api.track_purchase(external_id: 123, product_id: 456, ...)
|
89
|
+
```
|
90
|
+
|
91
|
+
### Track Everything for Everyone All at Once
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
api.track_users(purchases: purchases, events: events, attributes: attributes)
|
95
|
+
```
|
96
|
+
|
47
97
|
### Send Message
|
48
98
|
|
99
|
+
See: [Platform Push Object Specifications](https://www.braze.com/documentation/REST_API/#messaging)
|
100
|
+
|
101
|
+
##### Messages Payload
|
102
|
+
|
49
103
|
```ruby
|
50
|
-
|
51
|
-
|
104
|
+
messages = {
|
105
|
+
android_push: { alert: 'Hello Android' },
|
106
|
+
apple_push: { alert: "Hello iOS" }
|
107
|
+
}
|
108
|
+
```
|
52
109
|
|
53
|
-
|
110
|
+
##### Option A, Using External User IDs
|
54
111
|
|
55
|
-
|
112
|
+
```ruby
|
113
|
+
api.send_messages(messages: messages, external_user_ids: [123, 456])
|
114
|
+
```
|
115
|
+
|
116
|
+
##### Option B, Using Segment ID
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
api.send_messages(messages: messages, segment_id: '<segment-id>')
|
120
|
+
```
|
121
|
+
|
122
|
+
### Triggered Delivery Messages
|
123
|
+
|
124
|
+
See: [Sending Messages via API Triggered Delivery](https://www.braze.com/documentation/REST_API/#sending-messages-via-api-triggered-delivery)
|
125
|
+
|
126
|
+
##### Option A, Using Campaign ID
|
127
|
+
```ruby
|
128
|
+
api.trigger_campaign(
|
129
|
+
api_key: (required, string),
|
130
|
+
campaign_id: (required, string),
|
131
|
+
send_id: (optional, string),
|
132
|
+
audience: (optional, string),
|
133
|
+
trigger_properties: (optional, object),
|
134
|
+
broadcast: (optional, boolean, default, false),
|
135
|
+
recipients: (optional, array of recipient objects)
|
136
|
+
)
|
137
|
+
```
|
138
|
+
|
139
|
+
##### Option B, Using Canvas ID
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
api.trigger_canvas(
|
143
|
+
api_key: (required, string),
|
144
|
+
campaign_id: (required, string),
|
145
|
+
audience: (optional, string),
|
146
|
+
canvas_entry_properties: (optional, object),
|
147
|
+
broadcast: (optional, boolean, default, false),
|
148
|
+
recipients: (optional, array of recipient objects)
|
149
|
+
)
|
56
150
|
```
|
57
151
|
|
58
152
|
### Schedule Message
|
59
153
|
|
154
|
+
See: [Platform Push Object Specifications](https://www.braze.com/documentation/REST_API/#schedule-api-triggered-campaigns-and-canvases)
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
api.schedule_messages(send_at: 1.hour.since, messages: messages, segment_id: '<segment-id>')
|
158
|
+
```
|
159
|
+
|
160
|
+
### Changing Email Subscription
|
161
|
+
|
162
|
+
See: [Changing Email Subscription Status](https://www.braze.com/documentation/REST_API/#email-sync)
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
api.email_status(email: 'john@example.com', status: :opted_in)
|
166
|
+
```
|
167
|
+
|
168
|
+
### List Segments
|
169
|
+
|
170
|
+
See: [Segment Export](https://www.braze.com/documentation/REST_API/#segment-export)
|
171
|
+
|
60
172
|
```ruby
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
173
|
+
api.list_segments
|
174
|
+
```
|
175
|
+
|
176
|
+
### List Canvas
|
177
|
+
|
178
|
+
See: [Segment Export](https://www.braze.com/docs/api/endpoints/export/canvas/get_canvases)
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
api.list_canvas(
|
182
|
+
sort_direction: (optional, string, default: 'desc',
|
183
|
+
include_archived: (optional, boolean, default: false)
|
184
|
+
)
|
185
|
+
```
|
186
|
+
|
187
|
+
### Export Users
|
188
|
+
|
189
|
+
See: [User Export](https://www.braze.com/documentation/REST_API/#user-export)
|
190
|
+
|
191
|
+
#### By IDs
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
api.export_users(external_ids: [1])
|
195
|
+
```
|
196
|
+
|
197
|
+
#### By Segment
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
api.export_users(segment_id: segment_id, callback_endpoint: 'https://example.com')
|
201
|
+
```
|
202
|
+
|
203
|
+
## Debugging
|
204
|
+
|
205
|
+
The APPBOY_DEBUG environment variable will trigger full printouts of the Faraday gem's HTTP requests and responses.
|
65
206
|
|
66
|
-
|
207
|
+
```bash
|
208
|
+
cd /my/app
|
209
|
+
export APPBOY_DEBUG=true
|
210
|
+
bundle exec rails whatever
|
67
211
|
```
|
68
212
|
|
69
213
|
## Contributing
|
data/appboy.gemspec
CHANGED
@@ -4,22 +4,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'appboy/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'appboy'
|
8
8
|
spec.version = Appboy::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email =
|
9
|
+
spec.authors = ['Josh Nussbaum', 'Hugo Bastien']
|
10
|
+
spec.email = %w(josh@godynamo.com hugo@godynamo.com)
|
11
11
|
spec.description = %q{Appboy wrapper}
|
12
12
|
spec.summary = %q{A wrapper for the Appboy REST API, track users/events/purchases, send & schedule messages}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'http://appboy.com'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency '
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency
|
21
|
+
spec.add_dependency 'virtus'
|
22
|
+
spec.add_dependency 'faraday'
|
23
|
+
spec.add_dependency 'faraday_middleware'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'dotenv'
|
28
|
+
spec.add_development_dependency 'vcr'
|
29
|
+
spec.add_development_dependency 'webmock'
|
30
|
+
spec.add_development_dependency 'pry', '~> 0.9.12'
|
31
|
+
spec.add_development_dependency 'activesupport'
|
32
|
+
spec.add_development_dependency 'factory_girl', '~> 4.4.0'
|
25
33
|
end
|
data/lib/appboy.rb
CHANGED
data/lib/appboy/api.rb
CHANGED
@@ -1,42 +1,39 @@
|
|
1
|
+
require 'appboy/deprecated'
|
2
|
+
require 'appboy/endpoints/track_users'
|
3
|
+
require 'appboy/endpoints/delete_users'
|
4
|
+
require 'appboy/endpoints/send_messages'
|
5
|
+
require 'appboy/endpoints/schedule_messages'
|
6
|
+
require 'appboy/endpoints/email_status'
|
7
|
+
require 'appboy/endpoints/trigger_campaign'
|
8
|
+
require 'appboy/endpoints/trigger_canvas'
|
9
|
+
require 'appboy/endpoints/list_canvas'
|
10
|
+
|
1
11
|
module Appboy
|
2
12
|
class API
|
3
|
-
include
|
13
|
+
include Appboy::Deprecated
|
4
14
|
|
5
|
-
|
15
|
+
include Appboy::Endpoints::TrackUsers
|
16
|
+
include Appboy::Endpoints::DeleteUsers
|
17
|
+
include Appboy::Endpoints::SendMessages
|
18
|
+
include Appboy::Endpoints::ScheduleMessages
|
19
|
+
include Appboy::Endpoints::EmailStatus
|
20
|
+
include Appboy::Endpoints::TriggerCampaign
|
21
|
+
include Appboy::Endpoints::TriggerCanvas
|
22
|
+
include Appboy::Endpoints::ListCanvas
|
6
23
|
|
7
|
-
def
|
8
|
-
|
24
|
+
def export_users(**payload)
|
25
|
+
Appboy::REST::ExportUsers.new.perform(app_group_id, payload)
|
9
26
|
end
|
10
27
|
|
11
|
-
def
|
12
|
-
|
13
|
-
app_group_id: @app_group_id,
|
14
|
-
attributes: attributes,
|
15
|
-
events: events,
|
16
|
-
purchases: purchases
|
28
|
+
def list_segments
|
29
|
+
Appboy::REST::ListSegments.new.perform(app_group_id)
|
17
30
|
end
|
18
31
|
|
19
|
-
|
20
|
-
post '/messages/send', company_secret: @secret,
|
21
|
-
app_group_id: @app_group_id,
|
22
|
-
messages: message,
|
23
|
-
external_user_ids: user_ids,
|
24
|
-
segment_ids: [segment_id].compact
|
25
|
-
end
|
32
|
+
attr_reader :app_group_id
|
26
33
|
|
27
|
-
def
|
28
|
-
|
29
|
-
segment_ids: [segment_id],
|
30
|
-
send_at: date,
|
31
|
-
deliver_in_local_timezone: local_timezone,
|
32
|
-
messages: message
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
def post(url, payload)
|
37
|
-
response = self.class.post(url, query: payload)
|
38
|
-
puts response.inspect
|
39
|
-
response['message'] == 'success'
|
34
|
+
def initialize(app_group_id)
|
35
|
+
@app_group_id = app_group_id
|
40
36
|
end
|
41
37
|
end
|
42
38
|
end
|
39
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Deprecated
|
3
|
+
def track(attribute, events = [], purchases = [])
|
4
|
+
warn('[Appboy] `track` is deprecated. Please use `track_users` instead.')
|
5
|
+
track_users(attribute: attribute, events: events, purchases: purchases)
|
6
|
+
end
|
7
|
+
|
8
|
+
def send_message(message, user_ids, segment_ids = nil)
|
9
|
+
warn('[Appboy] `send_message` is deprecated. Please use `send_messages` instead.')
|
10
|
+
send_messages(messages: message, user_ids: user_ids, segment_ids: segment_ids)
|
11
|
+
end
|
12
|
+
|
13
|
+
def schedule_message(date, message, segment_id, local_timezone = false)
|
14
|
+
warn('[Appboy] `schedule_message` is deprecated. Please use `schedule_messages` instead.')
|
15
|
+
schedule_messages(send_at: date, messages: message,
|
16
|
+
segment_id: segment_id, local_timezone: local_timezone)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Appboy
|
2
|
+
module Endpoints
|
3
|
+
module ScheduleMessages
|
4
|
+
def schedule_messages(**payload)
|
5
|
+
schedule_messages_service.new(app_group_id, payload).perform
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def schedule_messages_service
|
11
|
+
Appboy::REST::ScheduleMessages
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|