BrazeRuby
A wrapper for the Braze REST API. Forked from https://github.com/DynamoMTL/appboy
Installation
Add this line to your application's Gemfile:
gem 'braze_ruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install braze_ruby
Examples
Initializing API
api = BrazeRuby::API.new('<braze-rest-api-key>', '<braze-rest-api-url')
Track User Attributes
api.track_users(attributes: [{
external_id: 123,
first_name: 'John',
last_name: 'Smith',
gender: 'male',
email: '[email protected]'
}])
Track Attributes for Single User
api.track_attribute(external_id: 123, first_name: 'John', ...)
Track Event
api.track_users(events: [{
external_id: 123,
name: 'add-to-cart',
time: Time.now
}])
Track Events for Single User
api.track_event(external_id: 123, name: 'Event', ...)
Track Purchase
api.track_users(purchases: [{
external_id: 123,
product_id: 456,
currency: 'CAD',
price: 1.99,
time: Time.now
}])
Track Purchases for Single User
api.track_purchase(external_id: 123, product_id: 456, ...)
Track Everything for Everyone All at Once
api.track_users(purchases: purchases, events: events, attributes: attributes)
Send Message
Messages Payload
= {
android_push: { alert: 'Hello Android' },
apple_push: { alert: "Hello iOS" }
}
Option A, Using External User IDs
api.(messages: , external_user_ids: [123, 456])
Option B, Using Segment ID
api.(messages: , segment_id: '<segment-id>')
Schedule Message
api.(send_at: 1.hour.since, messages: , external_user_ids: [123, 456])
Changing Email Subscription
api.email_status(email: '[email protected]', status: :opted_in)
List Segments
api.list_segments
Export Users
By IDs
api.export_users(external_ids: [1])
By Segment
api.export_users(segment_id: segment_id, callback_endpoint: 'https://example.com')
Delete Users
Delete Braze Users with an array of external_ids
api.delete_users([1, 2, 3])
Debugging
The BRAZE_RUBY_DEBUG environment variable will trigger full printouts of the Faraday gem's HTTP requests and responses.
cd /my/app
export BRAZE_RUBY_DEBUG=true
bundle exec rails whatever
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request