appboy 0.0.1 → 0.1.7

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 (81) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -0
  4. data/README.md +165 -21
  5. data/appboy.gemspec +18 -10
  6. data/lib/appboy.rb +5 -3
  7. data/lib/appboy/api.rb +27 -30
  8. data/lib/appboy/deprecated.rb +19 -0
  9. data/lib/appboy/endpoints/delete_users.rb +15 -0
  10. data/lib/appboy/endpoints/email_status.rb +13 -0
  11. data/lib/appboy/endpoints/list_canvas.rb +15 -0
  12. data/lib/appboy/endpoints/schedule_messages.rb +15 -0
  13. data/lib/appboy/endpoints/send_messages.rb +15 -0
  14. data/lib/appboy/endpoints/track_users.rb +29 -0
  15. data/lib/appboy/endpoints/trigger_campaign.rb +15 -0
  16. data/lib/appboy/endpoints/trigger_canvas.rb +15 -0
  17. data/lib/appboy/http.rb +32 -0
  18. data/lib/appboy/rest.rb +11 -0
  19. data/lib/appboy/rest/base.rb +15 -0
  20. data/lib/appboy/rest/delete_users.rb +21 -0
  21. data/lib/appboy/rest/email_status.rb +21 -0
  22. data/lib/appboy/rest/export_users.rb +27 -0
  23. data/lib/appboy/rest/list_canvas.rb +21 -0
  24. data/lib/appboy/rest/list_segments.rb +11 -0
  25. data/lib/appboy/rest/schedule_messages.rb +25 -0
  26. data/lib/appboy/rest/send_messages.rb +23 -0
  27. data/lib/appboy/rest/track_users.rb +14 -0
  28. data/lib/appboy/rest/trigger_campaign.rb +30 -0
  29. data/lib/appboy/rest/trigger_canvas.rb +28 -0
  30. data/lib/appboy/version.rb +1 -1
  31. data/spec/appboy/api_spec.rb +4 -0
  32. data/spec/appboy/endpoints/track_users_spec.rb +72 -0
  33. data/spec/appboy/endpoints/trigger_campaigns_spec.rb +47 -0
  34. data/spec/appboy/endpoints/trigger_canvas_spec.rb +47 -0
  35. data/spec/appboy/http_spec.rb +19 -0
  36. data/spec/appboy/rest/delete_users_spec.rb +23 -0
  37. data/spec/appboy/rest/email_status_spec.rb +19 -0
  38. data/spec/appboy/rest/export_users_spec.rb +20 -0
  39. data/spec/appboy/rest/list_canvas_spec.rb +23 -0
  40. data/spec/appboy/rest/schedule_messages_spec.rb +34 -0
  41. data/spec/appboy/rest/send_messages_spec.rb +36 -0
  42. data/spec/appboy/rest/track_users_spec.rb +24 -0
  43. data/spec/appboy/rest/trigger_campaign_spec.rb +50 -0
  44. data/spec/appboy/rest/trigger_canvas_spec.rb +47 -0
  45. data/spec/factories.rb +44 -0
  46. data/spec/fixtures/responses/delete_users/unauthorized/responds_with_unauthorized.yml +58 -0
  47. data/spec/fixtures/responses/delete_users/with_success/responds_with_created.yml +58 -0
  48. data/spec/fixtures/responses/delete_users/with_success/responds_with_success_message.yml +58 -0
  49. data/spec/fixtures/responses/email_status/existing_email/responds_with_created.yml +54 -0
  50. data/spec/fixtures/responses/email_status/existing_email/responds_with_success_message.yml +54 -0
  51. data/spec/fixtures/responses/email_status/unknown_email/responds_with_bad_request.yml +52 -0
  52. data/spec/fixtures/responses/email_status/unknown_email/responds_with_error_message.yml +52 -0
  53. data/spec/fixtures/responses/export_users/by_ids/with_success/responds_with_created.yml +56 -0
  54. data/spec/fixtures/responses/export_users/by_segment/with_success/responds_with_created.yml +54 -0
  55. data/spec/fixtures/responses/list_canvas/with_success/responds_with_a_list_of_segments.yml +67 -0
  56. data/spec/fixtures/responses/list_canvas/with_success/responds_with_success.yml +67 -0
  57. data/spec/fixtures/responses/list_segments/with_success/responds_with_a_list_of_segments.yml +58 -0
  58. data/spec/fixtures/responses/list_segments/with_success/responds_with_success.yml +58 -0
  59. data/spec/fixtures/responses/schedule_messages/unauthorized/responds_with_unauthorize.yml +53 -0
  60. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_created.yml +55 -0
  61. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_success_message.yml +55 -0
  62. data/spec/fixtures/responses/send_messages/unauthorized/responds_with_unauthorized.yml +52 -0
  63. data/spec/fixtures/responses/send_messages/with_success/responds_with_created.yml +54 -0
  64. data/spec/fixtures/responses/send_messages/with_success/responds_with_success_message.yml +54 -0
  65. data/spec/fixtures/responses/track_users/unauthorized/responds_with_unauthorized.yml +54 -0
  66. data/spec/fixtures/responses/track_users/with_success/responds_with_created.yml +56 -0
  67. data/spec/fixtures/responses/track_users/with_success/responds_with_success_message.yml +56 -0
  68. data/spec/integrations/delete_users_spec.rb +30 -0
  69. data/spec/integrations/email_status_spec.rb +36 -0
  70. data/spec/integrations/export_users_spec.rb +27 -0
  71. data/spec/integrations/list_canvas_spec.rb +21 -0
  72. data/spec/integrations/list_segments_spec.rb +21 -0
  73. data/spec/integrations/schedule_messages_spec.rb +31 -0
  74. data/spec/integrations/send_messages_spec.rb +30 -0
  75. data/spec/integrations/track_users_spec.rb +35 -0
  76. data/spec/spec_helper.rb +10 -1
  77. data/spec/support/factory_girl.rb +10 -0
  78. data/spec/support/integrations.rb +19 -0
  79. data/spec/support/vcr.rb +17 -0
  80. metadata +248 -19
  81. data/spec/api_spec.rb +0 -60
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b9b08323e1d2602a33183a99f18a06a7bb59ad1e
4
- data.tar.gz: 984094644be733e86940bb0e4b6d2c0dcf397d36
2
+ SHA256:
3
+ metadata.gz: 96b1b915bc01148105219d0aa25762991883ac33ecdfbc42afc2d05703bd4084
4
+ data.tar.gz: 23b7079dbcf8fa2dc7c095bcce30766dd542b9580d21b8eba3044275e313ba74
5
5
  SHA512:
6
- metadata.gz: 4f39f353d4618c26b0b340ea7580d535042f40baf1b03e74c578d80066db094b70e65f283e1a408a54b6946087a436417788da032265e2e4168131fcce10fc8c
7
- data.tar.gz: ec645bebf908780c2d633bdb18b7e211b72d304024ccf5afcb02e519921db65b49373bd3626489e4dd8573779a6ae2fcc2427fa29502800d901535907c1cbc8b
6
+ metadata.gz: 5636f61473d6f7c854e8086a695af8364429387b1fc710542805fe250fef63ff709265620dcc23c4eefb8cc8da394d4d5a87bbeec2830622f4c09503b1ca1781
7
+ data.tar.gz: e61ef8f59d13886bcc8dd62e854fa7137bde95b786599a9a7bf5f57e74d9d8a5ee9e40a443e31a31938a8b7ebd8134e6e9b981d902195f7c4ea6ea5f999c4ddd
data/.gitignore CHANGED
@@ -3,6 +3,8 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .ruby-version
7
+ .env
6
8
  Gemfile.lock
7
9
  InstalledFiles
8
10
  _yardoc
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 using HTTParty
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('<secret>', '<app-group-id>')
24
+ api = Appboy::API.new('<app-group-id>')
25
25
  ```
26
26
 
27
- ### Track User
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.track [{external_id: 123,
31
- first_name: 'John',
32
- last_name: 'Smith',
33
- gender: 'male',
34
- email: 'jsmith@example.com'}]
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
- {external_id: 123, name: 'add-to-cart', time: Time.now}
42
- ]
43
- api.track [], events
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
- message = {android_push: {alert: 'Hello Android'},
51
- apple_push: {alert: "Hello iOS"}}
104
+ messages = {
105
+ android_push: { alert: 'Hello Android' },
106
+ apple_push: { alert: "Hello iOS" }
107
+ }
108
+ ```
52
109
 
53
- user_ids = [123, 456]
110
+ ##### Option A, Using External User IDs
54
111
 
55
- api.send_message(message, user_ids)
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
- message = {android_push: {alert: 'Hello Android'},
62
- apple_push: {alert: "Hello iOS"}}
63
- segment_id = '<segment id>'
64
- send_at = Time.new(2014, 3, 12)
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
- api.schedule_message(send_at, message, segment_id)
207
+ ```bash
208
+ cd /my/app
209
+ export APPBOY_DEBUG=true
210
+ bundle exec rails whatever
67
211
  ```
68
212
 
69
213
  ## Contributing
@@ -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 = "appboy"
7
+ spec.name = 'appboy'
8
8
  spec.version = Appboy::VERSION
9
- spec.authors = ["Josh Nussbaum"]
10
- spec.email = ["josh@godynamo.com"]
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 = "http://appboy.com"
14
- spec.license = "MIT"
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 = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'httparty'
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec"
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
@@ -1,6 +1,8 @@
1
- require "appboy/version"
2
- require 'httparty'
1
+ require 'json'
2
+ require 'virtus'
3
+ require 'appboy/version'
3
4
 
4
5
  module Appboy
5
- autoload :API, "appboy/api"
6
+ autoload :API, 'appboy/api'
7
+ autoload :REST, 'appboy/rest'
6
8
  end
@@ -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 HTTParty
13
+ include Appboy::Deprecated
4
14
 
5
- base_uri 'https://api.appboy.com'
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 initialize(secret, app_group_id)
8
- @secret, @app_group_id = secret, app_group_id
24
+ def export_users(**payload)
25
+ Appboy::REST::ExportUsers.new.perform(app_group_id, payload)
9
26
  end
10
27
 
11
- def track(attributes, events=[], purchases=[])
12
- post '/users/track', company_secret: @secret,
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
- def send_message(message, user_ids, segment_id = nil)
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 schedule_message(date, message, segment_id, local_timezone=false)
28
- post '/messages/schedule', company_secret: @secret,
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 DeleteUsers
4
+ def delete_users(**payload)
5
+ delete_users_service.new(app_group_id, payload).perform
6
+ end
7
+
8
+ private
9
+
10
+ def delete_users_service
11
+ Appboy::REST::DeleteUsers
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Appboy
2
+ module Endpoints
3
+ module EmailStatus
4
+ def email_status(**payload)
5
+ email_status_service.new(app_group_id, payload).perform
6
+ end
7
+
8
+ def email_status_service
9
+ Appboy::REST::EmailStatus
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Appboy
2
+ module Endpoints
3
+ module ListCanvas
4
+ def list_canvas(**payload)
5
+ list_canvas_service.new(app_group_id, payload).perform
6
+ end
7
+
8
+ private
9
+
10
+ def list_canvas_service
11
+ Appboy::REST::ListCanvas
12
+ end
13
+ end
14
+ end
15
+ 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