trycourier 1.4.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/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/README.md +97 -7
- data/lib/trycourier/audiences.rb +45 -0
- data/lib/trycourier/version.rb +1 -1
- data/lib/trycourier.rb +7 -0
- metadata +3 -2
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
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,9 @@ 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
|
+
|
8
11
|
## [v1.4.0] - 2022-01-31
|
9
12
|
|
10
13
|
### Added
|
@@ -91,7 +94,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
91
94
|
|
92
95
|
Initial release by @troygoode
|
93
96
|
|
94
|
-
[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
|
95
99
|
[v1.4.0]: https://github.com/trycourier/courier-ruby/compare/v1.3.0...v1.4.0
|
96
100
|
[v1.3.0]: https://github.com/trycourier/courier-ruby/compare/v1.2.0...v1.3.0
|
97
101
|
[v1.2.0]: https://github.com/trycourier/courier-ruby/compare/v1.1.0...v1.2.0
|
data/Gemfile.lock
CHANGED
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,17 +87,27 @@ rescue Courier::CourierAPIError => re #error sent from from the API
|
|
64
87
|
end
|
65
88
|
```
|
66
89
|
|
67
|
-
|
68
|
-
|
69
|
-
### Send API enhanced
|
90
|
+
### Sending a message to an individual with metadata
|
70
91
|
|
71
92
|
```ruby
|
72
93
|
client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
|
73
94
|
res = client.send_message({
|
74
|
-
message => {
|
75
|
-
|
76
|
-
|
77
|
-
|
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"
|
78
111
|
}
|
79
112
|
}
|
80
113
|
})
|
@@ -85,6 +118,8 @@ rescue Courier::CourierAPIError => re #error sent from from the API
|
|
85
118
|
end
|
86
119
|
```
|
87
120
|
|
121
|
+
## Advanced Usage
|
122
|
+
|
88
123
|
### Lists
|
89
124
|
|
90
125
|
```ruby
|
@@ -421,6 +456,57 @@ Any other errors from the API are thrown as a CourierAPIError. Catch these error
|
|
421
456
|
rescue CourierAPIError
|
422
457
|
```
|
423
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
|
+
|
424
510
|
## Development
|
425
511
|
|
426
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.
|
@@ -434,3 +520,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/trycou
|
|
434
520
|
## License
|
435
521
|
|
436
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
|
data/lib/trycourier/version.rb
CHANGED
data/lib/trycourier.rb
CHANGED
@@ -6,8 +6,10 @@ require "trycourier/session"
|
|
6
6
|
require "trycourier/messages"
|
7
7
|
require "trycourier/automations"
|
8
8
|
require "trycourier/bulk"
|
9
|
+
require "trycourier/audiences"
|
9
10
|
require "trycourier/version"
|
10
11
|
require "trycourier/exceptions"
|
12
|
+
|
11
13
|
require "net/http"
|
12
14
|
require "json"
|
13
15
|
require "openssl"
|
@@ -62,6 +64,7 @@ module Courier
|
|
62
64
|
@brands = Courier::Brands.new(@session)
|
63
65
|
@automations = Courier::Automations.new(@session)
|
64
66
|
@bulk = Courier::Bulk.new(@session)
|
67
|
+
@audiences = Courier::Audiences.new(@session)
|
65
68
|
end
|
66
69
|
|
67
70
|
def send(body)
|
@@ -129,5 +132,9 @@ module Courier
|
|
129
132
|
attr_reader :automations
|
130
133
|
|
131
134
|
attr_reader :bulk
|
135
|
+
|
136
|
+
attr_reader :audiences
|
137
|
+
|
138
|
+
|
132
139
|
end
|
133
140
|
end
|
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: 2022-
|
11
|
+
date: 2022-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -61,6 +61,7 @@ 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
|
66
67
|
- lib/trycourier/bulk.rb
|