trycourier 1.3.0 → 1.4.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: 43ad4d30cf60c972878593e731297e16218eb733d5f234d42630c76ee4e61b70
4
- data.tar.gz: 1cf5722063320f2a9bd2365b28da54c2aed796c80fe26b5fd36f1e6409579c1e
3
+ metadata.gz: 2e2e7e6f4ad2900f3ad0d118062208c74492851e96976da6795c6309c95ad9ea
4
+ data.tar.gz: ce78409870df6608de59bc5ea4a628732b09f8d3ec7b304202f1721d07ff5836
5
5
  SHA512:
6
- metadata.gz: '08b2ec48d0f42bc45e87cfa2877d100b5deb2eb9927985a6544dbce6546a7950819a8d7885ffcd1d86c94c300ca2246d536ff57cb6589db0bb6f67be34c20107'
7
- data.tar.gz: d4a47fc88397e68f9160fb03fcee6ed11591c2d78eb044e279ab0463b225c22ebc2c0eb78a0eb4f879c79c76e65851a4d807f960676f1cce2424bae072e1198d
6
+ metadata.gz: 060ff6e98ab2a50557b9e54cf2e1fe2f13d02a4569e335f4ffe31c7bd8fa55c8bbcaef7df686c19c9c98ae0c032e024ba6bc705242bc4df5f26bd9c780174538
7
+ data.tar.gz: fd9c70f99624a1d82e3a0c6825b17cea6526a0d8c46e0a221c8740514e366851ba59854454919f723cd8a3b205ae8800462fe8965fe05aab9fb2dafe667b0333
@@ -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 2.7
18
- uses: actions/setup-ruby@v1
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
19
23
  with:
20
- ruby-version: 2.7.x
21
- - name: Install dependencies
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 2.7
36
- uses: actions/setup-ruby@v1
38
+ - name: Set up Ruby
39
+ uses: ruby/setup-ruby@v1
37
40
  with:
38
- ruby-version: 2.7.x
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,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased][unreleased]
7
7
 
8
+ ## [v1.4.0] - 2022-01-31
9
+
10
+ ### Added
11
+
12
+ - Support for enhanced Send API by @tk26
13
+
8
14
  ## [v1.3.0] - 2022-01-26
9
15
 
10
16
  ### Added
@@ -85,7 +91,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
85
91
 
86
92
  Initial release by @troygoode
87
93
 
88
- [unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.3.0...HEAD
94
+ [unreleased]: https://github.com/trycourier/courier-ruby/compare/v1.4.0...HEAD
95
+ [v1.4.0]: https://github.com/trycourier/courier-ruby/compare/v1.3.0...v1.4.0
89
96
  [v1.3.0]: https://github.com/trycourier/courier-ruby/compare/v1.2.0...v1.3.0
90
97
  [v1.2.0]: https://github.com/trycourier/courier-ruby/compare/v1.1.0...v1.2.0
91
98
  [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.2)
4
+ trycourier (1.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- addressable (2.7.0)
9
+ addressable (2.8.0)
10
10
  public_suffix (>= 2.0.2, < 5.0)
11
- ast (2.4.1)
11
+ ast (2.4.2)
12
12
  crack (0.4.5)
13
13
  rexml
14
- diff-lcs (1.3)
14
+ diff-lcs (1.5.0)
15
15
  hashdiff (1.0.1)
16
- parallel (1.20.1)
17
- parser (3.0.0.0)
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.0.0)
20
+ rainbow (3.1.1)
21
21
  rake (12.3.3)
22
- regexp_parser (2.0.3)
23
- rexml (3.2.4)
24
- rspec (3.9.0)
25
- rspec-core (~> 3.9.0)
26
- rspec-expectations (~> 3.9.0)
27
- rspec-mocks (~> 3.9.0)
28
- rspec-core (3.9.1)
29
- rspec-support (~> 3.9.1)
30
- rspec-expectations (3.9.0)
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.9.0)
33
- rspec-mocks (3.9.1)
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.9.0)
36
- rspec-support (3.9.2)
37
- rubocop (1.4.2)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.3)
37
+ rubocop (1.25.0)
38
38
  parallel (~> 1.10)
39
- parser (>= 2.7.1.5)
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.1)
43
+ rubocop-ast (>= 1.15.1, < 2.0)
44
44
  ruby-progressbar (~> 1.7)
45
- unicode-display_width (>= 1.4.0, < 2.0)
46
- rubocop-ast (1.4.0)
47
- parser (>= 2.7.1.5)
48
- rubocop-performance (1.9.1)
49
- rubocop (>= 0.90.0, < 2.0)
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 (0.10.2)
53
- rubocop (= 1.4.2)
54
- rubocop-performance (= 1.9.1)
55
- unicode-display_width (1.7.0)
56
- webmock (3.11.0)
57
- addressable (>= 2.3.6)
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.1.4
72
+ 2.2.15
data/README.md CHANGED
@@ -66,6 +66,25 @@ end
66
66
 
67
67
  ## Advanced Usage
68
68
 
69
+ ### Send API enhanced
70
+
71
+ ```ruby
72
+ client = Courier::Client.new "your-auth-token" # or set via COURIER_AUTH_TOKEN env var
73
+ res = client.send_message({
74
+ message => {
75
+ template => "my-template",
76
+ to => {
77
+ email => "foo@bar.com"
78
+ }
79
+ }
80
+ })
81
+ puts res.code # the HTTP response code
82
+ puts res.request_id # if the code is 202, this will be the Courier request ID for this message
83
+ rescue Courier::CourierAPIError => re #error sent from from the API
84
+ puts re.message
85
+ end
86
+ ```
87
+
69
88
  ### Lists
70
89
 
71
90
  ```ruby
@@ -7,7 +7,7 @@ module Courier
7
7
  end
8
8
 
9
9
  def create_job(message:, idempotency_key: nil, idempotency_expiry: nil)
10
- path = "#{KEY}"
10
+ path = KEY.to_s
11
11
  payload = {
12
12
  "message": message
13
13
  }
@@ -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
- class CourierAPIError < ResponseError; end
11
+
12
+ class CourierAPIError < ResponseError; end
11
13
 
12
14
  class ErrorHandler
13
15
  def self.check_err(res)
@@ -39,7 +39,7 @@ module Courier
39
39
  end
40
40
 
41
41
  def get_history(message_id:, type: nil)
42
- path ="#{KEY}/#{message_id}/history"
42
+ path = "#{KEY}/#{message_id}/history"
43
43
  params = {}
44
44
  if type
45
45
  params["type"] = type
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Courier
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/trycourier.rb CHANGED
@@ -23,6 +23,16 @@ module Courier
23
23
  end
24
24
  end
25
25
 
26
+ class SendMessageResponse
27
+ attr_reader :code
28
+ attr_reader :request_id
29
+
30
+ def initialize(code, request_id)
31
+ @code = code
32
+ @request_id = request_id
33
+ end
34
+ end
35
+
26
36
  class Client
27
37
  def initialize(auth_token = nil, username: nil, password: nil, base_url: nil)
28
38
  base = if base_url
@@ -55,15 +65,15 @@ module Courier
55
65
  end
56
66
 
57
67
  def send(body)
58
- if not body.is_a?(Hash)
68
+ if !body.is_a?(Hash)
59
69
  raise InputError, "Client#send must be passed a Hash as first argument."
60
- elsif body["event"] == nil && body[:event] == nil
70
+ elsif body["event"].nil? && body[:event].nil?
61
71
  raise InputError, "Must specify the 'event' key in Hash supplied to Client#send."
62
- elsif body["recipient"] == nil && body[:recipient] == nil
72
+ elsif body["recipient"].nil? && body[:recipient].nil?
63
73
  raise InputError, "Must specify the 'recipient' key in Hash supplied to Client#send."
64
- elsif (body["data"] != nil and not body["data"].is_a?(Hash)) || (body[:data] != nil and not body[:data].is_a?(Hash))
74
+ elsif (!body["data"].nil? && !body["data"].is_a?(Hash)) || (!body[:data].nil? && !body[:data].is_a?(Hash))
65
75
  raise InputError, "The 'data' key in the Hash supplied to Client#send must also be a Hash."
66
- elsif (body["profile"] != nil and not body["profile"].is_a?(Hash)) || (body[:profile] != nil and not body[:profile].is_a?(Hash))
76
+ elsif (!body["profile"].nil? && !body["profile"].is_a?(Hash)) || (!body[:profile].nil? && !body[:profile].is_a?(Hash))
67
77
  raise InputError, "The 'profile' key in the Hash supplied to Client#send must also be a Hash."
68
78
  end
69
79
 
@@ -81,6 +91,27 @@ module Courier
81
91
  end
82
92
  end
83
93
 
94
+ def send_message(body)
95
+ if !body.is_a?(Hash)
96
+ raise InputError, "Client#send_message must be passed a Hash as first argument."
97
+ elsif (!body["message"].nil? && !body["message"].is_a?(Hash)) || (!body[:message].nil? && !body[:message].is_a?(Hash))
98
+ raise InputError, "The 'message' key in the Hash supplied to Client#send_message must also be a Hash."
99
+ end
100
+
101
+ res = @session.send("/send", "POST", body: body)
102
+
103
+ code = res.code.to_i
104
+ obj = JSON.parse res.read_body
105
+
106
+ if code == 202
107
+ request_id = obj["requestId"]
108
+ SendMessageResponse.new(code, request_id)
109
+ elsif (message = obj["Message"].nil? ? obj["message"] : obj["Message"])
110
+ err = "#{code}: #{message}"
111
+ raise CourierAPIError, err
112
+ end
113
+ end
114
+
84
115
  # getters for all class variables
85
116
 
86
117
  attr_reader :session
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.3.0
4
+ version: 1.4.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-28 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec