Giter Site home page Giter Site logo

braze_ruby's Introduction

BrazeRuby CircleCI

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

Configuration

Configuration options may be passed when a new API object is instantiated:

BrazeRuby::API.new('<braze-rest-api-key>', '<braze-rest-url', {<additional options>})

Alternatively, you can pass your Braze REST API key, Braze REST URL, and any required Faraday options to the BrazeRuby::configure method:

BrazeRuby.configure do |config|
  config.rest_api_key = '<braze-rest-api-key>'
  config.rest_url = '<braze-rest-url>'
  config.options = {<additional options>}
end

Examples

Initializing API

api = BrazeRuby::API.new('<braze-rest-api-key>', '<braze-rest-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
messages = {
  android_push: { alert: 'Hello Android' },
  apple_push:   { alert: "Hello iOS" }
}
Option A, Using External User IDs
api.send_messages(messages: messages, external_user_ids: [123, 456])
Option B, Using Segment ID
api.send_messages(messages: messages, segment_id: '<segment-id>')

Schedule Message

api.schedule_messages(send_at: 1.hour.since, messages: messages, external_user_ids: [123, 456])

Schedule Campaigns

api.trigger_campaign_schedule(
  campaign_id: 'campaign-id',
  recipients: [{ external_user_id: 123 }]
  schedule: { time: Time.now.iso8601 }
)

Delete Scheduled Campaign

api.delete_campaign_trigger_schedule(
  campaign_id: 'campaign_id',
  schedule_id: 'schedule_id'
)

Send Campaigns

api.trigger_campaign_send(
  campaign_id: 'campaign-id',
  recipients: [{external_user_id: 123, trigger_properties: { first_name: 'John' }}]
)

Send Canvas

api.trigger_canvas_send(
  canvas_id: 'canvas-id',
  recipients: [external_user_id: 123, canvas_entry_properties: {first_name: 'John'}]
)

Changing Email Subscription

api.email_status(email: '[email protected]', status: :opted_in)

List Scheduled Messages and Canvases

api.scheduled_messages(end_time: Time.now.advance(weeks: 2).iso861)

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])

Subscription groups

Get subscription group status for users by id

api.subscription_user_status(external_id: [1])

Get users status for a specific subscription group

api.subscription_status_get(
  external_id: [1],
  subscription_group_id: 'some-uuid'
)

Set user status for a specific subscription group

api.subscription_status_set(
  external_id: [1],
  subscription_group_id: 'some-uuid',
  subscription_state: 'subscribed|unsubscribed'
)

User Alias

Create an alias-only user

api.create_user_aliases(
  user_aliases: [{
    user_alias: {
      alias_name: "device123",
      alias_label: "my_device_identifier",
    }
  }]
)

Identify an alias-only user

api.identify_users(
  aliases_to_identify: [{
    external_id: 1234,
    user_alias: {
      alias_name: "device123",
      alias_label: "my_device_identifier",
    }
  }]
)

External ID Migration

Rename users' external IDs with an array of external_id_renames

Note: you can send up to 50 rename objects per request.

api.rename_external_ids(
  external_id_renames: [{
    current_external_id: "old_external_id",
    new_external_id: "new_external_id",
  }]
)

Remove users' old deprecated external IDs

Note: you can send up to 50 external IDs per request.

api.remove_external_ids(external_ids: ['old_external_id'])

Email Sync

Get List of or Query Email Unsubscribes

api.email_unsubscribes(email: ['[email protected]'])

Get List of or Query Hard Bounced Emails

api.email_hard_bounces(email: ['[email protected]'])

Remove Email Addresses From Spam List

api.remove_emails_from_spam(email: ['[email protected]'])

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

braze_ruby's People

Contributors

bishwahang avatar dgalarza avatar fgoessler avatar hugobast avatar iskounen avatar jacobherrington avatar jerrodcarpenter avatar jhowden avatar jonallured avatar joshnuss avatar justinboltz avatar meshulam avatar morgoth avatar tborlee avatar tcione avatar trevorrjohn avatar wenga86 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.