braze_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +32 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +21 -0
- data/README.md +127 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/braze_api.gemspec +44 -0
- data/lib/braze_api.rb +7 -0
- data/lib/braze_api/client.rb +49 -0
- data/lib/braze_api/endpoints/subscription_groups/status.rb +21 -0
- data/lib/braze_api/endpoints/users/alias.rb +23 -0
- data/lib/braze_api/endpoints/users/export.rb +27 -0
- data/lib/braze_api/endpoints/users/identify.rb +26 -0
- data/lib/braze_api/endpoints/users/track.rb +43 -0
- data/lib/braze_api/errors.rb +20 -0
- data/lib/braze_api/response/raise_error.rb +26 -0
- data/lib/braze_api/version.rb +5 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5b354e0c914113afc16b8186ee81b1628343fb21
|
4
|
+
data.tar.gz: c068322384b40a25226122bc31fd84cacac904ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3614fc51536da290714201ab29d9aeb6d4a98b2c6e203c155badd2dc7e6f04e7d7909341a2c3d68f8f62566568015a042d37d30b9bcc0a4a09b284a01d4d623
|
7
|
+
data.tar.gz: 9ab1b7f729ef4ba477d778c983671aa87d93b749575eeb79a4d710658ba48c7caeb30cd5925811444955c9c95a079d057ba1749316694239c9cbdd07f10d2592
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: Lint & Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby 2.4
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 2.4
|
22
|
+
bundler-cache: true
|
23
|
+
- name: Run rubocop
|
24
|
+
run: |
|
25
|
+
gem install bundler
|
26
|
+
bundle install --jobs 4 --retry 3
|
27
|
+
bundle exec rubocop
|
28
|
+
- name: Run tests
|
29
|
+
run: |
|
30
|
+
bundle exec rspec
|
31
|
+
|
32
|
+
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.4
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at janie.amero@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
braze_api (0.1.0)
|
5
|
+
faraday (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.1)
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
faraday (1.0.1)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
method_source (1.0.0)
|
16
|
+
multipart-post (2.1.1)
|
17
|
+
parallel (1.19.2)
|
18
|
+
parser (2.7.1.4)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
pry (0.13.1)
|
21
|
+
coderay (~> 1.1)
|
22
|
+
method_source (~> 1.0)
|
23
|
+
rainbow (3.0.0)
|
24
|
+
rake (12.3.3)
|
25
|
+
regexp_parser (1.8.0)
|
26
|
+
rexml (3.2.4)
|
27
|
+
rspec (3.9.0)
|
28
|
+
rspec-core (~> 3.9.0)
|
29
|
+
rspec-expectations (~> 3.9.0)
|
30
|
+
rspec-mocks (~> 3.9.0)
|
31
|
+
rspec-core (3.9.2)
|
32
|
+
rspec-support (~> 3.9.3)
|
33
|
+
rspec-expectations (3.9.2)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-mocks (3.9.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-support (3.9.3)
|
40
|
+
rubocop (0.91.0)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.7.1.1)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
regexp_parser (>= 1.7)
|
45
|
+
rexml
|
46
|
+
rubocop-ast (>= 0.4.0, < 1.0)
|
47
|
+
ruby-progressbar (~> 1.7)
|
48
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
49
|
+
rubocop-ast (0.4.2)
|
50
|
+
parser (>= 2.7.1.4)
|
51
|
+
ruby-progressbar (1.10.1)
|
52
|
+
unicode-display_width (1.7.0)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
braze_api!
|
59
|
+
bundler (~> 2.0)
|
60
|
+
pry (~> 0.13.1)
|
61
|
+
rake (~> 12.3)
|
62
|
+
rspec (~> 3.9)
|
63
|
+
rubocop (~> 0.91)
|
64
|
+
|
65
|
+
BUNDLED WITH
|
66
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Janie Amero
|
4
|
+
|
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:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
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
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# BrazeAPI
|
2
|
+
|
3
|
+
The BrazeAPI gem is a Ruby wrapper for the [Braze REST API](https://www.braze.com/docs/api/basics/)
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'braze_api'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install braze_api
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
First you must create a client instance with your api_key, app_id, and braze_url:
|
25
|
+
```ruby
|
26
|
+
braze = BrazeAPI::Client.new(api_key: YOUR_API_KEY, app_id: YOUR_APP_ID, braze_url: YOUR_BRAZE_URL)
|
27
|
+
```
|
28
|
+
Once you've created your braze instance you can call a number of methods to the endpoints available in the gem:
|
29
|
+
|
30
|
+
### Users Track endpoint:
|
31
|
+
|
32
|
+
[Track](https://www.braze.com/docs/api/endpoints/user_data/post_user_track/)
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
braze.track(events: [], purchases: [], attributes: [])
|
36
|
+
```
|
37
|
+
With this method you can pass multiple event, purchase, and/or attribute objects at once. It will add a timestamp (current time) and your app_id to the event and purchase objects.
|
38
|
+
|
39
|
+
For single tracking objects you can call like:
|
40
|
+
```ruby
|
41
|
+
braze.track_event({ external_id: '123', event_name: 'A great event' })
|
42
|
+
braze.track_purchase({ external_id: '123', product_id: 'Space1', currency: 'GBP', price: 12.50 })
|
43
|
+
braze.track_attribute({ external_id: '123', first_name: 'Janie' })
|
44
|
+
```
|
45
|
+
These methods call `track` with just the single object
|
46
|
+
- [Event object documentation](https://www.braze.com/docs/api/objects_filters/event_object/#event-object)
|
47
|
+
- [Purchase object documentation](https://www.braze.com/docs/api/objects_filters/purchase_object/)
|
48
|
+
- [User Attributes object documentation](https://www.braze.com/docs/api/objects_filters/user_attributes_object/)
|
49
|
+
|
50
|
+
### Users Alias Endpoint:
|
51
|
+
|
52
|
+
[Alias](https://www.braze.com/docs/api/endpoints/user_data/post_user_alias/)
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
braze.track(alias_name: 'test@email.com', alias_label: 'email')
|
56
|
+
```
|
57
|
+
This method creates a user alias in Braze when passed an alias_name and an alias_label.
|
58
|
+
|
59
|
+
### Users Identify Endpoint:
|
60
|
+
|
61
|
+
[Identify](https://www.braze.com/docs/api/endpoints/user_data/post_user_identify/)
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
braze.identify(user_alias: { alias_name: 'test@email.com', alias_label: 'email' }, external_id: '123')
|
65
|
+
```
|
66
|
+
This method identifies an alias user when passed a user alias and an external id.
|
67
|
+
|
68
|
+
### Users Export Endpoint:
|
69
|
+
|
70
|
+
[Export Users](https://www.braze.com/docs/api/endpoints/export/user_data/post_users_identifier/)
|
71
|
+
|
72
|
+
Called with an array of external ids and not passed fields to export will return all fields for each of the users corresponding to the ids.
|
73
|
+
```ruby
|
74
|
+
braze.export_users(external_ids: ['123', '345'])
|
75
|
+
```
|
76
|
+
Called with an array of external ids and passed fields to export will return only those fields for each of the users corresponding to the ids.
|
77
|
+
```ruby
|
78
|
+
braze.export_users(external_ids: ['123', '345'], fields_to_export: ['purchases','email_subscribe'])
|
79
|
+
```
|
80
|
+
Called with an email and not passed fields to export will return all fields for each of the users with that email.
|
81
|
+
```ruby
|
82
|
+
braze.export_users(email: 'hello@gmail.com')
|
83
|
+
```
|
84
|
+
|
85
|
+
### Subscription Groups Status Set Endpoint:
|
86
|
+
|
87
|
+
[Update Status](https://www.braze.com/docs/api/endpoints/subscription_groups/post_update_user_subscription_group_status/)
|
88
|
+
|
89
|
+
With this method you can update a user's subscription state for a particular subscription group. It is called with an email or an external id for an email subscription group, and with a phone number or external id for a push subscription group.
|
90
|
+
```ruby
|
91
|
+
braze.update_status(
|
92
|
+
external_id: '123',
|
93
|
+
subscription_state: 'subscribed',
|
94
|
+
subscription_group_id: 'b6dw887f-d8de-456f-345a-fc5ad8734723'
|
95
|
+
)
|
96
|
+
# With only an email for an email subscription group
|
97
|
+
braze.update_status(
|
98
|
+
email: 'hello@gmail.com',
|
99
|
+
subscription_state: 'subscribed',
|
100
|
+
subscription_group_id: 'b6dw887f-d8de-456f-345a-fc5ad8734723'
|
101
|
+
)
|
102
|
+
# With only an phone for a push subscription group
|
103
|
+
braze.update_status(
|
104
|
+
phone: '+440000000000',
|
105
|
+
subscription_state: 'subscribed',
|
106
|
+
subscription_group_id: 'b6dw887f-d8de-456f-345a-fc5ad8734723'
|
107
|
+
)
|
108
|
+
```
|
109
|
+
|
110
|
+
|
111
|
+
## Development
|
112
|
+
|
113
|
+
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.
|
114
|
+
|
115
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/appearhere/braze_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
120
|
+
|
121
|
+
## License
|
122
|
+
|
123
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
124
|
+
|
125
|
+
## Code of Conduct
|
126
|
+
|
127
|
+
Everyone interacting in the BrazeAPI project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/appearhere/braze_api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'braze_api'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/braze_api.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'braze_api/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'braze_api'
|
9
|
+
spec.version = BrazeAPI::VERSION
|
10
|
+
spec.authors = ['Janie Amero']
|
11
|
+
spec.email = ['janie.amero@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Braze API wrapper for Ruby'
|
14
|
+
spec.homepage = 'https://github.com/appearhere/braze_api'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
+
spec.metadata['source_code_uri'] = 'https://github.com/appearhere/braze_api'
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/appearhere/braze_api'
|
23
|
+
else
|
24
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
25
|
+
'public gem pushes.'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = 'exe'
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ['lib']
|
36
|
+
spec.required_ruby_version = '>= 2.4.4'
|
37
|
+
|
38
|
+
spec.add_runtime_dependency 'faraday', '~> 1.0'
|
39
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
40
|
+
spec.add_development_dependency 'pry', '~> 0.13.1'
|
41
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
43
|
+
spec.add_development_dependency 'rubocop', '~> 0.91'
|
44
|
+
end
|
data/lib/braze_api.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'json'
|
5
|
+
require 'braze_api/response/raise_error'
|
6
|
+
require 'braze_api/errors'
|
7
|
+
require 'braze_api/endpoints/users/track'
|
8
|
+
require 'braze_api/endpoints/users/alias'
|
9
|
+
require 'braze_api/endpoints/users/identify'
|
10
|
+
require 'braze_api/endpoints/users/export'
|
11
|
+
require 'braze_api/endpoints/subscription_groups/status'
|
12
|
+
|
13
|
+
module BrazeAPI
|
14
|
+
# The top-level class that handles configuration and connection to the Braze API.
|
15
|
+
class Client
|
16
|
+
attr_reader :app_id
|
17
|
+
include BrazeAPI::Endpoints::Users::Track
|
18
|
+
include BrazeAPI::Endpoints::Users::Alias
|
19
|
+
include BrazeAPI::Endpoints::Users::Identify
|
20
|
+
include BrazeAPI::Endpoints::Users::Export
|
21
|
+
include BrazeAPI::Endpoints::SubscriptionGroups::Status
|
22
|
+
|
23
|
+
def initialize(api_key:, braze_url:, app_id:)
|
24
|
+
@api_key = api_key
|
25
|
+
@braze_url = braze_url
|
26
|
+
@app_id = app_id
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns a parsed response from a post request
|
30
|
+
def post(endpoint, params: {})
|
31
|
+
response = client.post(endpoint, params.to_json)
|
32
|
+
JSON.parse(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :api_key, :braze_url
|
38
|
+
# Creates a Faraday connection if there is none, otherwise returns the existing.
|
39
|
+
def client
|
40
|
+
@client ||= Faraday.new(braze_url) do |faraday|
|
41
|
+
faraday.use BrazeAPI::Response::RaiseError
|
42
|
+
faraday.adapter Faraday.default_adapter
|
43
|
+
faraday.headers['User-Agent'] = "Braze API Client gem v#{BrazeAPI::VERSION}"
|
44
|
+
faraday.headers['Content-Type'] = 'application/json'
|
45
|
+
faraday.headers['Authorization'] = "Bearer #{api_key}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrazeAPI
|
4
|
+
module Endpoints
|
5
|
+
module SubscriptionGroups
|
6
|
+
# Methods to call the subscription/status endpoint from a client instance
|
7
|
+
module Status
|
8
|
+
PATH = '/subscription/status/set'
|
9
|
+
# The method to update a users subscription status
|
10
|
+
# Args object will look like:
|
11
|
+
# {subscription_state: 'subscribed', subscription_group_id: id, external_id: uuid}
|
12
|
+
# with either an external_id or an email and the subscription state
|
13
|
+
# and subscription group id
|
14
|
+
def update_status(args = {})
|
15
|
+
args.compact!
|
16
|
+
post(PATH, params: args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrazeAPI
|
4
|
+
module Endpoints
|
5
|
+
module Users
|
6
|
+
# Methods to call the users/alias/new endpoint from a client instance
|
7
|
+
module Alias
|
8
|
+
PATH = '/users/alias/new'
|
9
|
+
|
10
|
+
# The main method calling the endpoint.
|
11
|
+
# Called with an alias name and an alias label.
|
12
|
+
def alias(alias_name:, alias_label:)
|
13
|
+
post(
|
14
|
+
PATH,
|
15
|
+
params: {
|
16
|
+
user_aliases: [{ alias_name: alias_name, alias_label: alias_label }]
|
17
|
+
}
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrazeAPI
|
4
|
+
module Endpoints
|
5
|
+
module Users
|
6
|
+
# Methods to call the users/export endpoint from a client instance
|
7
|
+
module Export
|
8
|
+
PATH = '/users/export/ids'
|
9
|
+
# The main method calling the endpoint.
|
10
|
+
# Called with an email, array of external_ids,
|
11
|
+
# and the fields that you wish to export data on.
|
12
|
+
# can only search by one email at a time, but can search with multiple ids
|
13
|
+
def export_users(email: nil, external_ids: [], fields_to_export: [])
|
14
|
+
body = {}.tap do |b|
|
15
|
+
b[:external_ids] = external_ids unless external_ids.empty?
|
16
|
+
b[:email_address] = email if email && external_ids.empty?
|
17
|
+
b[:fields_to_export] = fields_to_export unless fields_to_export.empty?
|
18
|
+
end
|
19
|
+
post(
|
20
|
+
PATH,
|
21
|
+
params: body
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrazeAPI
|
4
|
+
module Endpoints
|
5
|
+
module Users
|
6
|
+
# Methods to call the users/identify endpoint from a client instance
|
7
|
+
module Identify
|
8
|
+
PATH = '/users/identify'
|
9
|
+
# The main method calling the endpoint.
|
10
|
+
# Called with an object containing the user alias object
|
11
|
+
# and the external id of the user being identified.
|
12
|
+
def identify(user_alias:, external_id:)
|
13
|
+
post(
|
14
|
+
PATH,
|
15
|
+
params: { aliases_to_identify: [
|
16
|
+
{
|
17
|
+
external_id: external_id,
|
18
|
+
user_alias: user_alias
|
19
|
+
}
|
20
|
+
] }
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
module BrazeAPI
|
5
|
+
module Endpoints
|
6
|
+
module Users
|
7
|
+
# Methods to call the users/track endpoint from a client instance
|
8
|
+
module Track
|
9
|
+
PATH = '/users/track'
|
10
|
+
|
11
|
+
# The main method calling the endpoint.
|
12
|
+
# Called with an object containing multiple events and/or purchases and attributes.
|
13
|
+
def track(args = {})
|
14
|
+
args[:events] = add_time_and_app_id(args[:events]) if args[:events]
|
15
|
+
args[:purchases] = add_time_and_app_id(args[:purchases]) if args[:purchases]
|
16
|
+
post(PATH, params: args)
|
17
|
+
end
|
18
|
+
|
19
|
+
# If you would like to track a single event object
|
20
|
+
def track_event(event)
|
21
|
+
track(events: [event])
|
22
|
+
end
|
23
|
+
|
24
|
+
# If you would like to track a single purchase object
|
25
|
+
def track_purchase(purchase)
|
26
|
+
track(purchases: [purchase])
|
27
|
+
end
|
28
|
+
|
29
|
+
# If you would like to track a single attribute object
|
30
|
+
def track_attribute(attribute)
|
31
|
+
track(attributes: [attribute])
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Adds the time (mandatory for events and purchases) and the app id
|
37
|
+
def add_time_and_app_id(tracking_objects)
|
38
|
+
tracking_objects.map { |obj| obj.merge!(time: Time.now.iso8601, app_id: app_id) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrazeAPI
|
4
|
+
module Errors
|
5
|
+
# Error to raise when 400 Bad Request
|
6
|
+
class BadRequest < StandardError; end
|
7
|
+
# Error to raise when 401 Unauthorized
|
8
|
+
class Unauthorized < StandardError
|
9
|
+
def message
|
10
|
+
'Invalid API Key'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
# Error to raise when 404 Not Found
|
14
|
+
class NotFound < StandardError; end
|
15
|
+
# Error to raise when 429 Rate Limited
|
16
|
+
class RateLimited < StandardError; end
|
17
|
+
# Error to raise when 5XX
|
18
|
+
class InternalServerError < StandardError; end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrazeAPI
|
4
|
+
module Response
|
5
|
+
# Extends the Faraday RaiseError middleware to handle errors
|
6
|
+
class RaiseError < Faraday::Response::RaiseError
|
7
|
+
def on_complete(env) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
8
|
+
case env[:status]
|
9
|
+
when 400
|
10
|
+
raise BrazeAPI::Errors::BadRequest, JSON.parse(response_values(env)[:body])['message']
|
11
|
+
when 401
|
12
|
+
raise BrazeAPI::Errors::Unauthorized
|
13
|
+
when 404
|
14
|
+
raise BrazeAPI::Errors::NotFound, JSON.parse(response_values(env)[:body])['message']
|
15
|
+
when 429
|
16
|
+
raise BrazeAPI::Errors::RateLimited, JSON.parse(response_values(env)[:body])['message']
|
17
|
+
when ClientErrorStatuses
|
18
|
+
raise BrazeAPI::Errors::InternalServerError,
|
19
|
+
JSON.parse(response_values(env)[:body])['message']
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: braze_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Janie Amero
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.13.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.91'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.91'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- janie.amero@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".github/workflows/main.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- ".ruby-version"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- braze_api.gemspec
|
118
|
+
- lib/braze_api.rb
|
119
|
+
- lib/braze_api/client.rb
|
120
|
+
- lib/braze_api/endpoints/subscription_groups/status.rb
|
121
|
+
- lib/braze_api/endpoints/users/alias.rb
|
122
|
+
- lib/braze_api/endpoints/users/export.rb
|
123
|
+
- lib/braze_api/endpoints/users/identify.rb
|
124
|
+
- lib/braze_api/endpoints/users/track.rb
|
125
|
+
- lib/braze_api/errors.rb
|
126
|
+
- lib/braze_api/response/raise_error.rb
|
127
|
+
- lib/braze_api/version.rb
|
128
|
+
homepage: https://github.com/appearhere/braze_api
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata:
|
132
|
+
homepage_uri: https://github.com/appearhere/braze_api
|
133
|
+
source_code_uri: https://github.com/appearhere/braze_api
|
134
|
+
changelog_uri: https://github.com/appearhere/braze_api
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 2.4.4
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.6.14.1
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Braze API wrapper for Ruby
|
155
|
+
test_files: []
|