trycourier 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40ffa9399327479e0f0fa89c350decd17f242caa48b91f1a772cebd4f25d5610
4
- data.tar.gz: fd159122320af8ab96223890b78061dd21ce193adadceb146f7e18d36a798032
3
+ metadata.gz: 71daf0eb0e891e05d2a2f76461586d5af3fbd029d1c813c6df8dc41015329370
4
+ data.tar.gz: 54826227d59241eb5c0c4e382b9bdab12ce135eaaa4b5b7d17c2ba0bdc871f33
5
5
  SHA512:
6
- metadata.gz: 524f60d42ec87e581ce591d7550f34ab0a5c592d33618465eba1d26a25822b8c8d3974ad188ef5cc089d24947424ffebe434655e64481b81fed244b95fd22fbf
7
- data.tar.gz: bb97291b655840c5051b78beb48d345827be048392e16c7b7486749eac80e45f111cedc216448d8a93997eaae2f57c90c089c7ff1abbc00ad66aa9930bba9212
6
+ metadata.gz: 20f4fdbc92da8822a01110a7480113ef09fd1e76b2d1ee4045aadebf617930c1eba2a9756e785764b9a4487ff2df8b23fb09d393b27b07e3f4d1d5e1e6a921f2
7
+ data.tar.gz: 0e6f85140f74677ffbe309ecebc0194974ee4c7e97959fc9a94bb5ea838a27d75e780c5028de9dc43e9b3f8caee9ddae9ffaa9b500b2f37391485afe75fb1460
data/CHANGELOG.md CHANGED
@@ -5,8 +5,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased][unreleased]
7
7
 
8
+ ## [v1.2.0] - 2021-04-08
9
+
10
+ ### Added
11
+
12
+ - Support for [Automation API](https://docs.courier.com/reference/automation-api) by @tk26
13
+ - `POST /automations/invoke` with `client.automations.invoke` method
14
+ - `POST /automations/{template_id}/invoke` with `client.automations.invoke_template` method
15
+
8
16
  ## [v1.1.0] - 2021-01-26
17
+
9
18
  ### Added
19
+
10
20
  - Support for Basic Auth
11
21
  - ENV variables `COURIER_AUTH_USERNAME` and `COURIER_AUTH_PASSWORD` OR set with params
12
22
  - Token Auth using ENV variables
@@ -14,6 +24,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
14
24
  - Base URL parameter (with default of api.courier.com)
15
25
  - ENV variable `COURIER_BASE_URL`
16
26
  - Support for Lists API by @jrweingart
27
+
17
28
  - `POST /send/list` with `client.lists.send` method
18
29
  - `GET /lists` with `client.lists.list` method
19
30
  - `GET /lists/{list_id}` with `client.lists.get` method
@@ -26,6 +37,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
26
37
  - `DELETE /lists/{list_id}/subscriptions/{recipient_id}` with `client.lists.unsubscribe` method
27
38
 
28
39
  - Support for Profiles API by @jrweingart
40
+
29
41
  - `GET /profiles/{recipient_id}` with `client.profiles.get` method
30
42
  - `GET /profiles/{recipient_id}/lists` with `client.profiles.get_subscriptions` method
31
43
  - `PUT /profiles/{recipient_id}` with `client.profiles.replace` and `client.profiles.add` methods
@@ -33,11 +45,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
33
45
  - `POST /profiles/{recipient_id}` with `client.profiles.merge` method
34
46
 
35
47
  - Support for Messages API by @jrweingart
48
+
36
49
  - `GET /messages` with `client.messages.list` method
37
50
  - `GET /messages/{message_id}` with `client.messages.get` method
38
51
  - `GET /messages/{message_id}/history` with `client.messages.get_history` method
39
52
 
40
53
  - Support for Events API by @jrweingart
54
+
41
55
  - `GET /events` with `client.events.list` method
42
56
  - `GET /events/{event_id}` with `client.event.get` method
43
57
  - `PUT /events/{event_id}` with `client.events.replace` and `client.events.add` methods
@@ -50,17 +64,23 @@ This project adheres to [Semantic Versioning](http://semver.org/).
50
64
  - `DELETE /brands/brand_id` with `client.brands.delete` method
51
65
 
52
66
  ## [v1.0.2] - 2021-01-06
67
+
53
68
  ### Added
69
+
54
70
  - Minor bug fixes to ensure proper SSL certification by @scarney81
55
71
 
56
72
  ## [v1.0.1] - 2020-03-04
73
+
57
74
  ### Added
75
+
58
76
  - Support for Send API by @troy
59
77
 
60
78
  ## v1.0.0 - 2020-03-03
79
+
61
80
  Initial release by @troygoode
62
81
 
63
- [unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.1.0...HEAD
82
+ [unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.2.0...HEAD
83
+ [v1.2.0]: https://github.com/trycourier/courier-ruby/compare/v1.1.0...v1.2.0
64
84
  [v1.1.0]: https://github.com/trycourier/courier-ruby/compare/v1.0.2...v1.1.0
65
85
  [v1.0.2]: https://github.com/trycourier/courier-ruby/compare/v1.0.1...v1.0.2
66
86
  [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/README.md CHANGED
@@ -19,21 +19,29 @@ Or install it yourself as:
19
19
  $ gem install trycourier
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"
25
27
  ```
28
+
26
29
  To create a Courier Ruby client, all you need to do is pass in your authentication information. Then, you can start sending!
30
+
27
31
  ### Using token authentication (most secure)
32
+
28
33
  ```ruby
29
34
  client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var (recommended)
30
35
  ```
31
36
 
32
37
  ### Using basic authentication
38
+
33
39
  ```ruby
34
40
  client = Courier::Client.new(username: "USERNAME", password: "PASSWORD") # or set via COURIER_AUTH_USERNAME and COURIER_AUTH_PASSWORD env vars
35
41
  ```
42
+
36
43
  ### Sending a message to an individual recipient
44
+
37
45
  ```ruby
38
46
  client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
39
47
  res = client.send({
@@ -55,9 +63,11 @@ rescue Courier::CourierAPIError => re #error sent from from the API
55
63
  puts re.message
56
64
  end
57
65
  ```
66
+
58
67
  ## Advanced Usage
59
68
 
60
69
  ### Lists
70
+
61
71
  ```ruby
62
72
  require "trycourier"
63
73
  client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
@@ -143,7 +153,9 @@ Example: unsubscribe recipient from list
143
153
  """
144
154
  client.lists.unsubscribe(list_id: "your-list-id", recipient_id: "your-recipient-id")
145
155
  ```
156
+
146
157
  ### Profiles
158
+
147
159
  ```Ruby
148
160
  """
149
161
  Example: create a recipient's profile
@@ -188,13 +200,13 @@ resp = client.profiles.get_subscriptions(
188
200
  puts resp
189
201
 
190
202
  """
191
- Example: edit the contents of a recipient's profile with a patch operation
192
- (follows JSON Patch conventions: RFC 6902).
203
+ Example: edit the contents of a recipient's profile with a patch operation
204
+ (follows JSON Patch conventions: RFC 6902).
193
205
  """
194
206
  resp = client.profiles.patch(
195
207
  recipient_id: "your-recipient-id",
196
208
  operations: [
197
- {
209
+ {
198
210
  "op" => "add", #operation 1: add this email to profile
199
211
  "path" => "/parent",
200
212
  "value" => "example@example.com"
@@ -223,6 +235,7 @@ puts resp
223
235
  ```
224
236
 
225
237
  ### Messages
238
+
226
239
  ```Ruby
227
240
  """
228
241
  Example: fetch the statuses of messages you've previously sent.
@@ -254,6 +267,7 @@ puts resp
254
267
  ```
255
268
 
256
269
  ### Events
270
+
257
271
  ```Ruby
258
272
  """
259
273
  Example: fetch the list of events
@@ -296,7 +310,7 @@ Example: create a brand
296
310
  """
297
311
  resp = client.brands.create(
298
312
  name: "brand-name",
299
- settings: {
313
+ settings: {
300
314
  "color" => {
301
315
  "primary" => "#0000FF",
302
316
  "secondary" => "#FF0000",
@@ -333,16 +347,60 @@ resp = client.brands.delete(brand_id: "your-brand-id")
333
347
  puts resp
334
348
  ```
335
349
 
350
+ ### Automations
351
+
352
+ ````Ruby
353
+ """
354
+ Example: invoke ad-hoc automation
355
+ """
356
+ steps = [
357
+ {
358
+ "action" => "send"
359
+ }
360
+ ]
361
+ automation = {
362
+ "steps" => steps
363
+ }
364
+
365
+ resp = client.automations.invoke(
366
+ automation: automation,
367
+ brand: "your-brand-id", # optional
368
+ data: {}, # optional
369
+ profile: {
370
+ "email" => "example@example.com",
371
+ }, # optional
372
+ recipient: "your-recipient-id", # optional
373
+ template: "your-notification-template-id" # optional
374
+ )
375
+ puts resp['runId']
376
+
377
+ """
378
+ Example: invoke automation template
379
+ """
380
+ resp = client.automations.invoke_template(
381
+ template_id: "your-automation-template-id",
382
+ brand: "your-brand-id", # optional
383
+ data: {}, # optional
384
+ profile: {
385
+ "email" => "example@example.com",
386
+ }, # optional
387
+ recipient: "your-recipient-id", # optional
388
+ template: "your-notification-template-id" # optional
389
+ )
390
+ puts resp['runId']
391
+
336
392
  ### Notes on input and errors
337
393
  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.
338
394
  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:
339
395
  ```ruby
340
396
  rescue InputError
341
- ```
397
+ ````
398
+
342
399
  Any other errors from the API are thrown as a CourierAPIError. Catch these errors by putting this after your method calls:
400
+
343
401
  ```ruby
344
402
  rescue CourierAPIError
345
- ```
403
+ ```
346
404
 
347
405
  ## Development
348
406
 
data/lib/trycourier.rb CHANGED
@@ -4,6 +4,7 @@ require "trycourier/lists"
4
4
  require "trycourier/profiles"
5
5
  require "trycourier/session"
6
6
  require "trycourier/messages"
7
+ require "trycourier/automations"
7
8
  require "trycourier/version"
8
9
  require "trycourier/exceptions"
9
10
  require "net/http"
@@ -48,6 +49,7 @@ module Courier
48
49
  @lists = Courier::Lists.new(@session)
49
50
  @events = Courier::Events.new(@session)
50
51
  @brands = Courier::Brands.new(@session)
52
+ @automations = Courier::Automations.new(@session)
51
53
  end
52
54
 
53
55
  def send(body)
@@ -90,5 +92,7 @@ module Courier
90
92
  attr_reader :lists
91
93
 
92
94
  attr_reader :brands
95
+
96
+ attr_reader :automations
93
97
  end
94
98
  end
@@ -0,0 +1,67 @@
1
+ module Courier
2
+ class Automations
3
+ KEY = "/automations"
4
+
5
+ def initialize(session)
6
+ @session = session
7
+ end
8
+
9
+ def invoke(automation:, brand: nil, data: nil, profile: nil, recipient: nil, template: nil)
10
+ path = "#{KEY}/invoke"
11
+ payload = {
12
+ "automation": automation
13
+ }
14
+
15
+ if brand
16
+ payload["brand"] = brand
17
+ end
18
+
19
+ if data
20
+ payload["data"] = data
21
+ end
22
+
23
+ if profile
24
+ payload["profile"] = profile
25
+ end
26
+
27
+ if recipient
28
+ payload["recipient"] = recipient
29
+ end
30
+
31
+ if template
32
+ payload["template"] = template
33
+ end
34
+
35
+ res = @session.send(path, "POST", body: payload, headers: {})
36
+ ErrorHandler.check_err(res)
37
+ end
38
+
39
+ def invoke_template(template_id:, brand: nil, data: nil, profile: nil, recipient: nil, template: nil)
40
+ path = "#{KEY}/#{template_id}/invoke"
41
+ payload = {}
42
+
43
+ if brand
44
+ payload["brand"] = brand
45
+ end
46
+
47
+ if data
48
+ payload["data"] = data
49
+ end
50
+
51
+ if profile
52
+ payload["profile"] = profile
53
+ end
54
+
55
+ if recipient
56
+ payload["recipient"] = recipient
57
+ end
58
+
59
+ if template
60
+ payload["template"] = template
61
+ end
62
+
63
+ res = @session.send(path, "POST", body: payload, headers: {})
64
+ ErrorHandler.check_err(res)
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Courier
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Courier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -52,6 +52,7 @@ files:
52
52
  - ".gitignore"
53
53
  - ".rspec"
54
54
  - CHANGELOG.md
55
+ - CONTRIBUTING.md
55
56
  - Gemfile
56
57
  - Gemfile.lock
57
58
  - LICENSE
@@ -60,6 +61,7 @@ files:
60
61
  - bin/console
61
62
  - bin/setup
62
63
  - lib/trycourier.rb
64
+ - lib/trycourier/automations.rb
63
65
  - lib/trycourier/brands.rb
64
66
  - lib/trycourier/events.rb
65
67
  - lib/trycourier/exceptions.rb