trycourier 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e2e7e6f4ad2900f3ad0d118062208c74492851e96976da6795c6309c95ad9ea
4
- data.tar.gz: ce78409870df6608de59bc5ea4a628732b09f8d3ec7b304202f1721d07ff5836
3
+ metadata.gz: e9bd120c1a6bd12bf0960fae9661848fe6a6e41c2782baa6eb3ae166882c428b
4
+ data.tar.gz: 4d2f6ba063c1dfb2270feaab7c0763c7aafb88920ea1f327d91bdc681abbc975
5
5
  SHA512:
6
- metadata.gz: 060ff6e98ab2a50557b9e54cf2e1fe2f13d02a4569e335f4ffe31c7bd8fa55c8bbcaef7df686c19c9c98ae0c032e024ba6bc705242bc4df5f26bd9c780174538
7
- data.tar.gz: fd9c70f99624a1d82e3a0c6825b17cea6526a0d8c46e0a221c8740514e366851ba59854454919f723cd8a3b205ae8800462fe8965fe05aab9fb2dafe667b0333
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.4.0...HEAD
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trycourier (1.4.0)
4
+ trycourier (1.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- ## Advanced Usage
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
- template => "my-template",
76
- to => {
77
- email => "foo@bar.com"
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
@@ -1,3 +1,3 @@
1
1
  module Courier
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
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.0
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-01-31 00:00:00.000000000 Z
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