trycourier 1.3.0 → 1.6.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 +11 -9
- data/CHANGELOG.md +18 -1
- data/Gemfile.lock +36 -36
- data/README.md +193 -0
- data/lib/trycourier/audiences.rb +45 -0
- data/lib/trycourier/audit_events.rb +27 -0
- data/lib/trycourier/bulk.rb +1 -1
- data/lib/trycourier/exceptions.rb +4 -2
- data/lib/trycourier/messages.rb +1 -1
- data/lib/trycourier/session.rb +1 -2
- data/lib/trycourier/version.rb +1 -1
- data/lib/trycourier.rb +46 -5
- data/trycourier.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aa5b8cf9e2e4554e7238b5001707c706bb9e7c8cdceab309fce4ba805601e5a
|
4
|
+
data.tar.gz: 4396885d4f4f0da37c37896653850c74ba434eba8e01c44ba368bc4452892205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec711df626dea24a00a5038f2da814f040499972cbf841e8d747ff841162ff4ed7207b081aae704aa4f7f1740f15bf6d6fc2867d2315d107577a70d7364fc9aa
|
7
|
+
data.tar.gz: 24c12be8b4042da8188d54059395fc849d95ddf1e1c4ac03d1a5f5199a5d6e3f87ee62376fd1b5d383704af592e7767934c58214a8d483f0fbbc739023333d9d
|
@@ -12,14 +12,17 @@ jobs:
|
|
12
12
|
test:
|
13
13
|
runs-on: ubuntu-latest
|
14
14
|
|
15
|
+
strategy:
|
16
|
+
matrix:
|
17
|
+
ruby-version: ['2.7', '3.0', '3.1', 'head']
|
18
|
+
|
15
19
|
steps:
|
16
20
|
- uses: actions/checkout@v2
|
17
|
-
- name: Set up Ruby
|
18
|
-
uses:
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
19
23
|
with:
|
20
|
-
ruby-version:
|
21
|
-
|
22
|
-
run: bundle install
|
24
|
+
ruby-version: ${{ matrix.ruby-version }}
|
25
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
23
26
|
- name: Run tests
|
24
27
|
# Skipping rubocop for now
|
25
28
|
# run: bundle exec rake
|
@@ -32,11 +35,10 @@ jobs:
|
|
32
35
|
|
33
36
|
steps:
|
34
37
|
- uses: actions/checkout@v2
|
35
|
-
- name: Set up Ruby
|
36
|
-
uses:
|
38
|
+
- name: Set up Ruby
|
39
|
+
uses: ruby/setup-ruby@v1
|
37
40
|
with:
|
38
|
-
ruby-version: 2.7
|
39
|
-
|
41
|
+
ruby-version: 2.7
|
40
42
|
- name: Publish to RubyGems
|
41
43
|
run: |
|
42
44
|
mkdir -p $HOME/.gem
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,20 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
|
6
6
|
## [Unreleased][unreleased]
|
7
7
|
|
8
|
+
## [v1.6.0] - 2022-07-25
|
9
|
+
|
10
|
+
- Support for audit events API
|
11
|
+
|
12
|
+
## [v1.5.0] - 2022-03-28
|
13
|
+
|
14
|
+
- Support for audiences API
|
15
|
+
|
16
|
+
## [v1.4.0] - 2022-01-31
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
- Support for enhanced Send API by @tk26
|
21
|
+
|
8
22
|
## [v1.3.0] - 2022-01-26
|
9
23
|
|
10
24
|
### Added
|
@@ -85,7 +99,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
85
99
|
|
86
100
|
Initial release by @troygoode
|
87
101
|
|
88
|
-
[unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.
|
102
|
+
[unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.6.0...HEAD
|
103
|
+
[v1.6.0]: https://github.com/trycourier/courier-ruby/compare/v1.5.0...v1.6.0
|
104
|
+
[v1.5.0]: https://github.com/trycourier/courier-ruby/compare/v1.4.0...v1.5.0
|
105
|
+
[v1.4.0]: https://github.com/trycourier/courier-ruby/compare/v1.3.0...v1.4.0
|
89
106
|
[v1.3.0]: https://github.com/trycourier/courier-ruby/compare/v1.2.0...v1.3.0
|
90
107
|
[v1.2.0]: https://github.com/trycourier/courier-ruby/compare/v1.1.0...v1.2.0
|
91
108
|
[v1.1.0]: https://github.com/trycourier/courier-ruby/compare/v1.0.2...v1.1.0
|
data/Gemfile.lock
CHANGED
@@ -1,60 +1,60 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trycourier (1.0
|
4
|
+
trycourier (1.6.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
addressable (2.
|
9
|
+
addressable (2.8.0)
|
10
10
|
public_suffix (>= 2.0.2, < 5.0)
|
11
|
-
ast (2.4.
|
11
|
+
ast (2.4.2)
|
12
12
|
crack (0.4.5)
|
13
13
|
rexml
|
14
|
-
diff-lcs (1.
|
14
|
+
diff-lcs (1.5.0)
|
15
15
|
hashdiff (1.0.1)
|
16
|
-
parallel (1.
|
17
|
-
parser (3.
|
16
|
+
parallel (1.21.0)
|
17
|
+
parser (3.1.0.0)
|
18
18
|
ast (~> 2.4.1)
|
19
19
|
public_suffix (4.0.6)
|
20
|
-
rainbow (3.
|
20
|
+
rainbow (3.1.1)
|
21
21
|
rake (12.3.3)
|
22
|
-
regexp_parser (2.0
|
23
|
-
rexml (3.2.
|
24
|
-
rspec (3.
|
25
|
-
rspec-core (~> 3.
|
26
|
-
rspec-expectations (~> 3.
|
27
|
-
rspec-mocks (~> 3.
|
28
|
-
rspec-core (3.
|
29
|
-
rspec-support (~> 3.
|
30
|
-
rspec-expectations (3.
|
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)
|
31
31
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
-
rspec-support (~> 3.
|
33
|
-
rspec-mocks (3.
|
32
|
+
rspec-support (~> 3.10.0)
|
33
|
+
rspec-mocks (3.10.2)
|
34
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
-
rspec-support (~> 3.
|
36
|
-
rspec-support (3.
|
37
|
-
rubocop (1.
|
35
|
+
rspec-support (~> 3.10.0)
|
36
|
+
rspec-support (3.10.3)
|
37
|
+
rubocop (1.25.0)
|
38
38
|
parallel (~> 1.10)
|
39
|
-
parser (>=
|
39
|
+
parser (>= 3.1.0.0)
|
40
40
|
rainbow (>= 2.2.2, < 4.0)
|
41
|
-
regexp_parser (>= 1.8)
|
41
|
+
regexp_parser (>= 1.8, < 3.0)
|
42
42
|
rexml
|
43
|
-
rubocop-ast (>= 1.1.
|
43
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
44
44
|
ruby-progressbar (~> 1.7)
|
45
|
-
unicode-display_width (>= 1.4.0, <
|
46
|
-
rubocop-ast (1.
|
47
|
-
parser (>=
|
48
|
-
rubocop-performance (1.
|
49
|
-
rubocop (>=
|
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
50
|
rubocop-ast (>= 0.4.0)
|
51
51
|
ruby-progressbar (1.11.0)
|
52
|
-
standard (
|
53
|
-
rubocop (= 1.
|
54
|
-
rubocop-performance (= 1.
|
55
|
-
unicode-display_width (1.
|
56
|
-
webmock (3.
|
57
|
-
addressable (>= 2.
|
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
58
|
crack (>= 0.3.2)
|
59
59
|
hashdiff (>= 0.4.0, < 2.0.0)
|
60
60
|
|
@@ -69,4 +69,4 @@ DEPENDENCIES
|
|
69
69
|
webmock (>= 1.24.2)
|
70
70
|
|
71
71
|
BUNDLED WITH
|
72
|
-
2.
|
72
|
+
2.2.15
|
data/README.md
CHANGED
@@ -42,6 +42,29 @@ client = Courier::Client.new(username: "USERNAME", password: "PASSWORD") # or se
|
|
42
42
|
|
43
43
|
### Sending a message to an individual recipient
|
44
44
|
|
45
|
+
```ruby
|
46
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
47
|
+
res = client.send_message({
|
48
|
+
"message" => {
|
49
|
+
"to" => {
|
50
|
+
"email" => "foo@bar.com"
|
51
|
+
}
|
52
|
+
"content" => {
|
53
|
+
"title" => "hello {{name}}",
|
54
|
+
"body" => "Welcome to Courier!"
|
55
|
+
},
|
56
|
+
"data" => {
|
57
|
+
"name" => "Ruby"
|
58
|
+
}
|
59
|
+
}
|
60
|
+
})
|
61
|
+
puts res.code # the HTTP response code
|
62
|
+
puts res.request_id # if the code is 202, this will be the Courier request ID for this message
|
63
|
+
rescue Courier::CourierAPIError => re #error sent from from the API
|
64
|
+
puts re.message
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
45
68
|
```ruby
|
46
69
|
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
47
70
|
res = client.send({
|
@@ -64,6 +87,107 @@ rescue Courier::CourierAPIError => re #error sent from from the API
|
|
64
87
|
end
|
65
88
|
```
|
66
89
|
|
90
|
+
### Sending a message to an individual with metadata
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
94
|
+
res = client.send_message({
|
95
|
+
"message" => {
|
96
|
+
"to" => {
|
97
|
+
"email" => "foo@bar.com"
|
98
|
+
}
|
99
|
+
"content" => {
|
100
|
+
"title" => "hello {{name}}",
|
101
|
+
"body" => "Welcome to Courier!"
|
102
|
+
},
|
103
|
+
"data" => {
|
104
|
+
"name" => "Ruby"
|
105
|
+
},
|
106
|
+
"metadata" => {
|
107
|
+
"utm" => {
|
108
|
+
"source" => "Ruby"
|
109
|
+
},
|
110
|
+
"tags" => ["tag-1", "tag-2"],
|
111
|
+
"trace_id" => "feed-me-hungry"
|
112
|
+
}
|
113
|
+
}
|
114
|
+
})
|
115
|
+
puts res.code # the HTTP response code
|
116
|
+
puts res.request_id # if the code is 202, this will be the Courier request ID for this message
|
117
|
+
rescue Courier::CourierAPIError => re #error sent from from the API
|
118
|
+
puts re.message
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
### Sending a message to an individual with granular metadata
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
126
|
+
res = client.send_message({
|
127
|
+
"message" => {
|
128
|
+
"to" => {
|
129
|
+
"email" => "foo@bar.com"
|
130
|
+
},
|
131
|
+
"content" => {
|
132
|
+
"version" => "2020-01-01",
|
133
|
+
"elements" => [
|
134
|
+
{
|
135
|
+
"type" => "text",
|
136
|
+
"content" => "Thanks for signing up, {{name}}"
|
137
|
+
},
|
138
|
+
{
|
139
|
+
"type" => "action",
|
140
|
+
"content" => "Click Me!",
|
141
|
+
"href" => "https://www.example.com"
|
142
|
+
}
|
143
|
+
]
|
144
|
+
},
|
145
|
+
"routing" => {
|
146
|
+
"method" => "all",
|
147
|
+
"channels" => [
|
148
|
+
"email"
|
149
|
+
]
|
150
|
+
},
|
151
|
+
"data" => {
|
152
|
+
"name" => "Ruby"
|
153
|
+
},
|
154
|
+
"metadata" => {
|
155
|
+
"utm" => {
|
156
|
+
"source" => "Ruby"
|
157
|
+
},
|
158
|
+
},
|
159
|
+
"channels" => {
|
160
|
+
"email" => {
|
161
|
+
"routing_method" => "all",
|
162
|
+
"providers" => [
|
163
|
+
"sendgrid",
|
164
|
+
"mailjet"
|
165
|
+
],
|
166
|
+
"metadata" => {
|
167
|
+
"utm" => {
|
168
|
+
"medium" => "email"
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
},
|
173
|
+
"providers" => {
|
174
|
+
"sendgrid" => {
|
175
|
+
"metadata" => {
|
176
|
+
"utm" => {
|
177
|
+
"source" => "sendgrid"
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
})
|
184
|
+
puts res.code # the HTTP response code
|
185
|
+
puts res.request_id # if the code is 202, this will be the Courier request ID for this message
|
186
|
+
rescue Courier::CourierAPIError => re #error sent from from the API
|
187
|
+
puts re.message
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
67
191
|
## Advanced Usage
|
68
192
|
|
69
193
|
### Lists
|
@@ -402,6 +526,71 @@ Any other errors from the API are thrown as a CourierAPIError. Catch these error
|
|
402
526
|
rescue CourierAPIError
|
403
527
|
```
|
404
528
|
|
529
|
+
### Audiences
|
530
|
+
|
531
|
+
List of supported operators for audience filtering: https://www.courier.com/docs/reference/audieces/operators
|
532
|
+
|
533
|
+
```Ruby
|
534
|
+
"""
|
535
|
+
Example: create or update an Audience
|
536
|
+
"""
|
537
|
+
resp = client.audiences.put(
|
538
|
+
audience_id: "your-audience-id",
|
539
|
+
filter: {
|
540
|
+
"operator": "EQ",
|
541
|
+
"value": "en-US",
|
542
|
+
"path": "locale"
|
543
|
+
}
|
544
|
+
)
|
545
|
+
|
546
|
+
"""
|
547
|
+
Example: Get all members of an Audience
|
548
|
+
"""
|
549
|
+
resp = client.audiences.get_audience_members(
|
550
|
+
audience_id: "your-audience-id",
|
551
|
+
cursor: nil
|
552
|
+
)
|
553
|
+
puts resp['status']
|
554
|
+
|
555
|
+
"""
|
556
|
+
Example: Send to an Audience
|
557
|
+
"""
|
558
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
559
|
+
res = client.send_message({
|
560
|
+
"message" => {
|
561
|
+
"to" => {
|
562
|
+
"audience_id" => "your-audience-id"
|
563
|
+
}
|
564
|
+
"content" => {
|
565
|
+
"title" => "hello {{name}}",
|
566
|
+
"body" => "Welcome to Courier!"
|
567
|
+
},
|
568
|
+
"data" => {
|
569
|
+
"name" => "Ruby"
|
570
|
+
}
|
571
|
+
}
|
572
|
+
})
|
573
|
+
puts res.code # the HTTP response code
|
574
|
+
puts res.request_id # if the code is 202, this will be the Courier request ID for this message
|
575
|
+
rescue Courier::CourierAPIError => re #error sent from from the API
|
576
|
+
puts re.message
|
577
|
+
end
|
578
|
+
```
|
579
|
+
|
580
|
+
### Audit Events
|
581
|
+
|
582
|
+
```Ruby
|
583
|
+
"""
|
584
|
+
Example: List audit events
|
585
|
+
"""
|
586
|
+
resp = client.audit_events.list()
|
587
|
+
|
588
|
+
"""
|
589
|
+
Example: Get a specific audit event
|
590
|
+
"""
|
591
|
+
resp = client.audit_events.get(audit_event_id: "audit-event-id")
|
592
|
+
```
|
593
|
+
|
405
594
|
## Development
|
406
595
|
|
407
596
|
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.
|
@@ -415,3 +604,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/trycou
|
|
415
604
|
## License
|
416
605
|
|
417
606
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
607
|
+
|
608
|
+
```
|
609
|
+
|
610
|
+
```
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Courier
|
2
|
+
class Audiences
|
3
|
+
KEY = "/audiences"
|
4
|
+
|
5
|
+
def initialize(session)
|
6
|
+
@session = session
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_audience(audience_id:)
|
10
|
+
path = "#{KEY}/#{audience_id}"
|
11
|
+
res = @session.send(path, "GET")
|
12
|
+
ErrorHandler.check_err(res)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_audiences(cursor: nil)
|
16
|
+
params = {}
|
17
|
+
if cursor
|
18
|
+
params["cursor"] = cursor
|
19
|
+
end
|
20
|
+
|
21
|
+
res = @session.send(KEY, "GET", params: params)
|
22
|
+
ErrorHandler.check_err(res)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_audience_members(audience_id:, cursor: nil)
|
26
|
+
path = "#{KEY}/#{audience_id}/members"
|
27
|
+
|
28
|
+
params = {}
|
29
|
+
if cursor
|
30
|
+
params["cursor"] = cursor
|
31
|
+
end
|
32
|
+
|
33
|
+
res = @session.send(path, "GET", params: params)
|
34
|
+
ErrorHandler.check_err(res)
|
35
|
+
end
|
36
|
+
|
37
|
+
def put(audience_id:, payload:)
|
38
|
+
path = "#{KEY}/#{audience_id}"
|
39
|
+
|
40
|
+
res = @session.send(path, "PUT", body: payload)
|
41
|
+
ErrorHandler.check_err(res)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Courier
|
2
|
+
class AuditEvents
|
3
|
+
KEY = "/audit-events"
|
4
|
+
|
5
|
+
def initialize(session)
|
6
|
+
@session = session
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(audit_event_id:)
|
10
|
+
path = "#{KEY}/#{audit_event_id}"
|
11
|
+
res = @session.send(path, "GET")
|
12
|
+
ErrorHandler.check_err(res)
|
13
|
+
end
|
14
|
+
|
15
|
+
def list(cursor: nil)
|
16
|
+
path = "#{KEY}"
|
17
|
+
|
18
|
+
params = {}
|
19
|
+
if cursor
|
20
|
+
params["cursor"] = cursor
|
21
|
+
end
|
22
|
+
|
23
|
+
res = @session.send(path, "GET", params: params)
|
24
|
+
ErrorHandler.check_err(res)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/trycourier/bulk.rb
CHANGED
@@ -4,10 +4,12 @@ require "json"
|
|
4
4
|
require "openssl"
|
5
5
|
|
6
6
|
module Courier
|
7
|
-
#ResponseError in order to maintain v1.0.2 signature.
|
7
|
+
# ResponseError in order to maintain v1.0.2 signature.
|
8
8
|
class InputError < StandardError; end
|
9
|
+
|
9
10
|
class ResponseError < StandardError; end
|
10
|
-
|
11
|
+
|
12
|
+
class CourierAPIError < ResponseError; end
|
11
13
|
|
12
14
|
class ErrorHandler
|
13
15
|
def self.check_err(res)
|
data/lib/trycourier/messages.rb
CHANGED
data/lib/trycourier/session.rb
CHANGED
@@ -4,7 +4,6 @@ require "openssl"
|
|
4
4
|
|
5
5
|
module Courier
|
6
6
|
class CourierAPISession
|
7
|
-
|
8
7
|
def initialize(base_url)
|
9
8
|
@base_url = base_url
|
10
9
|
end
|
@@ -75,7 +74,7 @@ module Courier
|
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
|
-
#getter for base url (for testing)
|
77
|
+
# getter for base url (for testing)
|
79
78
|
attr_reader :base_url
|
80
79
|
end
|
81
80
|
end
|
data/lib/trycourier/version.rb
CHANGED
data/lib/trycourier.rb
CHANGED
@@ -6,8 +6,11 @@ require "trycourier/session"
|
|
6
6
|
require "trycourier/messages"
|
7
7
|
require "trycourier/automations"
|
8
8
|
require "trycourier/bulk"
|
9
|
+
require "trycourier/audiences"
|
10
|
+
require "trycourier/audit_events"
|
9
11
|
require "trycourier/version"
|
10
12
|
require "trycourier/exceptions"
|
13
|
+
|
11
14
|
require "net/http"
|
12
15
|
require "json"
|
13
16
|
require "openssl"
|
@@ -23,6 +26,16 @@ module Courier
|
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
29
|
+
class SendMessageResponse
|
30
|
+
attr_reader :code
|
31
|
+
attr_reader :request_id
|
32
|
+
|
33
|
+
def initialize(code, request_id)
|
34
|
+
@code = code
|
35
|
+
@request_id = request_id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
26
39
|
class Client
|
27
40
|
def initialize(auth_token = nil, username: nil, password: nil, base_url: nil)
|
28
41
|
base = if base_url
|
@@ -52,18 +65,20 @@ module Courier
|
|
52
65
|
@brands = Courier::Brands.new(@session)
|
53
66
|
@automations = Courier::Automations.new(@session)
|
54
67
|
@bulk = Courier::Bulk.new(@session)
|
68
|
+
@audiences = Courier::Audiences.new(@session)
|
69
|
+
@audit_events = Courier::AuditEvents.new(@session)
|
55
70
|
end
|
56
71
|
|
57
72
|
def send(body)
|
58
|
-
if
|
73
|
+
if !body.is_a?(Hash)
|
59
74
|
raise InputError, "Client#send must be passed a Hash as first argument."
|
60
|
-
elsif body["event"]
|
75
|
+
elsif body["event"].nil? && body[:event].nil?
|
61
76
|
raise InputError, "Must specify the 'event' key in Hash supplied to Client#send."
|
62
|
-
elsif body["recipient"]
|
77
|
+
elsif body["recipient"].nil? && body[:recipient].nil?
|
63
78
|
raise InputError, "Must specify the 'recipient' key in Hash supplied to Client#send."
|
64
|
-
elsif (body["data"]
|
79
|
+
elsif (!body["data"].nil? && !body["data"].is_a?(Hash)) || (!body[:data].nil? && !body[:data].is_a?(Hash))
|
65
80
|
raise InputError, "The 'data' key in the Hash supplied to Client#send must also be a Hash."
|
66
|
-
elsif (body["profile"]
|
81
|
+
elsif (!body["profile"].nil? && !body["profile"].is_a?(Hash)) || (!body[:profile].nil? && !body[:profile].is_a?(Hash))
|
67
82
|
raise InputError, "The 'profile' key in the Hash supplied to Client#send must also be a Hash."
|
68
83
|
end
|
69
84
|
|
@@ -81,6 +96,27 @@ module Courier
|
|
81
96
|
end
|
82
97
|
end
|
83
98
|
|
99
|
+
def send_message(body)
|
100
|
+
if !body.is_a?(Hash)
|
101
|
+
raise InputError, "Client#send_message must be passed a Hash as first argument."
|
102
|
+
elsif (!body["message"].nil? && !body["message"].is_a?(Hash)) || (!body[:message].nil? && !body[:message].is_a?(Hash))
|
103
|
+
raise InputError, "The 'message' key in the Hash supplied to Client#send_message must also be a Hash."
|
104
|
+
end
|
105
|
+
|
106
|
+
res = @session.send("/send", "POST", body: body)
|
107
|
+
|
108
|
+
code = res.code.to_i
|
109
|
+
obj = JSON.parse res.read_body
|
110
|
+
|
111
|
+
if code == 202
|
112
|
+
request_id = obj["requestId"]
|
113
|
+
SendMessageResponse.new(code, request_id)
|
114
|
+
elsif (message = obj["Message"].nil? ? obj["message"] : obj["Message"])
|
115
|
+
err = "#{code}: #{message}"
|
116
|
+
raise CourierAPIError, err
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
84
120
|
# getters for all class variables
|
85
121
|
|
86
122
|
attr_reader :session
|
@@ -98,5 +134,10 @@ module Courier
|
|
98
134
|
attr_reader :automations
|
99
135
|
|
100
136
|
attr_reader :bulk
|
137
|
+
|
138
|
+
attr_reader :audiences
|
139
|
+
|
140
|
+
attr_reader :audit_events
|
141
|
+
|
101
142
|
end
|
102
143
|
end
|
data/trycourier.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = "trycourier"
|
5
5
|
spec.version = Courier::VERSION
|
6
6
|
spec.authors = ["Courier"]
|
7
|
-
spec.email = ["support@courier.com"]
|
7
|
+
spec.email = ["support@courier.com"]
|
8
8
|
|
9
9
|
spec.summary = "Wraps calls to the Courier REST API"
|
10
10
|
spec.description = "Courier is the smartest way to design & deliver notifications. Design your notifications once, deliver them to any channel through one API."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trycourier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -61,6 +61,8 @@ files:
|
|
61
61
|
- bin/console
|
62
62
|
- bin/setup
|
63
63
|
- lib/trycourier.rb
|
64
|
+
- lib/trycourier/audiences.rb
|
65
|
+
- lib/trycourier/audit_events.rb
|
64
66
|
- lib/trycourier/automations.rb
|
65
67
|
- lib/trycourier/brands.rb
|
66
68
|
- lib/trycourier/bulk.rb
|