trycourier 1.0.2 → 1.4.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 +51 -0
- data/CHANGELOG.md +100 -0
- data/CONTRIBUTING.md +28 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +52 -14
- data/README.md +381 -9
- 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 +39 -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 +80 -0
- data/lib/trycourier/version.rb +1 -1
- data/lib/trycourier.rb +94 -27
- 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: 2e2e7e6f4ad2900f3ad0d118062208c74492851e96976da6795c6309c95ad9ea
|
4
|
+
data.tar.gz: ce78409870df6608de59bc5ea4a628732b09f8d3ec7b304202f1721d07ff5836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 060ff6e98ab2a50557b9e54cf2e1fe2f13d02a4569e335f4ffe31c7bd8fa55c8bbcaef7df686c19c9c98ae0c032e024ba6bc705242bc4df5f26bd9c780174538
|
7
|
+
data.tar.gz: fd9c70f99624a1d82e3a0c6825b17cea6526a0d8c46e0a221c8740514e366851ba59854454919f723cd8a3b205ae8800462fe8965fe05aab9fb2dafe667b0333
|
@@ -0,0 +1,51 @@
|
|
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
|
+
strategy:
|
16
|
+
matrix:
|
17
|
+
ruby-version: ['2.7', '3.0', '3.1', 'head']
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby-version }}
|
25
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
26
|
+
- name: Run tests
|
27
|
+
# Skipping rubocop for now
|
28
|
+
# run: bundle exec rake
|
29
|
+
run: bundle exec rspec spec
|
30
|
+
build:
|
31
|
+
name: Build + Publish
|
32
|
+
needs: test
|
33
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
34
|
+
runs-on: ubuntu-latest
|
35
|
+
|
36
|
+
steps:
|
37
|
+
- uses: actions/checkout@v2
|
38
|
+
- name: Set up Ruby
|
39
|
+
uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
ruby-version: 2.7
|
42
|
+
- name: Publish to RubyGems
|
43
|
+
run: |
|
44
|
+
mkdir -p $HOME/.gem
|
45
|
+
touch $HOME/.gem/credentials
|
46
|
+
chmod 0600 $HOME/.gem/credentials
|
47
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
48
|
+
gem build *.gemspec
|
49
|
+
gem push *.gem
|
50
|
+
env:
|
51
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,100 @@
|
|
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.4.0] - 2022-01-31
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Support for enhanced Send API by @tk26
|
13
|
+
|
14
|
+
## [v1.3.0] - 2022-01-26
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Support for Bulk API by @tk26
|
19
|
+
|
20
|
+
## [v1.2.0] - 2021-04-08
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- Support for [Automation API](https://docs.courier.com/reference/automation-api) by @tk26
|
25
|
+
- `POST /automations/invoke` with `client.automations.invoke` method
|
26
|
+
- `POST /automations/{template_id}/invoke` with `client.automations.invoke_template` method
|
27
|
+
|
28
|
+
## [v1.1.0] - 2021-01-26
|
29
|
+
|
30
|
+
### Added
|
31
|
+
|
32
|
+
- Support for Basic Auth
|
33
|
+
- ENV variables `COURIER_AUTH_USERNAME` and `COURIER_AUTH_PASSWORD` OR set with params
|
34
|
+
- Token Auth using ENV variables
|
35
|
+
- `COURIER_AUTH_TOKEN`
|
36
|
+
- Base URL parameter (with default of api.courier.com)
|
37
|
+
- ENV variable `COURIER_BASE_URL`
|
38
|
+
- Support for Lists API by @jrweingart
|
39
|
+
|
40
|
+
- `POST /send/list` with `client.lists.send` method
|
41
|
+
- `GET /lists` with `client.lists.list` method
|
42
|
+
- `GET /lists/{list_id}` with `client.lists.get` method
|
43
|
+
- `PUT /lists/{list_id}` with `client.lists.put` method
|
44
|
+
- `DELETE /lists/{list_id}` with `client.lists.delete` method
|
45
|
+
- `PUT /lists/{list_id}/restore` with `client.lists.restore` method
|
46
|
+
- `GET /lists/{list_id}/subscriptions` with `client.lists.get_subscriptions` method
|
47
|
+
- `PUT /lists/{list_id}/subscriptions` with `client.lists.put_subscriptions` method
|
48
|
+
- `PUT /lists/{list_id}/subscriptions/{recipient_id}` with `client.lists.subscribe` method
|
49
|
+
- `DELETE /lists/{list_id}/subscriptions/{recipient_id}` with `client.lists.unsubscribe` method
|
50
|
+
|
51
|
+
- Support for Profiles API by @jrweingart
|
52
|
+
|
53
|
+
- `GET /profiles/{recipient_id}` with `client.profiles.get` method
|
54
|
+
- `GET /profiles/{recipient_id}/lists` with `client.profiles.get_subscriptions` method
|
55
|
+
- `PUT /profiles/{recipient_id}` with `client.profiles.replace` and `client.profiles.add` methods
|
56
|
+
- `PATCH /profiles/{recipient_id}` with `client.profiles.patch` method
|
57
|
+
- `POST /profiles/{recipient_id}` with `client.profiles.merge` method
|
58
|
+
|
59
|
+
- Support for Messages API by @jrweingart
|
60
|
+
|
61
|
+
- `GET /messages` with `client.messages.list` method
|
62
|
+
- `GET /messages/{message_id}` with `client.messages.get` method
|
63
|
+
- `GET /messages/{message_id}/history` with `client.messages.get_history` method
|
64
|
+
|
65
|
+
- Support for Events API by @jrweingart
|
66
|
+
|
67
|
+
- `GET /events` with `client.events.list` method
|
68
|
+
- `GET /events/{event_id}` with `client.event.get` method
|
69
|
+
- `PUT /events/{event_id}` with `client.events.replace` and `client.events.add` methods
|
70
|
+
|
71
|
+
- Support for Brands API by @jrweingart
|
72
|
+
- `GET /brands` with `client.brands.list` method
|
73
|
+
- `GET /brands/brand_id` with `client.brands.get` method
|
74
|
+
- `POST /brands` with `client.brands.create` method
|
75
|
+
- `PUT /brands/brand_id` with `client.brands.replace` method
|
76
|
+
- `DELETE /brands/brand_id` with `client.brands.delete` method
|
77
|
+
|
78
|
+
## [v1.0.2] - 2021-01-06
|
79
|
+
|
80
|
+
### Added
|
81
|
+
|
82
|
+
- Minor bug fixes to ensure proper SSL certification by @scarney81
|
83
|
+
|
84
|
+
## [v1.0.1] - 2020-03-04
|
85
|
+
|
86
|
+
### Added
|
87
|
+
|
88
|
+
- Support for Send API by @troy
|
89
|
+
|
90
|
+
## v1.0.0 - 2020-03-03
|
91
|
+
|
92
|
+
Initial release by @troygoode
|
93
|
+
|
94
|
+
[unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.4.0...HEAD
|
95
|
+
[v1.4.0]: https://github.com/trycourier/courier-ruby/compare/v1.3.0...v1.4.0
|
96
|
+
[v1.3.0]: https://github.com/trycourier/courier-ruby/compare/v1.2.0...v1.3.0
|
97
|
+
[v1.2.0]: https://github.com/trycourier/courier-ruby/compare/v1.1.0...v1.2.0
|
98
|
+
[v1.1.0]: https://github.com/trycourier/courier-ruby/compare/v1.0.2...v1.1.0
|
99
|
+
[v1.0.2]: https://github.com/trycourier/courier-ruby/compare/v1.0.1...v1.0.2
|
100
|
+
[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,26 +1,62 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trycourier (1.0
|
4
|
+
trycourier (1.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
9
|
+
addressable (2.8.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
ast (2.4.2)
|
12
|
+
crack (0.4.5)
|
13
|
+
rexml
|
14
|
+
diff-lcs (1.5.0)
|
15
|
+
hashdiff (1.0.1)
|
16
|
+
parallel (1.21.0)
|
17
|
+
parser (3.1.0.0)
|
18
|
+
ast (~> 2.4.1)
|
19
|
+
public_suffix (4.0.6)
|
20
|
+
rainbow (3.1.1)
|
10
21
|
rake (12.3.3)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rspec-
|
15
|
-
|
16
|
-
rspec-
|
17
|
-
rspec-
|
22
|
+
regexp_parser (2.2.0)
|
23
|
+
rexml (3.2.5)
|
24
|
+
rspec (3.10.0)
|
25
|
+
rspec-core (~> 3.10.0)
|
26
|
+
rspec-expectations (~> 3.10.0)
|
27
|
+
rspec-mocks (~> 3.10.0)
|
28
|
+
rspec-core (3.10.2)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-expectations (3.10.2)
|
18
31
|
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.
|
20
|
-
rspec-mocks (3.
|
32
|
+
rspec-support (~> 3.10.0)
|
33
|
+
rspec-mocks (3.10.2)
|
21
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-support (3.
|
35
|
+
rspec-support (~> 3.10.0)
|
36
|
+
rspec-support (3.10.3)
|
37
|
+
rubocop (1.25.0)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 3.1.0.0)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
regexp_parser (>= 1.8, < 3.0)
|
42
|
+
rexml
|
43
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
46
|
+
rubocop-ast (1.15.1)
|
47
|
+
parser (>= 3.0.1.1)
|
48
|
+
rubocop-performance (1.13.2)
|
49
|
+
rubocop (>= 1.7.0, < 2.0)
|
50
|
+
rubocop-ast (>= 0.4.0)
|
51
|
+
ruby-progressbar (1.11.0)
|
52
|
+
standard (1.7.0)
|
53
|
+
rubocop (= 1.25.0)
|
54
|
+
rubocop-performance (= 1.13.2)
|
55
|
+
unicode-display_width (2.1.0)
|
56
|
+
webmock (3.14.0)
|
57
|
+
addressable (>= 2.8.0)
|
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
|
-
2.
|
72
|
+
2.2.15
|
data/README.md
CHANGED
@@ -20,33 +20,405 @@ 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
|
})
|
60
|
+
puts res.code # the HTTP response code
|
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
|
63
|
+
puts re.message
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
## Advanced Usage
|
41
68
|
|
69
|
+
### Send API enhanced
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
73
|
+
res = client.send_message({
|
74
|
+
message => {
|
75
|
+
template => "my-template",
|
76
|
+
to => {
|
77
|
+
email => "foo@bar.com"
|
78
|
+
}
|
79
|
+
}
|
80
|
+
})
|
42
81
|
puts res.code # the HTTP response code
|
43
|
-
puts res.
|
44
|
-
rescue Courier::
|
82
|
+
puts res.request_id # if the code is 202, this will be the Courier request ID for this message
|
83
|
+
rescue Courier::CourierAPIError => re #error sent from from the API
|
45
84
|
puts re.message
|
46
|
-
rescue Courier::InputError => ie
|
47
|
-
puts ie.message
|
48
85
|
end
|
86
|
+
```
|
87
|
+
|
88
|
+
### Lists
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
require "trycourier"
|
92
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
93
|
+
|
94
|
+
"""
|
95
|
+
Creating a List
|
96
|
+
"""
|
97
|
+
res = client.lists.put(list_id, name)
|
98
|
+
puts res
|
99
|
+
|
100
|
+
"""
|
101
|
+
Example: send a message to a list
|
102
|
+
"""
|
103
|
+
resp = client.lists.send(
|
104
|
+
event: "your-event-id",
|
105
|
+
list: "your.list.id",
|
106
|
+
brand: "your-brand-id", # optional
|
107
|
+
data: {}, # optional
|
108
|
+
override: {} # optional
|
109
|
+
)
|
110
|
+
puts resp['messageId'])
|
111
|
+
|
112
|
+
"""
|
113
|
+
Example: send a message to a list pattern
|
114
|
+
"""
|
115
|
+
resp = client.lists.send(
|
116
|
+
event: "your-event-id",
|
117
|
+
pattern: "your.list.*", #PATTERN (will send to all list ids that start with "your.list.")
|
118
|
+
brand: "your-brand-id", # optional
|
119
|
+
data: {}, # optional
|
120
|
+
override: {} # optional
|
121
|
+
)
|
122
|
+
puts resp['messageId'])
|
49
123
|
|
124
|
+
"""
|
125
|
+
Example: get all lists
|
126
|
+
"""
|
127
|
+
resp = client.lists.list(
|
128
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
|
129
|
+
)
|
130
|
+
puts resp
|
131
|
+
|
132
|
+
"""
|
133
|
+
Example: get a specific list
|
134
|
+
"""
|
135
|
+
resp = client.lists.get(list_id: "your-list-id")
|
136
|
+
puts resp
|
137
|
+
|
138
|
+
|
139
|
+
"""
|
140
|
+
Example: delete a list
|
141
|
+
"""
|
142
|
+
client.lists.delete(list_id: "your-list-id")
|
143
|
+
|
144
|
+
"""
|
145
|
+
Example: restore a list
|
146
|
+
"""
|
147
|
+
client.lists.restore(list_id: "your-list-id")
|
148
|
+
|
149
|
+
"""
|
150
|
+
Example: get a list's subscribptions
|
151
|
+
"""
|
152
|
+
resp = client.lists.get_subscriptions(list_id: "your-list-id",
|
153
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
|
154
|
+
)
|
155
|
+
puts resp
|
156
|
+
|
157
|
+
"""
|
158
|
+
Example: replace many recipients to a new or existing list
|
159
|
+
"""
|
160
|
+
client.lists.put_subscriptions(list_id: "your-list-id", recipients: [
|
161
|
+
"RECIPIENT_ID_1",
|
162
|
+
"RECIPIENT_ID_2"
|
163
|
+
])
|
164
|
+
|
165
|
+
"""
|
166
|
+
Example: Example: subscribe single recipient to a new or existing list
|
167
|
+
"""
|
168
|
+
client.lists.subscribe(list_id: "your-list-id", recipient_id: "your-recipient-id")
|
169
|
+
|
170
|
+
"""
|
171
|
+
Example: unsubscribe recipient from list
|
172
|
+
"""
|
173
|
+
client.lists.unsubscribe(list_id: "your-list-id", recipient_id: "your-recipient-id")
|
174
|
+
```
|
175
|
+
|
176
|
+
### Profiles
|
177
|
+
|
178
|
+
```Ruby
|
179
|
+
"""
|
180
|
+
Example: create a recipient's profile
|
181
|
+
"""
|
182
|
+
resp = client.profiles.add(
|
183
|
+
recipient_id: "your-recipient-id",
|
184
|
+
profile: {
|
185
|
+
"email" => "example@example.com",
|
186
|
+
"name" => "Example Name"
|
187
|
+
}
|
188
|
+
)
|
189
|
+
|
190
|
+
"""
|
191
|
+
Example: replace or create a recipient's profile
|
192
|
+
"""
|
193
|
+
resp = client.profiles.replace(
|
194
|
+
recipient_id: "your-recipient-id",
|
195
|
+
profile: {
|
196
|
+
"email" => "example@example.com"
|
197
|
+
}
|
198
|
+
)
|
199
|
+
puts resp['status']
|
200
|
+
|
201
|
+
"""
|
202
|
+
Example: merge or create a recipient's profile
|
203
|
+
"""
|
204
|
+
resp = client.profiles.merge(
|
205
|
+
recipient_id: "your-recipient-id",
|
206
|
+
profile: {
|
207
|
+
"phone_number" => "+15555555555"
|
208
|
+
}
|
209
|
+
)
|
210
|
+
puts resp['status']
|
211
|
+
|
212
|
+
"""
|
213
|
+
Example: get the subscribed lists of a recipient
|
214
|
+
"""
|
215
|
+
resp = client.profiles.get_subscriptions(
|
216
|
+
recipient_id: "your-recipient-id",
|
217
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA" #optional
|
218
|
+
)
|
219
|
+
puts resp
|
220
|
+
|
221
|
+
"""
|
222
|
+
Example: edit the contents of a recipient's profile with a patch operation
|
223
|
+
(follows JSON Patch conventions: RFC 6902).
|
224
|
+
"""
|
225
|
+
resp = client.profiles.patch(
|
226
|
+
recipient_id: "your-recipient-id",
|
227
|
+
operations: [
|
228
|
+
{
|
229
|
+
"op" => "add", #operation 1: add this email to profile
|
230
|
+
"path" => "/parent",
|
231
|
+
"value" => "example@example.com"
|
232
|
+
}
|
233
|
+
{
|
234
|
+
"op" => "replace", #operation 2: update with new email
|
235
|
+
"path" => "/parent",
|
236
|
+
"value" => "jane@doe.com"
|
237
|
+
}
|
238
|
+
{
|
239
|
+
"op" => "copy", #operation 3: copy that email to /emergency_contact
|
240
|
+
"from" => "/parent",
|
241
|
+
"path" => "/emergency_contact"
|
242
|
+
}
|
243
|
+
...
|
244
|
+
]
|
245
|
+
)
|
246
|
+
puts resp
|
247
|
+
|
248
|
+
|
249
|
+
"""
|
250
|
+
Example: get a recipient's profile
|
251
|
+
"""
|
252
|
+
resp = client.profiles.get(recipient_id: "your-recipient-id")
|
253
|
+
puts resp
|
254
|
+
```
|
255
|
+
|
256
|
+
### Messages
|
257
|
+
|
258
|
+
```Ruby
|
259
|
+
"""
|
260
|
+
Example: fetch the statuses of messages you've previously sent.
|
261
|
+
"""
|
262
|
+
resp = client.messages.list(
|
263
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
|
264
|
+
event: "your-event-id", # optional
|
265
|
+
list: "your-list-id", #optional
|
266
|
+
message_id: "your-message-id" #optional
|
267
|
+
notification: ["message-status-1", "message-status-2",...] #optional
|
268
|
+
recipient: "recipient-id" # optional
|
269
|
+
)
|
270
|
+
puts resp
|
271
|
+
|
272
|
+
"""
|
273
|
+
Example: fetch the status of a message you've previously sent
|
274
|
+
"""
|
275
|
+
resp = client.messages.get(message_id: "your-message-id")
|
276
|
+
puts resp
|
277
|
+
|
278
|
+
"""
|
279
|
+
Example: fetch the array of events of a message you've previously sent.
|
280
|
+
"""
|
281
|
+
resp = client.messages.get_history(
|
282
|
+
message_id: "your-message-id",
|
283
|
+
type: "list-type" #optional ("FILTERED", "RENDERED", "MAPPED", "PROFILE_LOADED")
|
284
|
+
)
|
285
|
+
puts resp
|
286
|
+
```
|
287
|
+
|
288
|
+
### Events
|
289
|
+
|
290
|
+
```Ruby
|
291
|
+
"""
|
292
|
+
Example: fetch the list of events
|
293
|
+
"""
|
294
|
+
resp = client.events.list
|
295
|
+
puts resp
|
296
|
+
|
297
|
+
"""
|
298
|
+
Example: fetch a specific event by event ID
|
299
|
+
"""
|
300
|
+
resp = client.events.get(event_id: "your-event-id")
|
301
|
+
puts resp
|
302
|
+
|
303
|
+
"""
|
304
|
+
Example: create or replace an event
|
305
|
+
"""
|
306
|
+
resp = client.events.replace(
|
307
|
+
event_id: "your-event-id",
|
308
|
+
notification_id: "notification_id",
|
309
|
+
type: "notificaton" ## optional, defaults to notification
|
310
|
+
)
|
311
|
+
puts resp
|
312
|
+
|
313
|
+
"""
|
314
|
+
Example: get all brands
|
315
|
+
"""
|
316
|
+
resp = client.brands.list(
|
317
|
+
cursor: "MTU4OTQ5NTI1ODY4NywxLTVlYmRjNWRhLTEwODZlYWFjMWRmMjEwMTNjM2I0ZjVhMA", # optional
|
318
|
+
)
|
319
|
+
puts resp
|
320
|
+
|
321
|
+
"""
|
322
|
+
Example: get a specific brand
|
323
|
+
"""
|
324
|
+
resp = client.brands.get(brand_id: "brand_id")
|
325
|
+
puts resp
|
326
|
+
|
327
|
+
"""
|
328
|
+
Example: create a brand
|
329
|
+
"""
|
330
|
+
resp = client.brands.create(
|
331
|
+
name: "brand-name",
|
332
|
+
settings: {
|
333
|
+
"color" => {
|
334
|
+
"primary" => "#0000FF",
|
335
|
+
"secondary" => "#FF0000",
|
336
|
+
"tertiary" => "#00FF00"
|
337
|
+
}
|
338
|
+
},
|
339
|
+
id: "my-brand-id", #optional
|
340
|
+
snippets: {}, #optional
|
341
|
+
idempotency_key: "my-idemp-key", #optional
|
342
|
+
)
|
343
|
+
puts resp
|
344
|
+
|
345
|
+
"""
|
346
|
+
Example: replace a brand
|
347
|
+
"""
|
348
|
+
resp = client.brands.replace(
|
349
|
+
brand_id: "your-brand-id",
|
350
|
+
name: "brand-name",
|
351
|
+
settings: {}
|
352
|
+
"color" => {
|
353
|
+
"primary" => "#FF0000",
|
354
|
+
"secondary" => "#00FF00",
|
355
|
+
"tertiary" => "#0000FF"
|
356
|
+
}
|
357
|
+
},
|
358
|
+
snippets: {} #optional
|
359
|
+
)
|
360
|
+
puts resp
|
361
|
+
|
362
|
+
"""
|
363
|
+
Example: delete a brand
|
364
|
+
"""
|
365
|
+
resp = client.brands.delete(brand_id: "your-brand-id")
|
366
|
+
puts resp
|
367
|
+
```
|
368
|
+
|
369
|
+
### Automations
|
370
|
+
|
371
|
+
````Ruby
|
372
|
+
"""
|
373
|
+
Example: invoke ad-hoc automation
|
374
|
+
"""
|
375
|
+
steps = [
|
376
|
+
{
|
377
|
+
"action" => "send"
|
378
|
+
}
|
379
|
+
]
|
380
|
+
automation = {
|
381
|
+
"steps" => steps
|
382
|
+
}
|
383
|
+
|
384
|
+
resp = client.automations.invoke(
|
385
|
+
automation: automation,
|
386
|
+
brand: "your-brand-id", # optional
|
387
|
+
data: {}, # optional
|
388
|
+
profile: {
|
389
|
+
"email" => "example@example.com",
|
390
|
+
}, # optional
|
391
|
+
recipient: "your-recipient-id", # optional
|
392
|
+
template: "your-notification-template-id" # optional
|
393
|
+
)
|
394
|
+
puts resp['runId']
|
395
|
+
|
396
|
+
"""
|
397
|
+
Example: invoke automation template
|
398
|
+
"""
|
399
|
+
resp = client.automations.invoke_template(
|
400
|
+
template_id: "your-automation-template-id",
|
401
|
+
brand: "your-brand-id", # optional
|
402
|
+
data: {}, # optional
|
403
|
+
profile: {
|
404
|
+
"email" => "example@example.com",
|
405
|
+
}, # optional
|
406
|
+
recipient: "your-recipient-id", # optional
|
407
|
+
template: "your-notification-template-id" # optional
|
408
|
+
)
|
409
|
+
puts resp['runId']
|
410
|
+
|
411
|
+
### Notes on input and errors
|
412
|
+
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.
|
413
|
+
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:
|
414
|
+
```ruby
|
415
|
+
rescue InputError
|
416
|
+
````
|
417
|
+
|
418
|
+
Any other errors from the API are thrown as a CourierAPIError. Catch these errors by putting this after your method calls:
|
419
|
+
|
420
|
+
```ruby
|
421
|
+
rescue CourierAPIError
|
50
422
|
```
|
51
423
|
|
52
424
|
## Development
|