trycourier 1.0.1 → 1.3.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 +49 -0
- data/CHANGELOG.md +93 -0
- data/CONTRIBUTING.md +28 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +39 -1
- data/README.md +364 -11
- data/Rakefile +2 -1
- data/lib/trycourier/automations.rb +67 -0
- data/lib/trycourier/brands.rb +70 -0
- data/lib/trycourier/bulk.rb +79 -0
- data/lib/trycourier/events.rb +35 -0
- data/lib/trycourier/exceptions.rb +37 -0
- data/lib/trycourier/lists.rb +109 -0
- data/lib/trycourier/messages.rb +51 -0
- data/lib/trycourier/profiles.rb +64 -0
- data/lib/trycourier/session.rb +81 -0
- data/lib/trycourier/version.rb +1 -1
- data/lib/trycourier.rb +62 -26
- data/trycourier.gemspec +15 -12
- metadata +45 -6
- data/.travis.yml +0 -6
data/lib/trycourier.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
require "trycourier/events"
|
2
|
+
require "trycourier/brands"
|
3
|
+
require "trycourier/lists"
|
4
|
+
require "trycourier/profiles"
|
5
|
+
require "trycourier/session"
|
6
|
+
require "trycourier/messages"
|
7
|
+
require "trycourier/automations"
|
8
|
+
require "trycourier/bulk"
|
1
9
|
require "trycourier/version"
|
10
|
+
require "trycourier/exceptions"
|
2
11
|
require "net/http"
|
3
12
|
require "json"
|
4
13
|
require "openssl"
|
5
14
|
|
6
15
|
module Courier
|
7
|
-
class ResponseError < StandardError; end
|
8
|
-
class InputError < StandardError; end
|
9
|
-
|
10
16
|
class SendResponse
|
11
17
|
attr_reader :code
|
12
18
|
attr_reader :message_id
|
@@ -18,49 +24,79 @@ module Courier
|
|
18
24
|
end
|
19
25
|
|
20
26
|
class Client
|
21
|
-
def initialize(auth_token = nil)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
def initialize(auth_token = nil, username: nil, password: nil, base_url: nil)
|
28
|
+
base = if base_url
|
29
|
+
base_url
|
30
|
+
elsif ENV["COURIER_BASE_URL"]
|
31
|
+
ENV["COURIER_BASE_URL"]
|
32
|
+
else
|
33
|
+
"https://api.courier.com"
|
34
|
+
end
|
35
|
+
|
36
|
+
@session = Courier::CourierAPISession.new(base)
|
37
|
+
|
38
|
+
if auth_token
|
39
|
+
@session.init_token_auth(auth_token)
|
40
|
+
elsif ENV["COURIER_AUTH_TOKEN"]
|
41
|
+
@session.init_token_auth(ENV["COURIER_AUTH_TOKEN"])
|
42
|
+
elsif username && password
|
43
|
+
@session.init_basic_auth(username, password)
|
44
|
+
elsif ENV["COURIER_AUTH_USERNAME"] && ENV["COURIER_AUTH_PASSWORD"]
|
45
|
+
@session.init_basic_auth(ENV["COURIER_AUTH_USERNAME"], ENV["COURIER_AUTH_PASSWORD"])
|
26
46
|
end
|
47
|
+
|
48
|
+
@messages = Courier::Messages.new(@session)
|
49
|
+
@profiles = Courier::Profiles.new(@session)
|
50
|
+
@lists = Courier::Lists.new(@session)
|
51
|
+
@events = Courier::Events.new(@session)
|
52
|
+
@brands = Courier::Brands.new(@session)
|
53
|
+
@automations = Courier::Automations.new(@session)
|
54
|
+
@bulk = Courier::Bulk.new(@session)
|
27
55
|
end
|
28
56
|
|
29
57
|
def send(body)
|
30
58
|
if not body.is_a?(Hash)
|
31
59
|
raise InputError, "Client#send must be passed a Hash as first argument."
|
32
|
-
elsif body["event"] == nil
|
60
|
+
elsif body["event"] == nil && body[:event] == nil
|
33
61
|
raise InputError, "Must specify the 'event' key in Hash supplied to Client#send."
|
34
|
-
elsif body["recipient"] == nil
|
62
|
+
elsif body["recipient"] == nil && body[:recipient] == nil
|
35
63
|
raise InputError, "Must specify the 'recipient' key in Hash supplied to Client#send."
|
36
|
-
elsif body["data"] != nil and not body["data"].is_a?(Hash)
|
64
|
+
elsif (body["data"] != nil and not body["data"].is_a?(Hash)) || (body[:data] != nil and not body[:data].is_a?(Hash))
|
37
65
|
raise InputError, "The 'data' key in the Hash supplied to Client#send must also be a Hash."
|
38
|
-
elsif body["profile"] != nil and not body["profile"].is_a?(Hash)
|
66
|
+
elsif (body["profile"] != nil and not body["profile"].is_a?(Hash)) || (body[:profile] != nil and not body[:profile].is_a?(Hash))
|
39
67
|
raise InputError, "The 'profile' key in the Hash supplied to Client#send must also be a Hash."
|
40
68
|
end
|
41
69
|
|
42
|
-
|
43
|
-
http.use_ssl = true
|
44
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
45
|
-
|
46
|
-
req = Net::HTTP::Post.new(@uri)
|
47
|
-
req["authorization"] = "Bearer #{@auth_token}"
|
48
|
-
req["content-type"] = "application/json"
|
49
|
-
req["User-Agent"] = "courier-ruby/#{Courier::VERSION}"
|
50
|
-
req.body = body.to_json
|
70
|
+
res = @session.send("/send", "POST", body: body)
|
51
71
|
|
52
|
-
res = http.request(req)
|
53
72
|
code = res.code.to_i
|
54
73
|
obj = JSON.parse res.read_body
|
55
74
|
|
56
75
|
if code == 200
|
57
76
|
message_id = obj["messageId"]
|
58
|
-
|
59
|
-
elsif
|
60
|
-
message = obj["Message"] == nil ? obj["message"] : obj["Message"]
|
77
|
+
SendResponse.new(code, message_id)
|
78
|
+
elsif (message = obj["Message"].nil? ? obj["message"] : obj["Message"])
|
61
79
|
err = "#{code}: #{message}"
|
62
|
-
raise
|
80
|
+
raise CourierAPIError, err
|
63
81
|
end
|
64
82
|
end
|
83
|
+
|
84
|
+
# getters for all class variables
|
85
|
+
|
86
|
+
attr_reader :session
|
87
|
+
|
88
|
+
attr_reader :messages
|
89
|
+
|
90
|
+
attr_reader :profiles
|
91
|
+
|
92
|
+
attr_reader :events
|
93
|
+
|
94
|
+
attr_reader :lists
|
95
|
+
|
96
|
+
attr_reader :brands
|
97
|
+
|
98
|
+
attr_reader :automations
|
99
|
+
|
100
|
+
attr_reader :bulk
|
65
101
|
end
|
66
102
|
end
|
data/trycourier.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "lib/trycourier/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name
|
5
|
-
spec.version
|
6
|
-
spec.authors
|
7
|
-
|
4
|
+
spec.name = "trycourier"
|
5
|
+
spec.version = Courier::VERSION
|
6
|
+
spec.authors = ["Courier"]
|
7
|
+
spec.email = ["support@courier.com"]
|
8
8
|
|
9
|
-
spec.summary
|
10
|
-
spec.description
|
11
|
-
spec.homepage
|
12
|
-
spec.license
|
9
|
+
spec.summary = "Wraps calls to the Courier REST API"
|
10
|
+
spec.description = "Courier is the smartest way to design & deliver notifications. Design your notifications once, deliver them to any channel through one API."
|
11
|
+
spec.homepage = "https://github.com/trycourier/courier-ruby"
|
12
|
+
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
14
|
|
15
15
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
@@ -20,10 +20,13 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
23
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
24
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
25
|
end
|
26
|
-
spec.bindir
|
27
|
-
spec.executables
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
31
|
+
spec.add_development_dependency "webmock", ">=1.24.2"
|
29
32
|
end
|
metadata
CHANGED
@@ -1,28 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trycourier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webmock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.24.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.24.2
|
13
41
|
description: Courier is the smartest way to design & deliver notifications. Design
|
14
42
|
your notifications once, deliver them to any channel through one API.
|
15
43
|
email:
|
16
|
-
- support@
|
44
|
+
- support@courier.com
|
17
45
|
executables: []
|
18
46
|
extensions: []
|
19
47
|
extra_rdoc_files: []
|
20
48
|
files:
|
21
49
|
- ".github/ISSUE_TEMPLATE.md"
|
22
50
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
51
|
+
- ".github/workflows/gem-push.yml"
|
23
52
|
- ".gitignore"
|
24
53
|
- ".rspec"
|
25
|
-
-
|
54
|
+
- CHANGELOG.md
|
55
|
+
- CONTRIBUTING.md
|
26
56
|
- Gemfile
|
27
57
|
- Gemfile.lock
|
28
58
|
- LICENSE
|
@@ -31,6 +61,15 @@ files:
|
|
31
61
|
- bin/console
|
32
62
|
- bin/setup
|
33
63
|
- lib/trycourier.rb
|
64
|
+
- lib/trycourier/automations.rb
|
65
|
+
- lib/trycourier/brands.rb
|
66
|
+
- lib/trycourier/bulk.rb
|
67
|
+
- lib/trycourier/events.rb
|
68
|
+
- lib/trycourier/exceptions.rb
|
69
|
+
- lib/trycourier/lists.rb
|
70
|
+
- lib/trycourier/messages.rb
|
71
|
+
- lib/trycourier/profiles.rb
|
72
|
+
- lib/trycourier/session.rb
|
34
73
|
- lib/trycourier/version.rb
|
35
74
|
- trycourier.gemspec
|
36
75
|
homepage: https://github.com/trycourier/courier-ruby
|
@@ -56,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
95
|
- !ruby/object:Gem::Version
|
57
96
|
version: '0'
|
58
97
|
requirements: []
|
59
|
-
rubygems_version: 3.1.
|
98
|
+
rubygems_version: 3.1.6
|
60
99
|
signing_key:
|
61
100
|
specification_version: 4
|
62
101
|
summary: Wraps calls to the Courier REST API
|