braze_ruby 0.4.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +26 -0
  3. data/.github/workflows/gem_credentials +2 -0
  4. data/.github/workflows/release.yml +20 -0
  5. data/.gitignore +12 -19
  6. data/.standard.yml +1 -0
  7. data/Gemfile +1 -2
  8. data/LICENSE.txt +17 -18
  9. data/README.md +63 -6
  10. data/Rakefile +2 -1
  11. data/bin/release +16 -0
  12. data/braze_ruby.gemspec +28 -31
  13. data/lib/braze_ruby/api.rb +17 -15
  14. data/lib/braze_ruby/configuration.rb +13 -0
  15. data/lib/braze_ruby/deprecated.rb +4 -5
  16. data/lib/braze_ruby/endpoints/campaigns.rb +8 -0
  17. data/lib/braze_ruby/endpoints/remove_email_addresses_from_spam.rb +19 -0
  18. data/lib/braze_ruby/endpoints/remove_external_ids.rb +2 -2
  19. data/lib/braze_ruby/endpoints/rename_external_ids.rb +2 -2
  20. data/lib/braze_ruby/endpoints/schedule_messages.rb +3 -5
  21. data/lib/braze_ruby/endpoints/subscription.rb +0 -1
  22. data/lib/braze_ruby/endpoints.rb +11 -10
  23. data/lib/braze_ruby/http.rb +12 -9
  24. data/lib/braze_ruby/rest/base.rb +3 -3
  25. data/lib/braze_ruby/rest/canvas_details.rb +1 -1
  26. data/lib/braze_ruby/rest/create_user_aliases.rb +2 -2
  27. data/lib/braze_ruby/rest/delete_trigger_campaign_schedule.rb +15 -0
  28. data/lib/braze_ruby/rest/delete_users.rb +2 -2
  29. data/lib/braze_ruby/rest/email_hard_bounces.rb +1 -1
  30. data/lib/braze_ruby/rest/email_status.rb +3 -3
  31. data/lib/braze_ruby/rest/email_unsubscribes.rb +1 -1
  32. data/lib/braze_ruby/rest/export_users.rb +7 -7
  33. data/lib/braze_ruby/rest/identify_users.rb +2 -2
  34. data/lib/braze_ruby/rest/list_segments.rb +1 -1
  35. data/lib/braze_ruby/rest/remove_email_addresses_from_spam.rb +13 -0
  36. data/lib/braze_ruby/rest/remove_external_ids.rb +2 -2
  37. data/lib/braze_ruby/rest/rename_external_ids.rb +2 -2
  38. data/lib/braze_ruby/rest/schedule_messages.rb +6 -6
  39. data/lib/braze_ruby/rest/scheduled_broadcasts.rb +20 -0
  40. data/lib/braze_ruby/rest/send_messages.rb +3 -3
  41. data/lib/braze_ruby/rest/subscription_status_get.rb +1 -1
  42. data/lib/braze_ruby/rest/subscription_status_set.rb +1 -1
  43. data/lib/braze_ruby/rest/subscription_user_status.rb +1 -1
  44. data/lib/braze_ruby/rest/track_users.rb +4 -4
  45. data/lib/braze_ruby/rest/trigger_campaign_schedule.rb +18 -0
  46. data/lib/braze_ruby/rest/trigger_campaign_send.rb +1 -1
  47. data/lib/braze_ruby/rest/trigger_canvas_send.rb +1 -1
  48. data/lib/braze_ruby/rest.rb +24 -20
  49. data/lib/braze_ruby/version.rb +1 -1
  50. data/lib/braze_ruby.rb +17 -4
  51. metadata +51 -197
  52. data/.github/workflows/ci.yml +0 -30
  53. data/Gemfile.lock +0 -82
  54. data/spec/braze_ruby/api_spec.rb +0 -6
  55. data/spec/braze_ruby/endpoints/delete_users_spec.rb +0 -31
  56. data/spec/braze_ruby/endpoints/track_users_spec.rb +0 -74
  57. data/spec/braze_ruby/http_spec.rb +0 -48
  58. data/spec/braze_ruby/rest/create_user_aliases_spec.rb +0 -23
  59. data/spec/braze_ruby/rest/delete_users_spec.rb +0 -22
  60. data/spec/braze_ruby/rest/email_status_spec.rb +0 -20
  61. data/spec/braze_ruby/rest/export_users_spec.rb +0 -21
  62. data/spec/braze_ruby/rest/identify_users_spec.rb +0 -23
  63. data/spec/braze_ruby/rest/remove_external_ids_spec.rb +0 -22
  64. data/spec/braze_ruby/rest/rename_external_ids_spec.rb +0 -22
  65. data/spec/braze_ruby/rest/schedule_messages_spec.rb +0 -37
  66. data/spec/braze_ruby/rest/send_messages_spec.rb +0 -30
  67. data/spec/braze_ruby/rest/track_users_spec.rb +0 -27
  68. data/spec/factories.rb +0 -38
  69. data/spec/fixtures/responses/campaigns/trigger_send/sends_an_email.yml +0 -71
  70. data/spec/fixtures/responses/canvas/details/returns_error_when_no_canvas.yml +0 -69
  71. data/spec/fixtures/responses/canvas/trigger_send/sends_a_canvas.yml +0 -71
  72. data/spec/fixtures/responses/create_user_aliases/unauthorized/responds_with_unauthorized.yml +0 -67
  73. data/spec/fixtures/responses/create_user_aliases/with_success/responds_with_created.yml +0 -71
  74. data/spec/fixtures/responses/create_user_aliases/with_success/responds_with_success_message.yml +0 -71
  75. data/spec/fixtures/responses/delete_users/unauthorized/responds_with_unauthorized.yml +0 -68
  76. data/spec/fixtures/responses/delete_users/with_success/responds_with_created.yml +0 -71
  77. data/spec/fixtures/responses/delete_users/with_success/responds_with_success_message.yml +0 -71
  78. data/spec/fixtures/responses/email_status/existing_email/responds_with_created.yml +0 -71
  79. data/spec/fixtures/responses/email_status/existing_email/responds_with_success_message.yml +0 -71
  80. data/spec/fixtures/responses/email_status/unknown_email/responds_with_bad_request.yml +0 -71
  81. data/spec/fixtures/responses/email_status/unknown_email/responds_with_success_message.yml +0 -71
  82. data/spec/fixtures/responses/email_sync/hard_bounces/responds_with_empty_array_when_no_hard_bounces.yml +0 -75
  83. data/spec/fixtures/responses/email_sync/unsubscribes/responds_with_empty_array_when_no_unsubscribes.yml +0 -75
  84. data/spec/fixtures/responses/email_sync/unsubscribes/responds_with_unsubscribed_emails.yml +0 -75
  85. data/spec/fixtures/responses/export_users/by_ids/with_success/responds_with_created.yml +0 -72
  86. data/spec/fixtures/responses/export_users/by_segment/with_success/responds_with_created.yml +0 -71
  87. data/spec/fixtures/responses/identify_users/unauthorized/responds_with_unauthorized.yml +0 -68
  88. data/spec/fixtures/responses/identify_users/with_success/responds_with_created.yml +0 -71
  89. data/spec/fixtures/responses/identify_users/with_success/responds_with_success_message.yml +0 -71
  90. data/spec/fixtures/responses/list_segments/with_success/responds_with_a_list_of_segments.yml +0 -81
  91. data/spec/fixtures/responses/list_segments/with_success/responds_with_success.yml +0 -81
  92. data/spec/fixtures/responses/remove_external_ids/unauthorized/responds_with_unauthorized.yml +0 -67
  93. data/spec/fixtures/responses/remove_external_ids/with_success/responds_with_created.yml +0 -69
  94. data/spec/fixtures/responses/remove_external_ids/with_success/responds_with_success_message.yml +0 -69
  95. data/spec/fixtures/responses/rename_external_ids/unauthorized/responds_with_unauthorized.yml +0 -67
  96. data/spec/fixtures/responses/rename_external_ids/with_success/responds_with_created.yml +0 -69
  97. data/spec/fixtures/responses/rename_external_ids/with_success/responds_with_success_message.yml +0 -69
  98. data/spec/fixtures/responses/schedule_messages/unauthorized/responds_with_unauthorize.yml +0 -68
  99. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_created.yml +0 -71
  100. data/spec/fixtures/responses/schedule_messages/with_success/responds_with_success_message.yml +0 -71
  101. data/spec/fixtures/responses/send_messages/unauthorized/responds_with_unauthorized.yml +0 -68
  102. data/spec/fixtures/responses/send_messages/with_success/responds_with_created.yml +0 -71
  103. data/spec/fixtures/responses/send_messages/with_success/responds_with_success_message.yml +0 -71
  104. data/spec/fixtures/responses/subscription/subscription_status_set/when_subscribing/subscribes_the_user.yml +0 -71
  105. data/spec/fixtures/responses/subscription/subscription_status_set/when_subscription_group_does_not_exist/returns_an_error_status.yml +0 -68
  106. data/spec/fixtures/responses/subscription/subscription_status_set/when_unsubscribing/unsubscribes_the_user.yml +0 -139
  107. data/spec/fixtures/responses/subscription/when_getting_subscription_group_statuses/subscription_status_get/when_checking_subscribed_and_unsubscribed_user_status/returns_only_users_that_were_once_subscribed.yml +0 -211
  108. data/spec/fixtures/responses/subscription/when_getting_subscription_group_statuses/subscription_status_get/when_group_does_not_exist/returns_an_error.yml +0 -199
  109. data/spec/fixtures/responses/subscription/when_getting_subscription_group_statuses/subscription_user_status/returns_subscription_groups_and_status_for_every_group.yml +0 -211
  110. data/spec/fixtures/responses/track_users/unauthorized/responds_with_unauthorized.yml +0 -70
  111. data/spec/fixtures/responses/track_users/with_success/responds_with_created.yml +0 -73
  112. data/spec/fixtures/responses/track_users/with_success/responds_with_success_message.yml +0 -73
  113. data/spec/integrations/campaigns_spec.rb +0 -19
  114. data/spec/integrations/canvas_spec.rb +0 -28
  115. data/spec/integrations/create_user_aliases_spec.rb +0 -32
  116. data/spec/integrations/delete_users_spec.rb +0 -32
  117. data/spec/integrations/email_status_spec.rb +0 -38
  118. data/spec/integrations/email_sync_spec.rb +0 -31
  119. data/spec/integrations/export_users_spec.rb +0 -29
  120. data/spec/integrations/identify_users_spec.rb +0 -32
  121. data/spec/integrations/list_segments_spec.rb +0 -21
  122. data/spec/integrations/remove_external_ids_spec.rb +0 -33
  123. data/spec/integrations/rename_external_ids_spec.rb +0 -37
  124. data/spec/integrations/schedule_messages_spec.rb +0 -34
  125. data/spec/integrations/send_messages_spec.rb +0 -33
  126. data/spec/integrations/subscription_spec.rb +0 -149
  127. data/spec/integrations/track_users_spec.rb +0 -38
  128. data/spec/spec_helper.rb +0 -25
  129. data/spec/support/factory_bot.rb +0 -12
  130. data/spec/support/integrations.rb +0 -27
  131. data/spec/support/vcr.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8aae95520a637f8bfb69c12c2df7700966eec68e243743fabc03798b194a924f
4
- data.tar.gz: 95791c077beeb50119d715e81374533778032ee85d1fef28ed946352a1bd618b
3
+ metadata.gz: 92627ab40d55d8abadf9acd07b143a0eae13586d0caad935e657c8e4fb074d54
4
+ data.tar.gz: e21b4acbf9aef12c2f7ab37029aece94f421a3a9e2d45afd0c41216316b3a402
5
5
  SHA512:
6
- metadata.gz: 61bd0b6c2bb7c59e396cc1c3aa40fe0b54095c95f0195c5287e96c6e8504955442052a36d8e137150e816a357e2ae2982c112d4a79df95047d4841adf9b8b448
7
- data.tar.gz: 1ac6bb7da1dc22c6138c62a00072ec62d82d48ac2ee8b2922607c62dabcd7febe36b798c606466d85c88bc86f8d01067f347a3c4b11d0d92ba7c46a003b6ea91
6
+ metadata.gz: 841f8f3d844ee4881f2d98745eaca37cbf47f7e3352e13373a39bf95567cfd10950df47b60ace6810f805db7962e76bcdcf707dd2ae363f7a16a14850e558b57
7
+ data.tar.gz: 5163647859b894bb7946503995fdbad55bc8becd0eb25fb3378b11cfb5283d1ae0cf01f8003a683246693d9c4e52b085f1b7af99e3e4cab0d6053189e10739df
@@ -0,0 +1,26 @@
1
+ version: 2.1
2
+ jobs:
3
+ test:
4
+ parameters:
5
+ ruby-version:
6
+ type: string
7
+ docker:
8
+ - image: << parameters.ruby-version >>
9
+ steps:
10
+ - checkout
11
+ - run:
12
+ name: Gem install bundler
13
+ command: gem update --system && gem install bundler
14
+ - run:
15
+ name: Bundle install
16
+ command: bundle install --jobs=4 --retry=3 --path vendor/bundle
17
+ - run:
18
+ name: Run tests
19
+ command: bundle exec rake
20
+ workflows:
21
+ all-tests:
22
+ jobs:
23
+ - test:
24
+ matrix:
25
+ parameters:
26
+ ruby-version: ["ruby:3.0.1", "ruby:2.7.3", "ruby:2.6.7"]
@@ -0,0 +1,2 @@
1
+ ---
2
+ :rubygems_api_key: REPLACE_ME
@@ -0,0 +1,20 @@
1
+ name: release
2
+ on:
3
+ push:
4
+ tags:
5
+ - v*
6
+ jobs:
7
+ release:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - name: Setup rubygems
12
+ run: |
13
+ mkdir ~/.gem
14
+ cp ./.github/workflows/gem_credentials ~/.gem/credentials
15
+ chmod 0600 ~/.gem/credentials
16
+ sed -i "s/REPLACE_ME/${{ secrets.RUBYGEMS_KEY }}/g" ~/.gem/credentials
17
+ - name: Build gem
18
+ run: gem build braze_ruby.gemspec --output braze_ruby.gem
19
+ - name: Publish gem
20
+ run: gem push braze_ruby.gem
data/.gitignore CHANGED
@@ -1,19 +1,12 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- .ruby-version
7
- .ruby-gemset
8
- .env
9
- InstalledFiles
10
- _yardoc
11
- coverage
12
- doc/
13
- lib/bundler/man
14
- pkg
15
- rdoc
16
- spec/reports
17
- test/tmp
18
- test/version_tmp
19
- tmp
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ format: progress
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in braze_ruby.gemspec
6
5
  gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2014 Josh Nussbaum
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2021 Jon Allured
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # BrazeRuby
1
+ # BrazeRuby [![CircleCI][badge]][circle]
2
2
 
3
- A wrapper for the Braze REST API. Forked from https://github.com/DynamoMTL/appboy
3
+ A wrapper for the Braze REST API. Forked from
4
+ https://github.com/DynamoMTL/appboy
4
5
 
5
6
  ## Installation
6
7
 
@@ -16,12 +17,32 @@ Or install it yourself as:
16
17
 
17
18
  $ gem install braze_ruby
18
19
 
20
+ ### Configuration
21
+
22
+ Configuration options may be passed when a new API object is instantiated:
23
+
24
+ ```ruby
25
+ BrazeRuby::API.new('<braze-rest-api-key>', '<braze-rest-url', {<additional options>})
26
+ ```
27
+
28
+ Alternatively, you can pass your [Braze REST API key][braze_api_key], [Braze
29
+ REST URL][braze_url], and any required [Faraday options][faraday_options] to the
30
+ `BrazeRuby::configure` method:
31
+
32
+ ```ruby
33
+ BrazeRuby.configure do |config|
34
+ config.rest_api_key = '<braze-rest-api-key>'
35
+ config.rest_url = '<braze-rest-url>'
36
+ config.options = {<additional options>}
37
+ end
38
+ ```
39
+
19
40
  ## Examples
20
41
 
21
42
  ### Initializing API
22
43
 
23
44
  ```ruby
24
- api = BrazeRuby::API.new('<braze-rest-api-key>', '<braze-rest-api-url')
45
+ api = BrazeRuby::API.new('<braze-rest-api-key>', '<braze-rest-url')
25
46
  ```
26
47
 
27
48
  ### Track User Attributes
@@ -105,19 +126,37 @@ api.send_messages(messages: messages, external_user_ids: [123, 456])
105
126
  api.send_messages(messages: messages, segment_id: '<segment-id>')
106
127
  ```
107
128
 
108
-
109
129
  ### Schedule Message
110
130
 
111
131
  ```ruby
112
132
  api.schedule_messages(send_at: 1.hour.since, messages: messages, external_user_ids: [123, 456])
113
133
  ```
114
134
 
135
+ ### Schedule Campaigns
136
+
137
+ ```ruby
138
+ api.trigger_campaign_schedule(
139
+ campaign_id: 'campaign-id',
140
+ recipients: [{ external_user_id: 123 }]
141
+ schedule: { time: Time.now.iso8601 }
142
+ )
143
+ ```
144
+
145
+ ### Delete Scheduled Campaign
146
+
147
+ ```ruby
148
+ api.delete_campaign_trigger_schedule(
149
+ campaign_id: 'campaign_id',
150
+ schedule_id: 'schedule_id'
151
+ )
152
+ ```
153
+
115
154
  ### Send Campaigns
116
155
 
117
156
  ```ruby
118
157
  api.trigger_campaign_send(
119
158
  campaign_id: 'campaign-id',
120
- recipients: [external_user_id: 123, trigger_properties: {first_name: 'John'}]
159
+ recipients: [{external_user_id: 123, trigger_properties: { first_name: 'John' }}]
121
160
  )
122
161
  ```
123
162
 
@@ -136,6 +175,12 @@ api.trigger_canvas_send(
136
175
  api.email_status(email: 'john@example.com', status: :opted_in)
137
176
  ```
138
177
 
178
+ ### List Scheduled Messages and Canvases
179
+
180
+ ```ruby
181
+ api.scheduled_messages(end_time: Time.now.advance(weeks: 2).iso861)
182
+ ```
183
+
139
184
  ### List Segments
140
185
 
141
186
  ```ruby
@@ -246,9 +291,15 @@ api.email_unsubscribes(email: ['jdoe@example.com'])
246
291
  api.email_hard_bounces(email: ['jdoe@example.com'])
247
292
  ```
248
293
 
294
+ #### Remove Email Addresses From Spam List
295
+ ```ruby
296
+ api.remove_emails_from_spam(email: ['jdoe@example.com'])
297
+ ```
298
+
249
299
  ## Debugging
250
300
 
251
- The BRAZE_RUBY_DEBUG environment variable will trigger full printouts of the Faraday gem's HTTP requests and responses.
301
+ The BRAZE_RUBY_DEBUG environment variable will trigger full printouts of the
302
+ Faraday gem's HTTP requests and responses.
252
303
 
253
304
  ```bash
254
305
  cd /my/app
@@ -263,3 +314,9 @@ bundle exec rails whatever
263
314
  3. Commit your changes (`git commit -am 'Add some feature'`)
264
315
  4. Push to the branch (`git push origin my-new-feature`)
265
316
  5. Create new Pull Request
317
+
318
+ [badge]: https://circleci.com/gh/jonallured/braze_ruby.svg?style=svg
319
+ [braze_api_key]: https://www.braze.com/docs/api/api_key/
320
+ [braze_url]: https://www.braze.com/docs/api/basics/#endpoints
321
+ [circle]: https://circleci.com/gh/jonallured/braze_ruby
322
+ [faraday_options]: https://github.com/lostisland/faraday/blob/main/lib/faraday/options.rb
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
+ require "standard/rake"
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
- task default: :spec
8
+ task default: %i[standard spec]
data/bin/release ADDED
@@ -0,0 +1,16 @@
1
+ #! /bin/sh
2
+ set -ex
3
+
4
+ old_version=$1
5
+ new_version=$2
6
+
7
+ version_files="lib/braze_ruby/version.rb Gemfile.lock"
8
+ commit_message="Bumping version numbers for $new_version"
9
+ tag_message="Tagging version $new_version"
10
+
11
+ sed -i "" "s/$old_version/$new_version/g" $version_files
12
+ git add .
13
+ git commit --message "$commit_message"
14
+ git push origin main
15
+ git tag --annotate v$new_version --message "$tag_message"
16
+ git push origin --tags
data/braze_ruby.gemspec CHANGED
@@ -1,38 +1,35 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'braze_ruby/version'
1
+ require_relative "lib/braze_ruby/version"
4
2
 
5
3
  Gem::Specification.new do |spec|
6
- spec.name = 'braze_ruby'
7
- spec.version = BrazeRuby::VERSION
8
- spec.authors = ['Josh Nussbaum', 'Hugo Bastien', 'Justin Boltz']
9
- spec.email = %w(josh@godynamo.com hugo@godynamo.com justin.boltz@takl.com)
10
- spec.description = %q{Braze wrapper}
11
- spec.summary = %q{A wrapper for the Braze REST API forked from the appboy gem, track users/events/purchases, send & schedule messages}
12
- spec.homepage = 'https://www.braze.com/'
13
- spec.license = 'MIT'
4
+ spec.name = "braze_ruby"
5
+ spec.version = BrazeRuby::VERSION
6
+ spec.authors = ["Josh Nussbaum", "Hugo Bastien", "Justin Boltz", "Jonathan Allured"]
7
+ spec.email = %w[josh@godynamo.com hugo@godynamo.com justin.boltz@takl.com jon.allured@gmail.com]
14
8
 
15
- if spec.respond_to?(:metadata)
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/jboltz88/braze_ruby"
18
- else
19
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
20
- end
9
+ spec.summary = "A wrapper gem for the Braze REST API."
10
+ spec.description = "Wrapper for Braze API"
11
+ spec.homepage = "https://github.com/jonallured/braze_ruby"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
21
17
 
22
- spec.files = `git ls-files`.split($/)
23
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
- spec.require_paths = ['lib']
26
- spec.required_ruby_version = '>= 2.0'
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
20
+ end
21
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
27
24
 
28
- spec.add_dependency 'faraday'
25
+ spec.add_dependency "faraday"
29
26
 
30
- spec.add_development_dependency 'bundler', '>= 1.3'
31
- spec.add_development_dependency 'rake', '>= 12.3.3'
32
- spec.add_development_dependency 'rspec', '~> 3.8'
33
- spec.add_development_dependency 'dotenv', '~> 2.7.5'
34
- spec.add_development_dependency 'vcr', '>= 5.0.0'
35
- spec.add_development_dependency 'webmock', '>= 3.7.5'
36
- spec.add_development_dependency 'pry', '>= 0.12.2'
37
- spec.add_development_dependency 'factory_bot', '>= 5.1.0'
27
+ spec.add_development_dependency "dotenv"
28
+ spec.add_development_dependency "factory_bot"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "rspec"
32
+ spec.add_development_dependency "standard"
33
+ spec.add_development_dependency "vcr"
34
+ spec.add_development_dependency "webmock"
38
35
  end
@@ -1,17 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'braze_ruby/deprecated'
4
- require 'braze_ruby/endpoints/track_users'
5
- require 'braze_ruby/endpoints/send_messages'
6
- require 'braze_ruby/endpoints/schedule_messages'
7
- require 'braze_ruby/endpoints/email_status'
8
- require 'braze_ruby/endpoints/email_sync'
9
- require 'braze_ruby/endpoints/delete_users'
10
- require 'braze_ruby/endpoints/campaigns'
11
- require 'braze_ruby/endpoints/canvas'
12
- require 'braze_ruby/endpoints/subscription'
13
- require 'braze_ruby/endpoints/rename_external_ids'
14
- require 'braze_ruby/endpoints/remove_external_ids'
3
+ require "braze_ruby/deprecated"
4
+ require "braze_ruby/endpoints/track_users"
5
+ require "braze_ruby/endpoints/send_messages"
6
+ require "braze_ruby/endpoints/schedule_messages"
7
+ require "braze_ruby/endpoints/email_status"
8
+ require "braze_ruby/endpoints/email_sync"
9
+ require "braze_ruby/endpoints/delete_users"
10
+ require "braze_ruby/endpoints/campaigns"
11
+ require "braze_ruby/endpoints/canvas"
12
+ require "braze_ruby/endpoints/subscription"
13
+ require "braze_ruby/endpoints/rename_external_ids"
14
+ require "braze_ruby/endpoints/remove_external_ids"
15
+ require "braze_ruby/endpoints/remove_email_addresses_from_spam"
15
16
 
16
17
  module BrazeRuby
17
18
  class API
@@ -30,6 +31,7 @@ module BrazeRuby
30
31
  include BrazeRuby::Endpoints::CreateUserAliases
31
32
  include BrazeRuby::Endpoints::RenameExternalIds
32
33
  include BrazeRuby::Endpoints::RemoveExternalIds
34
+ include BrazeRuby::Endpoints::RemoveEmailAddressesFromSpam
33
35
 
34
36
  def export_users(**payload)
35
37
  BrazeRuby::REST::ExportUsers.new(api_key, braze_url, options).perform(**payload)
@@ -42,9 +44,9 @@ module BrazeRuby
42
44
  attr_reader :api_key, :braze_url, :options
43
45
 
44
46
  def initialize(api_key, braze_url, options = {})
45
- @api_key = api_key
46
- @braze_url = braze_url
47
- @options = options
47
+ @api_key = api_key || configuration.rest_api_key
48
+ @braze_url = braze_url || configuration.rest_url
49
+ @options = options || configuration.options
48
50
  end
49
51
  end
50
52
  end
@@ -0,0 +1,13 @@
1
+ module BrazeRuby
2
+ class Configuration
3
+ attr_accessor :rest_api_key,
4
+ :rest_url,
5
+ :options # See BrazeRuby::HTTP#default_options
6
+
7
+ def initialize
8
+ @rest_api_key = nil
9
+ @rest_url = nil
10
+ @options = nil
11
+ end
12
+ end
13
+ end
@@ -3,19 +3,18 @@
3
3
  module BrazeRuby
4
4
  module Deprecated
5
5
  def track(attribute, events = [], purchases = [])
6
- warn('[BrazeRuby] `track` is deprecated. Please use `track_users` instead.')
6
+ warn("[BrazeRuby] `track` is deprecated. Please use `track_users` instead.")
7
7
  track_users(attribute: attribute, events: events, purchases: purchases)
8
8
  end
9
9
 
10
10
  def send_message(message, user_ids, segment_ids = nil)
11
- warn('[BrazeRuby] `send_message` is deprecated. Please use `send_messages` instead.')
11
+ warn("[BrazeRuby] `send_message` is deprecated. Please use `send_messages` instead.")
12
12
  send_messages(messages: message, user_ids: user_ids, segment_ids: segment_ids)
13
13
  end
14
14
 
15
15
  def schedule_message(date, message, segment_id, local_timezone = false)
16
- warn('[BrazeRuby] `schedule_message` is deprecated. Please use `schedule_messages` instead.')
17
- schedule_messages(send_at: date, messages: message,
18
- segment_id: segment_id, local_timezone: local_timezone)
16
+ warn("[BrazeRuby] `schedule_message` is deprecated. Please use `schedule_messages` instead.")
17
+ schedule_messages(send_at: date, messages: message, segment_id: segment_id, local_timezone: local_timezone)
19
18
  end
20
19
  end
21
20
  end
@@ -3,9 +3,17 @@
3
3
  module BrazeRuby
4
4
  module Endpoints
5
5
  module Campaigns
6
+ def delete_campaign_trigger_schedule(**payload)
7
+ BrazeRuby::REST::DeleteTriggerCampaignSchedule.new(api_key, braze_url, options).perform(**payload)
8
+ end
9
+
6
10
  def trigger_campaign_send(**payload)
7
11
  BrazeRuby::REST::TriggerCampaignSend.new(api_key, braze_url, options, **payload).perform
8
12
  end
13
+
14
+ def trigger_campaign_schedule(**payload)
15
+ BrazeRuby::REST::TriggerCampaignSchedule.new(api_key, braze_url, options, **payload).perform
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BrazeRuby
4
+ module Endpoints
5
+ module RemoveEmailAddressesFromSpam
6
+ attr_writer :remove_emails_from_spam_service
7
+
8
+ def remove_emails_from_spam(**payload)
9
+ remove_emails_from_spam_service.perform(**payload)
10
+ end
11
+
12
+ private
13
+
14
+ def remove_emails_from_spam_service
15
+ @remove_emails_from_spam_service ||= BrazeRuby::REST::RemoveEmailAddressesFromSpam.new(api_key, braze_url, options)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,8 +5,8 @@ module BrazeRuby
5
5
  module RemoveExternalIds
6
6
  attr_writer :remove_external_ids_service
7
7
 
8
- def remove_external_ids(**payload)
9
- remove_external_ids_service.perform(**payload)
8
+ def remove_external_ids(payload)
9
+ remove_external_ids_service.perform(external_ids: payload[:external_ids])
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module BrazeRuby
5
5
  module RenameExternalIds
6
6
  attr_writer :rename_external_ids_service
7
7
 
8
- def rename_external_ids(**payload)
9
- rename_external_ids_service.perform(**payload)
8
+ def rename_external_ids(payload)
9
+ rename_external_ids_service.perform(external_id_renames: payload[:external_id_renames])
10
10
  end
11
11
 
12
12
  private
@@ -4,13 +4,11 @@ module BrazeRuby
4
4
  module Endpoints
5
5
  module ScheduleMessages
6
6
  def schedule_messages(**payload)
7
- schedule_messages_service.new(api_key, braze_url, options, **payload).perform
7
+ BrazeRuby::REST::ScheduleMessages.new(api_key, braze_url, options, **payload).perform
8
8
  end
9
9
 
10
- private
11
-
12
- def schedule_messages_service
13
- BrazeRuby::REST::ScheduleMessages
10
+ def scheduled_messages(**payload)
11
+ BrazeRuby::REST::ScheduledBroadcasts.new(api_key, braze_url, options, **payload).perform
14
12
  end
15
13
  end
16
14
  end
@@ -11,7 +11,6 @@ module BrazeRuby
11
11
  BrazeRuby::REST::SubscriptionStatusGet.new(api_key, braze_url, options, **payload).perform
12
12
  end
13
13
 
14
-
15
14
  def subscription_user_status(**payload)
16
15
  BrazeRuby::REST::SubscriptionUserStatus.new(api_key, braze_url, options, **payload).perform
17
16
  end
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'braze_ruby/endpoints/email_status'
4
- require 'braze_ruby/endpoints/email_sync'
5
- require 'braze_ruby/endpoints/schedule_messages'
6
- require 'braze_ruby/endpoints/send_messages'
7
- require 'braze_ruby/endpoints/track_users'
8
- require 'braze_ruby/endpoints/delete_users'
9
- require 'braze_ruby/endpoints/identify_users'
10
- require 'braze_ruby/endpoints/create_user_aliases'
11
- require 'braze_ruby/endpoints/rename_external_ids'
12
- require 'braze_ruby/endpoints/remove_external_ids'
3
+ require "braze_ruby/endpoints/email_status"
4
+ require "braze_ruby/endpoints/email_sync"
5
+ require "braze_ruby/endpoints/schedule_messages"
6
+ require "braze_ruby/endpoints/send_messages"
7
+ require "braze_ruby/endpoints/track_users"
8
+ require "braze_ruby/endpoints/delete_users"
9
+ require "braze_ruby/endpoints/identify_users"
10
+ require "braze_ruby/endpoints/create_user_aliases"
11
+ require "braze_ruby/endpoints/rename_external_ids"
12
+ require "braze_ruby/endpoints/remove_external_ids"
13
+ require "braze_ruby/endpoints/remove_email_addresses_from_spam"
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require 'faraday'
3
+ require "json"
4
+ require "faraday"
5
5
 
6
6
  module BrazeRuby
7
7
  class HTTP
8
8
  DEFAULT_TIMEOUT = 30
9
+ DEFAULT_OPEN_TIMEOUT = 5
9
10
 
10
11
  def initialize(api_key, braze_url, options = {})
11
- @api_key = api_key
12
+ @api_key = api_key
12
13
  @braze_url = braze_url
13
- @options = default_options.merge(options)
14
+ @options = default_options.merge(options)
14
15
  end
15
16
 
16
17
  def post(path, payload)
@@ -25,23 +26,25 @@ module BrazeRuby
25
26
 
26
27
  def connection
27
28
  @connection ||= Faraday.new(url: @braze_url) do |connection|
28
- connection.headers["Content-Type"] = "application/json"
29
- connection.headers["Accept"] = "application/json"
30
- connection.headers["User-Agent"] = "Braze Ruby gem v#{BrazeRuby::VERSION}"
29
+ connection.headers["Content-Type"] = "application/json"
30
+ connection.headers["Accept"] = "application/json"
31
+ connection.headers["User-Agent"] = "Braze Ruby gem v#{BrazeRuby::VERSION}"
31
32
  connection.headers["Authorization"] = "Bearer #{@api_key}"
32
33
 
33
- connection.response :logger if ENV['BRAZE_RUBY_DEBUG']
34
+ connection.response :logger if ENV["BRAZE_RUBY_DEBUG"]
35
+ connection.request :retry, @options[:retry] if @options[:retry]
34
36
 
35
37
  connection.adapter Faraday.default_adapter
36
38
 
37
39
  connection.options[:timeout] = @options[:timeout]
40
+ connection.options[:open_timeout] = @options[:open_timeout]
38
41
  end
39
42
  end
40
43
 
41
44
  private
42
45
 
43
46
  def default_options
44
- {timeout: DEFAULT_TIMEOUT}
47
+ {timeout: DEFAULT_TIMEOUT, open_timeout: DEFAULT_OPEN_TIMEOUT}
45
48
  end
46
49
  end
47
50
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'braze_ruby/http'
3
+ require "braze_ruby/http"
4
4
 
5
5
  module BrazeRuby
6
6
  module REST
@@ -8,9 +8,9 @@ module BrazeRuby
8
8
  attr_writer :http
9
9
 
10
10
  def initialize(api_key, braze_url, options)
11
- @api_key = api_key
11
+ @api_key = api_key
12
12
  @braze_url = braze_url
13
- @options = options
13
+ @options = options
14
14
  end
15
15
 
16
16
  private