trycourier 1.0.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +49 -0
- data/CHANGELOG.md +93 -0
- data/CONTRIBUTING.md +28 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +39 -1
- data/README.md +364 -11
- data/Rakefile +2 -1
- data/lib/trycourier/automations.rb +67 -0
- data/lib/trycourier/brands.rb +70 -0
- data/lib/trycourier/bulk.rb +79 -0
- data/lib/trycourier/events.rb +35 -0
- data/lib/trycourier/exceptions.rb +37 -0
- data/lib/trycourier/lists.rb +109 -0
- data/lib/trycourier/messages.rb +51 -0
- data/lib/trycourier/profiles.rb +64 -0
- data/lib/trycourier/session.rb +81 -0
- data/lib/trycourier/version.rb +1 -1
- data/lib/trycourier.rb +62 -26
- data/trycourier.gemspec +15 -12
- metadata +45 -6
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43ad4d30cf60c972878593e731297e16218eb733d5f234d42630c76ee4e61b70
|
4
|
+
data.tar.gz: 1cf5722063320f2a9bd2365b28da54c2aed796c80fe26b5fd36f1e6409579c1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08b2ec48d0f42bc45e87cfa2877d100b5deb2eb9927985a6544dbce6546a7950819a8d7885ffcd1d86c94c300ca2246d536ff57cb6589db0bb6f67be34c20107'
|
7
|
+
data.tar.gz: d4a47fc88397e68f9160fb03fcee6ed11591c2d78eb044e279ab0463b225c22ebc2c0eb78a0eb4f879c79c76e65851a4d807f960676f1cce2424bae072e1198d
|
@@ -0,0 +1,49 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
tags:
|
7
|
+
- v*
|
8
|
+
pull_request:
|
9
|
+
branches: [master]
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby 2.7
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 2.7.x
|
21
|
+
- name: Install dependencies
|
22
|
+
run: bundle install
|
23
|
+
- name: Run tests
|
24
|
+
# Skipping rubocop for now
|
25
|
+
# run: bundle exec rake
|
26
|
+
run: bundle exec rspec spec
|
27
|
+
build:
|
28
|
+
name: Build + Publish
|
29
|
+
needs: test
|
30
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
31
|
+
runs-on: ubuntu-latest
|
32
|
+
|
33
|
+
steps:
|
34
|
+
- uses: actions/checkout@v2
|
35
|
+
- name: Set up Ruby 2.7
|
36
|
+
uses: actions/setup-ruby@v1
|
37
|
+
with:
|
38
|
+
ruby-version: 2.7.x
|
39
|
+
|
40
|
+
- name: Publish to RubyGems
|
41
|
+
run: |
|
42
|
+
mkdir -p $HOME/.gem
|
43
|
+
touch $HOME/.gem/credentials
|
44
|
+
chmod 0600 $HOME/.gem/credentials
|
45
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
46
|
+
gem build *.gemspec
|
47
|
+
gem push *.gem
|
48
|
+
env:
|
49
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
|
+
|
6
|
+
## [Unreleased][unreleased]
|
7
|
+
|
8
|
+
## [v1.3.0] - 2022-01-26
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Support for Bulk API by @tk26
|
13
|
+
|
14
|
+
## [v1.2.0] - 2021-04-08
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Support for [Automation API](https://docs.courier.com/reference/automation-api) by @tk26
|
19
|
+
- `POST /automations/invoke` with `client.automations.invoke` method
|
20
|
+
- `POST /automations/{template_id}/invoke` with `client.automations.invoke_template` method
|
21
|
+
|
22
|
+
## [v1.1.0] - 2021-01-26
|
23
|
+
|
24
|
+
### Added
|
25
|
+
|
26
|
+
- Support for Basic Auth
|
27
|
+
- ENV variables `COURIER_AUTH_USERNAME` and `COURIER_AUTH_PASSWORD` OR set with params
|
28
|
+
- Token Auth using ENV variables
|
29
|
+
- `COURIER_AUTH_TOKEN`
|
30
|
+
- Base URL parameter (with default of api.courier.com)
|
31
|
+
- ENV variable `COURIER_BASE_URL`
|
32
|
+
- Support for Lists API by @jrweingart
|
33
|
+
|
34
|
+
- `POST /send/list` with `client.lists.send` method
|
35
|
+
- `GET /lists` with `client.lists.list` method
|
36
|
+
- `GET /lists/{list_id}` with `client.lists.get` method
|
37
|
+
- `PUT /lists/{list_id}` with `client.lists.put` method
|
38
|
+
- `DELETE /lists/{list_id}` with `client.lists.delete` method
|
39
|
+
- `PUT /lists/{list_id}/restore` with `client.lists.restore` method
|
40
|
+
- `GET /lists/{list_id}/subscriptions` with `client.lists.get_subscriptions` method
|
41
|
+
- `PUT /lists/{list_id}/subscriptions` with `client.lists.put_subscriptions` method
|
42
|
+
- `PUT /lists/{list_id}/subscriptions/{recipient_id}` with `client.lists.subscribe` method
|
43
|
+
- `DELETE /lists/{list_id}/subscriptions/{recipient_id}` with `client.lists.unsubscribe` method
|
44
|
+
|
45
|
+
- Support for Profiles API by @jrweingart
|
46
|
+
|
47
|
+
- `GET /profiles/{recipient_id}` with `client.profiles.get` method
|
48
|
+
- `GET /profiles/{recipient_id}/lists` with `client.profiles.get_subscriptions` method
|
49
|
+
- `PUT /profiles/{recipient_id}` with `client.profiles.replace` and `client.profiles.add` methods
|
50
|
+
- `PATCH /profiles/{recipient_id}` with `client.profiles.patch` method
|
51
|
+
- `POST /profiles/{recipient_id}` with `client.profiles.merge` method
|
52
|
+
|
53
|
+
- Support for Messages API by @jrweingart
|
54
|
+
|
55
|
+
- `GET /messages` with `client.messages.list` method
|
56
|
+
- `GET /messages/{message_id}` with `client.messages.get` method
|
57
|
+
- `GET /messages/{message_id}/history` with `client.messages.get_history` method
|
58
|
+
|
59
|
+
- Support for Events API by @jrweingart
|
60
|
+
|
61
|
+
- `GET /events` with `client.events.list` method
|
62
|
+
- `GET /events/{event_id}` with `client.event.get` method
|
63
|
+
- `PUT /events/{event_id}` with `client.events.replace` and `client.events.add` methods
|
64
|
+
|
65
|
+
- Support for Brands API by @jrweingart
|
66
|
+
- `GET /brands` with `client.brands.list` method
|
67
|
+
- `GET /brands/brand_id` with `client.brands.get` method
|
68
|
+
- `POST /brands` with `client.brands.create` method
|
69
|
+
- `PUT /brands/brand_id` with `client.brands.replace` method
|
70
|
+
- `DELETE /brands/brand_id` with `client.brands.delete` method
|
71
|
+
|
72
|
+
## [v1.0.2] - 2021-01-06
|
73
|
+
|
74
|
+
### Added
|
75
|
+
|
76
|
+
- Minor bug fixes to ensure proper SSL certification by @scarney81
|
77
|
+
|
78
|
+
## [v1.0.1] - 2020-03-04
|
79
|
+
|
80
|
+
### Added
|
81
|
+
|
82
|
+
- Support for Send API by @troy
|
83
|
+
|
84
|
+
## v1.0.0 - 2020-03-03
|
85
|
+
|
86
|
+
Initial release by @troygoode
|
87
|
+
|
88
|
+
[unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.3.0...HEAD
|
89
|
+
[v1.3.0]: https://github.com/trycourier/courier-ruby/compare/v1.2.0...v1.3.0
|
90
|
+
[v1.2.0]: https://github.com/trycourier/courier-ruby/compare/v1.1.0...v1.2.0
|
91
|
+
[v1.1.0]: https://github.com/trycourier/courier-ruby/compare/v1.0.2...v1.1.0
|
92
|
+
[v1.0.2]: https://github.com/trycourier/courier-ruby/compare/v1.0.1...v1.0.2
|
93
|
+
[v1.0.1]: https://github.com/trycourier/courier-ruby/compare/v1.0.0...v1.0.1
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/trycourier/courier-ruby
|
4
|
+
|
5
|
+
## Local development
|
6
|
+
|
7
|
+
- Fork this repository
|
8
|
+
- Clone your fork
|
9
|
+
- Run `bundle install`
|
10
|
+
- Write code!
|
11
|
+
- Test your code using `bundle exec rspec spec`
|
12
|
+
|
13
|
+
## Releasing New Versions
|
14
|
+
|
15
|
+
To publish Courier Ruby to RUBYGEMS.ORG
|
16
|
+
|
17
|
+
- Update the CHANGELOG.md
|
18
|
+
- Bump the package version in `lib/trycourier/version.rb`
|
19
|
+
- Submit a PR to merge changes into main
|
20
|
+
- Create and push a new version tag
|
21
|
+
|
22
|
+
```bash
|
23
|
+
git tag -a v<VERSION> -m v<VERSION>
|
24
|
+
git push origin v<VERSION>
|
25
|
+
```
|
26
|
+
|
27
|
+
- Wait for GitHub Action to test and deploy
|
28
|
+
- Confirm you are able to successfully install the new version by running `gem install trycourier`
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trycourier (1.0.
|
4
|
+
trycourier (1.0.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
addressable (2.7.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
ast (2.4.1)
|
12
|
+
crack (0.4.5)
|
13
|
+
rexml
|
9
14
|
diff-lcs (1.3)
|
15
|
+
hashdiff (1.0.1)
|
16
|
+
parallel (1.20.1)
|
17
|
+
parser (3.0.0.0)
|
18
|
+
ast (~> 2.4.1)
|
19
|
+
public_suffix (4.0.6)
|
20
|
+
rainbow (3.0.0)
|
10
21
|
rake (12.3.3)
|
22
|
+
regexp_parser (2.0.3)
|
23
|
+
rexml (3.2.4)
|
11
24
|
rspec (3.9.0)
|
12
25
|
rspec-core (~> 3.9.0)
|
13
26
|
rspec-expectations (~> 3.9.0)
|
@@ -21,6 +34,29 @@ GEM
|
|
21
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
35
|
rspec-support (~> 3.9.0)
|
23
36
|
rspec-support (3.9.2)
|
37
|
+
rubocop (1.4.2)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 2.7.1.5)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
regexp_parser (>= 1.8)
|
42
|
+
rexml
|
43
|
+
rubocop-ast (>= 1.1.1)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
46
|
+
rubocop-ast (1.4.0)
|
47
|
+
parser (>= 2.7.1.5)
|
48
|
+
rubocop-performance (1.9.1)
|
49
|
+
rubocop (>= 0.90.0, < 2.0)
|
50
|
+
rubocop-ast (>= 0.4.0)
|
51
|
+
ruby-progressbar (1.11.0)
|
52
|
+
standard (0.10.2)
|
53
|
+
rubocop (= 1.4.2)
|
54
|
+
rubocop-performance (= 1.9.1)
|
55
|
+
unicode-display_width (1.7.0)
|
56
|
+
webmock (3.11.0)
|
57
|
+
addressable (>= 2.3.6)
|
58
|
+
crack (>= 0.3.2)
|
59
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
24
60
|
|
25
61
|
PLATFORMS
|
26
62
|
ruby
|
@@ -28,7 +64,9 @@ PLATFORMS
|
|
28
64
|
DEPENDENCIES
|
29
65
|
rake (~> 12.0)
|
30
66
|
rspec (~> 3.0)
|
67
|
+
standard
|
31
68
|
trycourier!
|
69
|
+
webmock (>= 1.24.2)
|
32
70
|
|
33
71
|
BUNDLED WITH
|
34
72
|
2.1.4
|
data/README.md
CHANGED
@@ -20,33 +20,386 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
After installing, make sure to include this line at the top of your ruby file:
|
24
|
+
|
23
25
|
```ruby
|
24
26
|
require "trycourier"
|
27
|
+
```
|
28
|
+
|
29
|
+
To create a Courier Ruby client, all you need to do is pass in your authentication information. Then, you can start sending!
|
30
|
+
|
31
|
+
### Using token authentication (most secure)
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var (recommended)
|
35
|
+
```
|
36
|
+
|
37
|
+
### Using basic authentication
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
client = Courier::Client.new(username: "USERNAME", password: "PASSWORD") # or set via COURIER_AUTH_USERNAME and COURIER_AUTH_PASSWORD env vars
|
41
|
+
```
|
42
|
+
|
43
|
+
### Sending a message to an individual recipient
|
25
44
|
|
26
|
-
|
27
|
-
|
28
|
-
|
45
|
+
```ruby
|
46
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
47
|
+
res = client.send({
|
29
48
|
"event" => "your-event-id",
|
30
49
|
"recipient" => "your-recipient-id",
|
31
50
|
|
32
|
-
"profile" => {
|
51
|
+
"profile" => { #optional (include any key-value pairs required by your chosen integrations. This information can also be stored in the recipient's profile in Courier)
|
33
52
|
"email": "example@example.com",
|
34
53
|
"phone_number": "555-867-5309"
|
35
54
|
},
|
36
55
|
|
37
|
-
"data" => {
|
56
|
+
"data" => { #any data you want to pass to a message template
|
38
57
|
"world" => "Ruby!"
|
39
58
|
}
|
40
59
|
})
|
41
|
-
|
42
60
|
puts res.code # the HTTP response code
|
43
|
-
puts res.message_id # if 200, this will be the Courier message ID for this notification
|
44
|
-
rescue Courier::
|
61
|
+
puts res.message_id # if the code is 200, this will be the Courier message ID for this notification
|
62
|
+
rescue Courier::CourierAPIError => re #error sent from from the API
|
45
63
|
puts re.message
|
46
|
-
rescue Courier::InputError => ie
|
47
|
-
puts ie.message
|
48
64
|
end
|
65
|
+
```
|
66
|
+
|
67
|
+
## Advanced Usage
|
68
|
+
|
69
|
+
### Lists
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
require "trycourier"
|
73
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
74
|
+
|
75
|
+
"""
|
76
|
+
Creating a List
|
77
|
+
"""
|
78
|
+
res = client.lists.put(list_id, name)
|
79
|
+
puts res
|
80
|
+
|
81
|
+
"""
|
82
|
+
Example: send a message to a list
|
83
|
+
"""
|
84
|
+
resp = client.lists.send(
|
85
|
+
event: "your-event-id",
|
86
|
+
list: "your.list.id",
|
87
|
+
brand: "your-brand-id", # optional
|
88
|
+
data: {}, # optional
|
89
|
+
override: {} # optional
|
90
|
+
)
|
91
|
+
puts resp['messageId'])
|
92
|
+
|
93
|
+
"""
|
94
|
+
Example: send a message to a list pattern
|
95
|
+
"""
|
96
|
+
resp = client.lists.send(
|
97
|
+
event: "your-event-id",
|
98
|
+
pattern: "your.list.*", #PATTERN (will send to all list ids that start with "your.list.")
|
99
|
+
brand: "your-brand-id", # optional
|
100
|
+
data: {}, # optional
|
101
|
+
override: {} # optional
|
102
|
+
)
|
103
|
+
puts resp['messageId'])
|
104
|
+
|
105
|
+
"""
|
106
|
+
Example: get all lists
|
107
|
+
"""
|
108
|
+
resp = client.lists.list(
|
109
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
|
110
|
+
)
|
111
|
+
puts resp
|
112
|
+
|
113
|
+
"""
|
114
|
+
Example: get a specific list
|
115
|
+
"""
|
116
|
+
resp = client.lists.get(list_id: "your-list-id")
|
117
|
+
puts resp
|
118
|
+
|
119
|
+
|
120
|
+
"""
|
121
|
+
Example: delete a list
|
122
|
+
"""
|
123
|
+
client.lists.delete(list_id: "your-list-id")
|
124
|
+
|
125
|
+
"""
|
126
|
+
Example: restore a list
|
127
|
+
"""
|
128
|
+
client.lists.restore(list_id: "your-list-id")
|
129
|
+
|
130
|
+
"""
|
131
|
+
Example: get a list's subscribptions
|
132
|
+
"""
|
133
|
+
resp = client.lists.get_subscriptions(list_id: "your-list-id",
|
134
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
|
135
|
+
)
|
136
|
+
puts resp
|
137
|
+
|
138
|
+
"""
|
139
|
+
Example: replace many recipients to a new or existing list
|
140
|
+
"""
|
141
|
+
client.lists.put_subscriptions(list_id: "your-list-id", recipients: [
|
142
|
+
"RECIPIENT_ID_1",
|
143
|
+
"RECIPIENT_ID_2"
|
144
|
+
])
|
145
|
+
|
146
|
+
"""
|
147
|
+
Example: Example: subscribe single recipient to a new or existing list
|
148
|
+
"""
|
149
|
+
client.lists.subscribe(list_id: "your-list-id", recipient_id: "your-recipient-id")
|
150
|
+
|
151
|
+
"""
|
152
|
+
Example: unsubscribe recipient from list
|
153
|
+
"""
|
154
|
+
client.lists.unsubscribe(list_id: "your-list-id", recipient_id: "your-recipient-id")
|
155
|
+
```
|
156
|
+
|
157
|
+
### Profiles
|
158
|
+
|
159
|
+
```Ruby
|
160
|
+
"""
|
161
|
+
Example: create a recipient's profile
|
162
|
+
"""
|
163
|
+
resp = client.profiles.add(
|
164
|
+
recipient_id: "your-recipient-id",
|
165
|
+
profile: {
|
166
|
+
"email" => "example@example.com",
|
167
|
+
"name" => "Example Name"
|
168
|
+
}
|
169
|
+
)
|
49
170
|
|
171
|
+
"""
|
172
|
+
Example: replace or create a recipient's profile
|
173
|
+
"""
|
174
|
+
resp = client.profiles.replace(
|
175
|
+
recipient_id: "your-recipient-id",
|
176
|
+
profile: {
|
177
|
+
"email" => "example@example.com"
|
178
|
+
}
|
179
|
+
)
|
180
|
+
puts resp['status']
|
181
|
+
|
182
|
+
"""
|
183
|
+
Example: merge or create a recipient's profile
|
184
|
+
"""
|
185
|
+
resp = client.profiles.merge(
|
186
|
+
recipient_id: "your-recipient-id",
|
187
|
+
profile: {
|
188
|
+
"phone_number" => "+15555555555"
|
189
|
+
}
|
190
|
+
)
|
191
|
+
puts resp['status']
|
192
|
+
|
193
|
+
"""
|
194
|
+
Example: get the subscribed lists of a recipient
|
195
|
+
"""
|
196
|
+
resp = client.profiles.get_subscriptions(
|
197
|
+
recipient_id: "your-recipient-id",
|
198
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA" #optional
|
199
|
+
)
|
200
|
+
puts resp
|
201
|
+
|
202
|
+
"""
|
203
|
+
Example: edit the contents of a recipient's profile with a patch operation
|
204
|
+
(follows JSON Patch conventions: RFC 6902).
|
205
|
+
"""
|
206
|
+
resp = client.profiles.patch(
|
207
|
+
recipient_id: "your-recipient-id",
|
208
|
+
operations: [
|
209
|
+
{
|
210
|
+
"op" => "add", #operation 1: add this email to profile
|
211
|
+
"path" => "/parent",
|
212
|
+
"value" => "example@example.com"
|
213
|
+
}
|
214
|
+
{
|
215
|
+
"op" => "replace", #operation 2: update with new email
|
216
|
+
"path" => "/parent",
|
217
|
+
"value" => "jane@doe.com"
|
218
|
+
}
|
219
|
+
{
|
220
|
+
"op" => "copy", #operation 3: copy that email to /emergency_contact
|
221
|
+
"from" => "/parent",
|
222
|
+
"path" => "/emergency_contact"
|
223
|
+
}
|
224
|
+
...
|
225
|
+
]
|
226
|
+
)
|
227
|
+
puts resp
|
228
|
+
|
229
|
+
|
230
|
+
"""
|
231
|
+
Example: get a recipient's profile
|
232
|
+
"""
|
233
|
+
resp = client.profiles.get(recipient_id: "your-recipient-id")
|
234
|
+
puts resp
|
235
|
+
```
|
236
|
+
|
237
|
+
### Messages
|
238
|
+
|
239
|
+
```Ruby
|
240
|
+
"""
|
241
|
+
Example: fetch the statuses of messages you've previously sent.
|
242
|
+
"""
|
243
|
+
resp = client.messages.list(
|
244
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
|
245
|
+
event: "your-event-id", # optional
|
246
|
+
list: "your-list-id", #optional
|
247
|
+
message_id: "your-message-id" #optional
|
248
|
+
notification: ["message-status-1", "message-status-2",...] #optional
|
249
|
+
recipient: "recipient-id" # optional
|
250
|
+
)
|
251
|
+
puts resp
|
252
|
+
|
253
|
+
"""
|
254
|
+
Example: fetch the status of a message you've previously sent
|
255
|
+
"""
|
256
|
+
resp = client.messages.get(message_id: "your-message-id")
|
257
|
+
puts resp
|
258
|
+
|
259
|
+
"""
|
260
|
+
Example: fetch the array of events of a message you've previously sent.
|
261
|
+
"""
|
262
|
+
resp = client.messages.get_history(
|
263
|
+
message_id: "your-message-id",
|
264
|
+
type: "list-type" #optional ("FILTERED", "RENDERED", "MAPPED", "PROFILE_LOADED")
|
265
|
+
)
|
266
|
+
puts resp
|
267
|
+
```
|
268
|
+
|
269
|
+
### Events
|
270
|
+
|
271
|
+
```Ruby
|
272
|
+
"""
|
273
|
+
Example: fetch the list of events
|
274
|
+
"""
|
275
|
+
resp = client.events.list
|
276
|
+
puts resp
|
277
|
+
|
278
|
+
"""
|
279
|
+
Example: fetch a specific event by event ID
|
280
|
+
"""
|
281
|
+
resp = client.events.get(event_id: "your-event-id")
|
282
|
+
puts resp
|
283
|
+
|
284
|
+
"""
|
285
|
+
Example: create or replace an event
|
286
|
+
"""
|
287
|
+
resp = client.events.replace(
|
288
|
+
event_id: "your-event-id",
|
289
|
+
notification_id: "notification_id",
|
290
|
+
type: "notificaton" ## optional, defaults to notification
|
291
|
+
)
|
292
|
+
puts resp
|
293
|
+
|
294
|
+
"""
|
295
|
+
Example: get all brands
|
296
|
+
"""
|
297
|
+
resp = client.brands.list(
|
298
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
|
299
|
+
)
|
300
|
+
puts resp
|
301
|
+
|
302
|
+
"""
|
303
|
+
Example: get a specific brand
|
304
|
+
"""
|
305
|
+
resp = client.brands.get(brand_id: "brand_id")
|
306
|
+
puts resp
|
307
|
+
|
308
|
+
"""
|
309
|
+
Example: create a brand
|
310
|
+
"""
|
311
|
+
resp = client.brands.create(
|
312
|
+
name: "brand-name",
|
313
|
+
settings: {
|
314
|
+
"color" => {
|
315
|
+
"primary" => "#0000FF",
|
316
|
+
"secondary" => "#FF0000",
|
317
|
+
"tertiary" => "#00FF00"
|
318
|
+
}
|
319
|
+
},
|
320
|
+
id: "my-brand-id", #optional
|
321
|
+
snippets: {}, #optional
|
322
|
+
idempotency_key: "my-idemp-key", #optional
|
323
|
+
)
|
324
|
+
puts resp
|
325
|
+
|
326
|
+
"""
|
327
|
+
Example: replace a brand
|
328
|
+
"""
|
329
|
+
resp = client.brands.replace(
|
330
|
+
brand_id: "your-brand-id",
|
331
|
+
name: "brand-name",
|
332
|
+
settings: {}
|
333
|
+
"color" => {
|
334
|
+
"primary" => "#FF0000",
|
335
|
+
"secondary" => "#00FF00",
|
336
|
+
"tertiary" => "#0000FF"
|
337
|
+
}
|
338
|
+
},
|
339
|
+
snippets: {} #optional
|
340
|
+
)
|
341
|
+
puts resp
|
342
|
+
|
343
|
+
"""
|
344
|
+
Example: delete a brand
|
345
|
+
"""
|
346
|
+
resp = client.brands.delete(brand_id: "your-brand-id")
|
347
|
+
puts resp
|
348
|
+
```
|
349
|
+
|
350
|
+
### Automations
|
351
|
+
|
352
|
+
````Ruby
|
353
|
+
"""
|
354
|
+
Example: invoke ad-hoc automation
|
355
|
+
"""
|
356
|
+
steps = [
|
357
|
+
{
|
358
|
+
"action" => "send"
|
359
|
+
}
|
360
|
+
]
|
361
|
+
automation = {
|
362
|
+
"steps" => steps
|
363
|
+
}
|
364
|
+
|
365
|
+
resp = client.automations.invoke(
|
366
|
+
automation: automation,
|
367
|
+
brand: "your-brand-id", # optional
|
368
|
+
data: {}, # optional
|
369
|
+
profile: {
|
370
|
+
"email" => "example@example.com",
|
371
|
+
}, # optional
|
372
|
+
recipient: "your-recipient-id", # optional
|
373
|
+
template: "your-notification-template-id" # optional
|
374
|
+
)
|
375
|
+
puts resp['runId']
|
376
|
+
|
377
|
+
"""
|
378
|
+
Example: invoke automation template
|
379
|
+
"""
|
380
|
+
resp = client.automations.invoke_template(
|
381
|
+
template_id: "your-automation-template-id",
|
382
|
+
brand: "your-brand-id", # optional
|
383
|
+
data: {}, # optional
|
384
|
+
profile: {
|
385
|
+
"email" => "example@example.com",
|
386
|
+
}, # optional
|
387
|
+
recipient: "your-recipient-id", # optional
|
388
|
+
template: "your-notification-template-id" # optional
|
389
|
+
)
|
390
|
+
puts resp['runId']
|
391
|
+
|
392
|
+
### Notes on input and errors
|
393
|
+
With the exception of passing an auth token to create a client, and ```client.send(body)```, every parameter (optional or required) is sent using keyword arguments.
|
394
|
+
In the case of ```client.send(body)```, if the hash does not have the required components, it will throw an InputError exception, which can be caught with rescue blocks:
|
395
|
+
```ruby
|
396
|
+
rescue InputError
|
397
|
+
````
|
398
|
+
|
399
|
+
Any other errors from the API are thrown as a CourierAPIError. Catch these errors by putting this after your method calls:
|
400
|
+
|
401
|
+
```ruby
|
402
|
+
rescue CourierAPIError
|
50
403
|
```
|
51
404
|
|
52
405
|
## Development
|
@@ -57,7 +410,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
57
410
|
|
58
411
|
## Contributing
|
59
412
|
|
60
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
413
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/trycourier/courier-ruby.
|
61
414
|
|
62
415
|
## License
|
63
416
|
|