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 +4 -4
- data/.github/workflows/gem-push.yml +11 -9
- data/CHANGELOG.md +8 -1
- data/Gemfile.lock +36 -36
- data/README.md +19 -0
- data/lib/trycourier/bulk.rb +1 -1
- 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 +36 -5
- data/trycourier.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e2e7e6f4ad2900f3ad0d118062208c74492851e96976da6795c6309c95ad9ea
|
4
|
+
data.tar.gz: ce78409870df6608de59bc5ea4a628732b09f8d3ec7b304202f1721d07ff5836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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,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.
|
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
|
4
|
+
trycourier (1.4.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
@@ -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
|
data/lib/trycourier/bulk.rb
CHANGED
@@ -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
@@ -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
|
68
|
+
if !body.is_a?(Hash)
|
59
69
|
raise InputError, "Client#send must be passed a Hash as first argument."
|
60
|
-
elsif body["event"]
|
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"]
|
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"]
|
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"]
|
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.
|
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-
|
11
|
+
date: 2022-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|