Brazify

Wrapper library that provides convenient access to the Braze REST API from applications written in Ruby.

Documentation

See the Braze REST API docs.

Installation

Add this line to your application's Gemfile:

gem 'brazify'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install brazify

Requirements

  • Ruby 2.7+.

Usage

Configuration

The library needs to be configured with your braze account's API key and an optional base URL. Set Braze.api_key to its value:

# initializers/brazify.rb

Braze.api_key = 'braze-api-key...'
Braze.base_url = 'braze-base-url...'

Resources

Email

  Brazify::Email.update_status(
    email: '[email protected]',
    subscription_state: 'subscribed'
  )
  Brazify::Email.blacklist(
    email: '[email protected]'
  )

User

  Brazify::User.delete(
    external_ids: ['123', '456'],
    user_aliases: ['john_doe'], #optional
    braze_ids: ['789'] #optional
  )
 Brazify::User.track(
   attributes: [
     {
       external_id: 'user_identifier',
       string_attribute: 'fruit',
       boolean_attribute_1: true,
       integer_attribute: 25,
       array_attribute: %w[banana apple]
     }
   ],
   events: [
     {
       external_id: 'user_identifier',
       app_id: 'app_identifier',
       name: 'watched_trailer',
       time: '2013-07-16T19:20:30+1:00'
     }
   ],
   purchases: [
     {
       external_id: 'user_identifier',
       app_id: 'app_identifier',
       product_id: 'product_name',
       currency: 'USD',
       price: 12.12,
       quantity: 6,
       time: '2017-05-12T18:47:12Z',
       properties: {
         integer_property: 3,
         string_property: 'Russell',
         date_property: '2014-02-02T00:00:00Z'
       }
     }
   ]
 )

Event

  Brazify::Event.list
  Brazify::Event.retrieve_analytics(
    event: 'event_name',
    length: 24,
    options: {
      unit: 'hour',
      ending_at: '2014-12-10T23:59:59-05:00'
    }
  )

Segment

  Brazify::Segment.list
  Brazify::Segment.retrieve(
    segment_id: 123
  )
  Brazify::Segment.retrieve_analytics(
    segment_id: '123',
    length: 14,
    ending_at: '2018-06-27T23:59:59-5:00'
  )

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Releasing

To release a new version, run:

bin/release [major, minor, patch, <specific_version>]

This will bump the version, create a git tag for the version and push git commits and tags.

The CI will then handle creating a github release, updating the changelog and publishing the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Portify/brazify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Brazify project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.