trycourier 1.2.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +11 -9
- data/CHANGELOG.md +19 -1
- data/Gemfile.lock +36 -36
- data/README.md +109 -0
- data/lib/trycourier/audiences.rb +45 -0
- data/lib/trycourier/bulk.rb +79 -0
- 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 +47 -5
- data/trycourier.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e9bd120c1a6bd12bf0960fae9661848fe6a6e41c2782baa6eb3ae166882c428b
|
|
4
|
+
data.tar.gz: 4d2f6ba063c1dfb2270feaab7c0763c7aafb88920ea1f327d91bdc681abbc975
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56c1130d7caa6e4484ce56ff35dbce92518cd5559c32cf2895a18c45227bd81c49f27fb376e45d8c610eef5c49c2857265233028a5020bcf76a8f8a8630cb671
|
|
7
|
+
data.tar.gz: 1680c9bf19b28f762ce9ec73c01c33f6ae7035a0a824f4a013f5d489471c54ef2dde450f85729aba4658ff7b8db129f6e898b1bc77bd3cce8e3e867c5a03807f
|
|
@@ -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,21 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased][unreleased]
|
|
7
7
|
|
|
8
|
+
## [v1.5.0] - 2022-03-28
|
|
9
|
+
- Support for audiences API
|
|
10
|
+
|
|
11
|
+
## [v1.4.0] - 2022-01-31
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Support for enhanced Send API by @tk26
|
|
16
|
+
|
|
17
|
+
## [v1.3.0] - 2022-01-26
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Support for Bulk API by @tk26
|
|
22
|
+
|
|
8
23
|
## [v1.2.0] - 2021-04-08
|
|
9
24
|
|
|
10
25
|
### Added
|
|
@@ -79,7 +94,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
79
94
|
|
|
80
95
|
Initial release by @troygoode
|
|
81
96
|
|
|
82
|
-
[unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.
|
|
97
|
+
[unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.5.0...HEAD
|
|
98
|
+
[v1.5.0]: https://github.com/trycourier/courier-ruby/compare/v1.4.0...v1.5.0
|
|
99
|
+
[v1.4.0]: https://github.com/trycourier/courier-ruby/compare/v1.3.0...v1.4.0
|
|
100
|
+
[v1.3.0]: https://github.com/trycourier/courier-ruby/compare/v1.2.0...v1.3.0
|
|
83
101
|
[v1.2.0]: https://github.com/trycourier/courier-ruby/compare/v1.1.0...v1.2.0
|
|
84
102
|
[v1.1.0]: https://github.com/trycourier/courier-ruby/compare/v1.0.2...v1.1.0
|
|
85
103
|
[v1.0.2]: https://github.com/trycourier/courier-ruby/compare/v1.0.1...v1.0.2
|
data/Gemfile.lock
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
trycourier (1.0
|
|
4
|
+
trycourier (1.5.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,37 @@ 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
|
+
"trace_id" => "feed-me-hungry"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
puts res.code # the HTTP response code
|
|
115
|
+
puts res.request_id # if the code is 202, this will be the Courier request ID for this message
|
|
116
|
+
rescue Courier::CourierAPIError => re #error sent from from the API
|
|
117
|
+
puts re.message
|
|
118
|
+
end
|
|
119
|
+
```
|
|
120
|
+
|
|
67
121
|
## Advanced Usage
|
|
68
122
|
|
|
69
123
|
### Lists
|
|
@@ -402,6 +456,57 @@ Any other errors from the API are thrown as a CourierAPIError. Catch these error
|
|
|
402
456
|
rescue CourierAPIError
|
|
403
457
|
```
|
|
404
458
|
|
|
459
|
+
### Audiences
|
|
460
|
+
|
|
461
|
+
List of supported operators for audience filtering: https://www.courier.com/docs/reference/audieces/operators
|
|
462
|
+
|
|
463
|
+
```Ruby
|
|
464
|
+
"""
|
|
465
|
+
Example: create or update an Audience
|
|
466
|
+
"""
|
|
467
|
+
resp = client.audiences.put(
|
|
468
|
+
audience_id: "your-audience-id",
|
|
469
|
+
filter: {
|
|
470
|
+
"operator": "EQ",
|
|
471
|
+
"value": "en-US",
|
|
472
|
+
"path": "locale"
|
|
473
|
+
}
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
"""
|
|
477
|
+
Example: Get all members of an Audience
|
|
478
|
+
"""
|
|
479
|
+
resp = client.audiences.get_audience_members(
|
|
480
|
+
audience_id: "your-audience-id",
|
|
481
|
+
cursor: nil
|
|
482
|
+
)
|
|
483
|
+
puts resp['status']
|
|
484
|
+
|
|
485
|
+
"""
|
|
486
|
+
Example: Send to an Audience
|
|
487
|
+
"""
|
|
488
|
+
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
|
489
|
+
res = client.send_message({
|
|
490
|
+
"message" => {
|
|
491
|
+
"to" => {
|
|
492
|
+
"audience_id" => "your-audience-id"
|
|
493
|
+
}
|
|
494
|
+
"content" => {
|
|
495
|
+
"title" => "hello {{name}}",
|
|
496
|
+
"body" => "Welcome to Courier!"
|
|
497
|
+
},
|
|
498
|
+
"data" => {
|
|
499
|
+
"name" => "Ruby"
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
})
|
|
503
|
+
puts res.code # the HTTP response code
|
|
504
|
+
puts res.request_id # if the code is 202, this will be the Courier request ID for this message
|
|
505
|
+
rescue Courier::CourierAPIError => re #error sent from from the API
|
|
506
|
+
puts re.message
|
|
507
|
+
end
|
|
508
|
+
```
|
|
509
|
+
|
|
405
510
|
## Development
|
|
406
511
|
|
|
407
512
|
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 +520,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/trycou
|
|
|
415
520
|
## License
|
|
416
521
|
|
|
417
522
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
523
|
+
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
```
|
|
@@ -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,79 @@
|
|
|
1
|
+
module Courier
|
|
2
|
+
class Bulk
|
|
3
|
+
KEY = "/bulk"
|
|
4
|
+
|
|
5
|
+
def initialize(session)
|
|
6
|
+
@session = session
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def create_job(message:, idempotency_key: nil, idempotency_expiry: nil)
|
|
10
|
+
path = KEY.to_s
|
|
11
|
+
payload = {
|
|
12
|
+
"message": message
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
headers = {}
|
|
16
|
+
if idempotency_key
|
|
17
|
+
headers["idempotency_key"] = idempotency_key
|
|
18
|
+
end
|
|
19
|
+
if idempotency_expiry
|
|
20
|
+
headers["x-idempotency-expiration"] = idempotency_expiry
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
res = @session.send(path, "POST", body: payload, headers: headers)
|
|
24
|
+
ErrorHandler.check_err(res)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def ingest_job(job_id:, users:, idempotency_key: nil, idempotency_expiry: nil)
|
|
28
|
+
path = "#{KEY}/#{job_id}"
|
|
29
|
+
payload = {
|
|
30
|
+
"users": users
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
headers = {}
|
|
34
|
+
if idempotency_key
|
|
35
|
+
headers["idempotency_key"] = idempotency_key
|
|
36
|
+
end
|
|
37
|
+
if idempotency_expiry
|
|
38
|
+
headers["x-idempotency-expiration"] = idempotency_expiry
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
res = @session.send(path, "POST", body: payload, headers: headers)
|
|
42
|
+
ErrorHandler.check_err(res)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def run_job(job_id:, idempotency_key: nil, idempotency_expiry: nil)
|
|
46
|
+
path = "#{KEY}/#{job_id}/run"
|
|
47
|
+
payload = {}
|
|
48
|
+
|
|
49
|
+
headers = {}
|
|
50
|
+
if idempotency_key
|
|
51
|
+
headers["idempotency_key"] = idempotency_key
|
|
52
|
+
end
|
|
53
|
+
if idempotency_expiry
|
|
54
|
+
headers["x-idempotency-expiration"] = idempotency_expiry
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
res = @session.send(path, "POST", body: payload, headers: headers)
|
|
58
|
+
ErrorHandler.check_err_non_json(res)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def get_job(job_id:)
|
|
62
|
+
path = "#{KEY}/#{job_id}"
|
|
63
|
+
res = @session.send(path, "GET")
|
|
64
|
+
ErrorHandler.check_err(res)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def get_job_users(job_id:, cursor: nil)
|
|
68
|
+
path = "#{KEY}/#{job_id}/users"
|
|
69
|
+
|
|
70
|
+
params = {}
|
|
71
|
+
if cursor
|
|
72
|
+
params["cursor"] = cursor
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
res = @session.send(path, "GET", params: params)
|
|
76
|
+
ErrorHandler.check_err(res)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -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
|
@@ -5,8 +5,11 @@ require "trycourier/profiles"
|
|
|
5
5
|
require "trycourier/session"
|
|
6
6
|
require "trycourier/messages"
|
|
7
7
|
require "trycourier/automations"
|
|
8
|
+
require "trycourier/bulk"
|
|
9
|
+
require "trycourier/audiences"
|
|
8
10
|
require "trycourier/version"
|
|
9
11
|
require "trycourier/exceptions"
|
|
12
|
+
|
|
10
13
|
require "net/http"
|
|
11
14
|
require "json"
|
|
12
15
|
require "openssl"
|
|
@@ -22,6 +25,16 @@ module Courier
|
|
|
22
25
|
end
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
class SendMessageResponse
|
|
29
|
+
attr_reader :code
|
|
30
|
+
attr_reader :request_id
|
|
31
|
+
|
|
32
|
+
def initialize(code, request_id)
|
|
33
|
+
@code = code
|
|
34
|
+
@request_id = request_id
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
25
38
|
class Client
|
|
26
39
|
def initialize(auth_token = nil, username: nil, password: nil, base_url: nil)
|
|
27
40
|
base = if base_url
|
|
@@ -50,18 +63,20 @@ module Courier
|
|
|
50
63
|
@events = Courier::Events.new(@session)
|
|
51
64
|
@brands = Courier::Brands.new(@session)
|
|
52
65
|
@automations = Courier::Automations.new(@session)
|
|
66
|
+
@bulk = Courier::Bulk.new(@session)
|
|
67
|
+
@audiences = Courier::Audiences.new(@session)
|
|
53
68
|
end
|
|
54
69
|
|
|
55
70
|
def send(body)
|
|
56
|
-
if
|
|
71
|
+
if !body.is_a?(Hash)
|
|
57
72
|
raise InputError, "Client#send must be passed a Hash as first argument."
|
|
58
|
-
elsif body["event"]
|
|
73
|
+
elsif body["event"].nil? && body[:event].nil?
|
|
59
74
|
raise InputError, "Must specify the 'event' key in Hash supplied to Client#send."
|
|
60
|
-
elsif body["recipient"]
|
|
75
|
+
elsif body["recipient"].nil? && body[:recipient].nil?
|
|
61
76
|
raise InputError, "Must specify the 'recipient' key in Hash supplied to Client#send."
|
|
62
|
-
elsif (body["data"]
|
|
77
|
+
elsif (!body["data"].nil? && !body["data"].is_a?(Hash)) || (!body[:data].nil? && !body[:data].is_a?(Hash))
|
|
63
78
|
raise InputError, "The 'data' key in the Hash supplied to Client#send must also be a Hash."
|
|
64
|
-
elsif (body["profile"]
|
|
79
|
+
elsif (!body["profile"].nil? && !body["profile"].is_a?(Hash)) || (!body[:profile].nil? && !body[:profile].is_a?(Hash))
|
|
65
80
|
raise InputError, "The 'profile' key in the Hash supplied to Client#send must also be a Hash."
|
|
66
81
|
end
|
|
67
82
|
|
|
@@ -79,6 +94,27 @@ module Courier
|
|
|
79
94
|
end
|
|
80
95
|
end
|
|
81
96
|
|
|
97
|
+
def send_message(body)
|
|
98
|
+
if !body.is_a?(Hash)
|
|
99
|
+
raise InputError, "Client#send_message must be passed a Hash as first argument."
|
|
100
|
+
elsif (!body["message"].nil? && !body["message"].is_a?(Hash)) || (!body[:message].nil? && !body[:message].is_a?(Hash))
|
|
101
|
+
raise InputError, "The 'message' key in the Hash supplied to Client#send_message must also be a Hash."
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
res = @session.send("/send", "POST", body: body)
|
|
105
|
+
|
|
106
|
+
code = res.code.to_i
|
|
107
|
+
obj = JSON.parse res.read_body
|
|
108
|
+
|
|
109
|
+
if code == 202
|
|
110
|
+
request_id = obj["requestId"]
|
|
111
|
+
SendMessageResponse.new(code, request_id)
|
|
112
|
+
elsif (message = obj["Message"].nil? ? obj["message"] : obj["Message"])
|
|
113
|
+
err = "#{code}: #{message}"
|
|
114
|
+
raise CourierAPIError, err
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
82
118
|
# getters for all class variables
|
|
83
119
|
|
|
84
120
|
attr_reader :session
|
|
@@ -94,5 +130,11 @@ module Courier
|
|
|
94
130
|
attr_reader :brands
|
|
95
131
|
|
|
96
132
|
attr_reader :automations
|
|
133
|
+
|
|
134
|
+
attr_reader :bulk
|
|
135
|
+
|
|
136
|
+
attr_reader :audiences
|
|
137
|
+
|
|
138
|
+
|
|
97
139
|
end
|
|
98
140
|
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.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Courier
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-04-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -61,8 +61,10 @@ files:
|
|
|
61
61
|
- bin/console
|
|
62
62
|
- bin/setup
|
|
63
63
|
- lib/trycourier.rb
|
|
64
|
+
- lib/trycourier/audiences.rb
|
|
64
65
|
- lib/trycourier/automations.rb
|
|
65
66
|
- lib/trycourier/brands.rb
|
|
67
|
+
- lib/trycourier/bulk.rb
|
|
66
68
|
- lib/trycourier/events.rb
|
|
67
69
|
- lib/trycourier/exceptions.rb
|
|
68
70
|
- lib/trycourier/lists.rb
|
|
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
94
96
|
- !ruby/object:Gem::Version
|
|
95
97
|
version: '0'
|
|
96
98
|
requirements: []
|
|
97
|
-
rubygems_version: 3.1.
|
|
99
|
+
rubygems_version: 3.1.6
|
|
98
100
|
signing_key:
|
|
99
101
|
specification_version: 4
|
|
100
102
|
summary: Wraps calls to the Courier REST API
|