trycourier 1.0.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 +7 -0
- data/.github/ISSUE_TEMPLATE.md +17 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +27 -0
- data/.gitignore +67 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/trycourier.rb +62 -0
- data/lib/trycourier/version.rb +3 -0
- data/trycourier.gemspec +29 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c5fd74b5fd13d1df8a4a0eb4dbdf51d81fa18296a511e40c7cff04cd6b071e73
|
4
|
+
data.tar.gz: '096936274e4e4136493b0647683ad82b07b05848dc5e43e26b66b685713355a8'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d87355c131b45bc5a7a5d14f1669c0013448d01e7c24ce69874917d96324d0682e21072f4f36bb82bd0a004300767f3c5d3d3c1eba13e6bd161ea2c4f5bb1411
|
7
|
+
data.tar.gz: ecc59711579d942524e99d478755206940a1cc372ef4b2affdc7bd7eb31b5cbcbd2021fc61e3f5ac443e2e2524751c34d57b58a5b72c46723363ad7e453d48bf
|
@@ -0,0 +1,27 @@
|
|
1
|
+
## Description of the change
|
2
|
+
|
3
|
+
> Description here
|
4
|
+
|
5
|
+
## Type of change
|
6
|
+
- [ ] Bug fix (non-breaking change that fixes an issue)
|
7
|
+
- [ ] New feature (non-breaking change that adds functionality)
|
8
|
+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
9
|
+
|
10
|
+
## Related issues
|
11
|
+
|
12
|
+
> Fix [#1]()
|
13
|
+
|
14
|
+
## Checklists
|
15
|
+
|
16
|
+
### Development
|
17
|
+
|
18
|
+
- [ ] Lint rules pass locally
|
19
|
+
- [ ] The code changed/added as part of this pull request has been covered with tests
|
20
|
+
- [ ] All tests related to the changed code pass in development
|
21
|
+
|
22
|
+
### Code review
|
23
|
+
|
24
|
+
- [ ] This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
|
25
|
+
- [ ] "Ready for review" label attached to the PR and reviewers mentioned in a comment
|
26
|
+
- [ ] Changes have been reviewed by at least one other engineer
|
27
|
+
- [ ] Issue from task tracker has a link to this pull request
|
data/.gitignore
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
# via bundle gem <FOO>
|
59
|
+
/.bundle/
|
60
|
+
/.yardoc
|
61
|
+
/_yardoc/
|
62
|
+
/coverage/
|
63
|
+
/doc/
|
64
|
+
/pkg/
|
65
|
+
/spec/reports/
|
66
|
+
/tmp/
|
67
|
+
.rspec_status
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
trycourier (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (12.3.3)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.1)
|
16
|
+
rspec-support (~> 3.9.1)
|
17
|
+
rspec-expectations (3.9.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
rake (~> 12.0)
|
30
|
+
rspec (~> 3.0)
|
31
|
+
trycourier!
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Courier
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# `trycourier`
|
2
|
+
|
3
|
+
This Gem helps you send notifications through [Courier](https://www.trycourier.com/), the smartest way to design & deliver notifications. Design your notifications once using our drag & drop editor, then deliver to any channel through one API. Email, mobile push, SMS, Slack — you name it!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'trycourier'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install trycourier
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "trycourier"
|
25
|
+
|
26
|
+
begin
|
27
|
+
client = Courier::Client.new ApiKey
|
28
|
+
res = client.send({
|
29
|
+
"event" => Event,
|
30
|
+
"recipient" => Recipient,
|
31
|
+
"data" => {
|
32
|
+
"world" => "Ruby!"
|
33
|
+
}
|
34
|
+
})
|
35
|
+
|
36
|
+
puts res.code # the HTTP response code
|
37
|
+
puts res.message_id # if 200, this will be the Courier message ID for this notification
|
38
|
+
rescue Courier::ResponseError => re
|
39
|
+
puts re.message
|
40
|
+
rescue Courier::InputError => ie
|
41
|
+
puts ie.message
|
42
|
+
end
|
43
|
+
|
44
|
+
```
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
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.
|
49
|
+
|
50
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/trycourier.
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "trycourier"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/trycourier.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "trycourier/version"
|
2
|
+
require "net/http"
|
3
|
+
require "json"
|
4
|
+
require "openssl"
|
5
|
+
|
6
|
+
module Courier
|
7
|
+
class ResponseError < StandardError; end
|
8
|
+
class InputError < StandardError; end
|
9
|
+
|
10
|
+
class SendResponse
|
11
|
+
attr_reader :code
|
12
|
+
attr_reader :message_id
|
13
|
+
|
14
|
+
def initialize(code, message_id)
|
15
|
+
@code = code
|
16
|
+
@message_id = message_id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Client
|
21
|
+
def initialize(api_key)
|
22
|
+
@api_key = api_key
|
23
|
+
@uri = URI.parse('https://api.trycourier.app/send')
|
24
|
+
end
|
25
|
+
|
26
|
+
def send(body)
|
27
|
+
if not body.is_a?(Hash)
|
28
|
+
raise InputError, "Client#send must be passed a Hash as first argument."
|
29
|
+
elsif body["event"] == nil
|
30
|
+
raise InputError, "Must specify the 'event' key in Hash supplied to Client#send."
|
31
|
+
elsif body["recipient"] == nil
|
32
|
+
raise InputError, "Must specify the 'recipient' key in Hash supplied to Client#send."
|
33
|
+
elsif body["data"] != nil and not body["data"].is_a?(Hash)
|
34
|
+
raise InputError, "The 'data' key in the Hash supplied to Client#send must also be a Hash."
|
35
|
+
elsif body["profile"] != nil and not body["profile"].is_a?(Hash)
|
36
|
+
raise InputError, "The 'profile' key in the Hash supplied to Client#send must also be a Hash."
|
37
|
+
end
|
38
|
+
|
39
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
40
|
+
http.use_ssl = true
|
41
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
42
|
+
|
43
|
+
req = Net::HTTP::Post.new(@uri)
|
44
|
+
req["authorization"] = "Bearer #{@api_key}"
|
45
|
+
req["content-type"] = "application/json"
|
46
|
+
req.body = body.to_json
|
47
|
+
|
48
|
+
res = http.request(req)
|
49
|
+
code = res.code.to_i
|
50
|
+
obj = JSON.parse res.read_body
|
51
|
+
|
52
|
+
if code == 200
|
53
|
+
message_id = obj["messageId"]
|
54
|
+
return SendResponse.new(code, message_id)
|
55
|
+
elsif
|
56
|
+
message = obj["Message"] == nil ? obj["message"] : obj["Message"]
|
57
|
+
err = "#{code}: #{message}"
|
58
|
+
raise ResponseError, err
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/trycourier.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/trycourier/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "trycourier"
|
5
|
+
spec.version = Courier::VERSION
|
6
|
+
spec.authors = ["Courier"]
|
7
|
+
spec.email = ["support@trycourier.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Wraps calls to the Courier REST API}
|
10
|
+
spec.description = %q{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
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trycourier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Courier
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Courier is the smartest way to design & deliver notifications. Design
|
14
|
+
your notifications once, deliver them to any channel through one API.
|
15
|
+
email:
|
16
|
+
- support@trycourier.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".github/ISSUE_TEMPLATE.md"
|
22
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
23
|
+
- ".gitignore"
|
24
|
+
- ".rspec"
|
25
|
+
- ".travis.yml"
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- bin/console
|
32
|
+
- bin/setup
|
33
|
+
- lib/trycourier.rb
|
34
|
+
- lib/trycourier/version.rb
|
35
|
+
- trycourier.gemspec
|
36
|
+
homepage: https://github.com/trycourier/courier-ruby
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
allowed_push_host: https://rubygems.org
|
41
|
+
homepage_uri: https://github.com/trycourier/courier-ruby
|
42
|
+
source_code_uri: https://github.com/trycourier/courier-ruby
|
43
|
+
changelog_uri: https://github.com/trycourier/courier-ruby
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.3.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.1.2
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Wraps calls to the Courier REST API
|
63
|
+
test_files: []
|