flowmailer_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +146 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flowmailer_rails.gemspec +40 -0
- data/lib/flowmailer_rails.rb +17 -0
- data/lib/flowmailer_rails/mail_converter.rb +43 -0
- data/lib/flowmailer_rails/mailer.rb +98 -0
- data/lib/flowmailer_rails/railtie.rb +9 -0
- data/lib/flowmailer_rails/version.rb +3 -0
- metadata +206 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b1b138e49c32a25c5acd356442942b9a42c38e55b4741b9b69206af53cab09b
|
4
|
+
data.tar.gz: 517ef17f387643e360448dcd27f968257f6f61606e6fed8ab24963cd44ac84a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3caf9173ee0bc60f66eb2b064a28d56ac68e2cf48af17644448680178ae76433c895c20adaa4bb63c7b992996f4f4560b7560bc9b4e6df9a6c7201661ad8da7
|
7
|
+
data.tar.gz: 9ea6b6bf40e79072b9ba7218fb8aaa32e52a5f03e93a9e31a5d01e6bc558173ba8835972d2dc43f9cf1f8eb6f9e782220b72b8098eb1a2f38d03eae6da800487
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at himynameisjonas@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flowmailer_rails (0.1.0)
|
5
|
+
actionmailer (>= 3.0.0)
|
6
|
+
faraday (>= 0.7.4, < 1.0)
|
7
|
+
faraday_middleware
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionmailer (6.0.3.4)
|
13
|
+
actionpack (= 6.0.3.4)
|
14
|
+
actionview (= 6.0.3.4)
|
15
|
+
activejob (= 6.0.3.4)
|
16
|
+
mail (~> 2.5, >= 2.5.4)
|
17
|
+
rails-dom-testing (~> 2.0)
|
18
|
+
actionpack (6.0.3.4)
|
19
|
+
actionview (= 6.0.3.4)
|
20
|
+
activesupport (= 6.0.3.4)
|
21
|
+
rack (~> 2.0, >= 2.0.8)
|
22
|
+
rack-test (>= 0.6.3)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
25
|
+
actionview (6.0.3.4)
|
26
|
+
activesupport (= 6.0.3.4)
|
27
|
+
builder (~> 3.1)
|
28
|
+
erubi (~> 1.4)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
31
|
+
activejob (6.0.3.4)
|
32
|
+
activesupport (= 6.0.3.4)
|
33
|
+
globalid (>= 0.3.6)
|
34
|
+
activesupport (6.0.3.4)
|
35
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
36
|
+
i18n (>= 0.7, < 2)
|
37
|
+
minitest (~> 5.1)
|
38
|
+
tzinfo (~> 1.1)
|
39
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
40
|
+
addressable (2.7.0)
|
41
|
+
public_suffix (>= 2.0.2, < 5.0)
|
42
|
+
ast (2.4.1)
|
43
|
+
builder (3.2.4)
|
44
|
+
concurrent-ruby (1.1.7)
|
45
|
+
crack (0.4.4)
|
46
|
+
crass (1.0.6)
|
47
|
+
diff-lcs (1.3)
|
48
|
+
docile (1.3.2)
|
49
|
+
erubi (1.10.0)
|
50
|
+
faraday (0.17.3)
|
51
|
+
multipart-post (>= 1.2, < 3)
|
52
|
+
faraday_middleware (0.14.0)
|
53
|
+
faraday (>= 0.7.4, < 1.0)
|
54
|
+
globalid (0.4.2)
|
55
|
+
activesupport (>= 4.2.0)
|
56
|
+
hashdiff (1.0.1)
|
57
|
+
i18n (1.8.5)
|
58
|
+
concurrent-ruby (~> 1.0)
|
59
|
+
loofah (2.7.0)
|
60
|
+
crass (~> 1.0.2)
|
61
|
+
nokogiri (>= 1.5.9)
|
62
|
+
mail (2.7.1)
|
63
|
+
mini_mime (>= 0.1.1)
|
64
|
+
mini_mime (1.0.2)
|
65
|
+
mini_portile2 (2.4.0)
|
66
|
+
minitest (5.14.2)
|
67
|
+
multipart-post (2.1.1)
|
68
|
+
nokogiri (1.10.10)
|
69
|
+
mini_portile2 (~> 2.4.0)
|
70
|
+
parallel (1.20.0)
|
71
|
+
parser (2.7.2.0)
|
72
|
+
ast (~> 2.4.1)
|
73
|
+
public_suffix (4.0.6)
|
74
|
+
rack (2.2.3)
|
75
|
+
rack-test (1.1.0)
|
76
|
+
rack (>= 1.0, < 3)
|
77
|
+
rails-dom-testing (2.0.3)
|
78
|
+
activesupport (>= 4.2.0)
|
79
|
+
nokogiri (>= 1.6)
|
80
|
+
rails-html-sanitizer (1.3.0)
|
81
|
+
loofah (~> 2.3)
|
82
|
+
rainbow (3.0.0)
|
83
|
+
rake (13.0.1)
|
84
|
+
regexp_parser (1.8.2)
|
85
|
+
rexml (3.2.4)
|
86
|
+
rspec (3.9.0)
|
87
|
+
rspec-core (~> 3.9.0)
|
88
|
+
rspec-expectations (~> 3.9.0)
|
89
|
+
rspec-mocks (~> 3.9.0)
|
90
|
+
rspec-core (3.9.1)
|
91
|
+
rspec-support (~> 3.9.1)
|
92
|
+
rspec-expectations (3.9.0)
|
93
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
94
|
+
rspec-support (~> 3.9.0)
|
95
|
+
rspec-json_expectations (2.2.0)
|
96
|
+
rspec-mocks (3.9.1)
|
97
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
98
|
+
rspec-support (~> 3.9.0)
|
99
|
+
rspec-support (3.9.2)
|
100
|
+
rubocop (0.91.1)
|
101
|
+
parallel (~> 1.10)
|
102
|
+
parser (>= 2.7.1.1)
|
103
|
+
rainbow (>= 2.2.2, < 4.0)
|
104
|
+
regexp_parser (>= 1.7)
|
105
|
+
rexml
|
106
|
+
rubocop-ast (>= 0.4.0, < 1.0)
|
107
|
+
ruby-progressbar (~> 1.7)
|
108
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
109
|
+
rubocop-ast (0.8.0)
|
110
|
+
parser (>= 2.7.1.5)
|
111
|
+
rubocop-performance (1.8.1)
|
112
|
+
rubocop (>= 0.87.0)
|
113
|
+
rubocop-ast (>= 0.4.0)
|
114
|
+
ruby-progressbar (1.10.1)
|
115
|
+
simplecov (0.19.1)
|
116
|
+
docile (~> 1.1)
|
117
|
+
simplecov-html (~> 0.11)
|
118
|
+
simplecov-html (0.12.3)
|
119
|
+
standard (0.6.2)
|
120
|
+
rubocop (= 0.91.1)
|
121
|
+
rubocop-performance (= 1.8.1)
|
122
|
+
thread_safe (0.3.6)
|
123
|
+
tzinfo (1.2.8)
|
124
|
+
thread_safe (~> 0.1)
|
125
|
+
unicode-display_width (1.7.0)
|
126
|
+
webmock (3.10.0)
|
127
|
+
addressable (>= 2.3.6)
|
128
|
+
crack (>= 0.3.2)
|
129
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
130
|
+
zeitwerk (2.4.1)
|
131
|
+
|
132
|
+
PLATFORMS
|
133
|
+
ruby
|
134
|
+
|
135
|
+
DEPENDENCIES
|
136
|
+
bundler (~> 2.0)
|
137
|
+
flowmailer_rails!
|
138
|
+
rake (~> 13.0)
|
139
|
+
rspec (~> 3.0)
|
140
|
+
rspec-json_expectations (~> 2.2)
|
141
|
+
simplecov (~> 0.19)
|
142
|
+
standard (~> 0.6.1)
|
143
|
+
webmock (~> 3.10.0)
|
144
|
+
|
145
|
+
BUNDLED WITH
|
146
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jonas Brusman
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# FlowmailerRails
|
2
|
+
|
3
|
+
Send ActionMailer emails with Flowmailer
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'flowmailer_rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install FlowmailerRails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
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).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/teamtailor/flowmailer_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the FlowmailerRails project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/teamtailor/flowmailer_rails/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flowmailer_rails"
|
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
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "flowmailer_rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "flowmailer_rails"
|
7
|
+
spec.version = FlowmailerRails::VERSION
|
8
|
+
spec.authors = ["Jonas Brusman"]
|
9
|
+
spec.email = ["jonas@teamtailor.com"]
|
10
|
+
|
11
|
+
spec.summary = "ActionMailer adapter for Flowmailer"
|
12
|
+
spec.description = "Send ActionMailer messages with the Flowmailer API"
|
13
|
+
spec.homepage = "https://github.com/Teamtailor/flowmailer_rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/Teamtailor/flowmailer_rails"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/Teamtailor/flowmailer_rails/blob/master/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.start_with?(".") }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency("actionmailer", ">= 3.0.0")
|
30
|
+
spec.add_dependency("faraday", ">= 0.7.4", "< 1.0")
|
31
|
+
spec.add_dependency("faraday_middleware")
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "rspec-json_expectations", "~> 2.2"
|
37
|
+
spec.add_development_dependency "simplecov", "~> 0.19"
|
38
|
+
spec.add_development_dependency "webmock", "~> 3.10.0"
|
39
|
+
spec.add_development_dependency "standard", "~> 0.6.1"
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "action_mailer"
|
2
|
+
require "flowmailer_rails/mailer"
|
3
|
+
require "flowmailer_rails/mail_converter"
|
4
|
+
|
5
|
+
module FlowmailerRails
|
6
|
+
def self.install
|
7
|
+
ActionMailer::Base.add_delivery_method :flowmailer, FlowmailerRails::Mailer
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# :nocov:
|
12
|
+
if defined?(Rails)
|
13
|
+
require "flowmailer_rails/railtie"
|
14
|
+
else
|
15
|
+
FlowmailerRails.install
|
16
|
+
end
|
17
|
+
# :nocov:
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module FlowmailerRails
|
4
|
+
class MailConverter
|
5
|
+
attr_reader :rails_mail
|
6
|
+
|
7
|
+
def initialize(rails_mail)
|
8
|
+
@rails_mail = rails_mail
|
9
|
+
end
|
10
|
+
|
11
|
+
def recipients_as_json
|
12
|
+
recipient_addresses.map do |recipient|
|
13
|
+
JSON.dump(as_json.merge(recipientAddress: recipient))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def as_json
|
20
|
+
@json ||= {
|
21
|
+
messageType: "EMAIL",
|
22
|
+
mimedata: mimedata,
|
23
|
+
senderAddress: sender_address
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def mimedata
|
28
|
+
Base64.encode64(rails_mail.to_s)
|
29
|
+
end
|
30
|
+
|
31
|
+
def sender_address
|
32
|
+
Mail::Address.new(
|
33
|
+
rails_mail.from_addrs.first
|
34
|
+
).address
|
35
|
+
end
|
36
|
+
|
37
|
+
def recipient_addresses
|
38
|
+
(rails_mail.to_addrs | rails_mail.cc_addrs | rails_mail.bcc_addrs).map do |address|
|
39
|
+
Mail::Address.new(address).address
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
|
4
|
+
module FlowmailerRails
|
5
|
+
class Mailer
|
6
|
+
class NoAccessTokenError < StandardError; end
|
7
|
+
class DeliveryError < StandardError; end
|
8
|
+
class ExpiredAccessTokenError < StandardError; end
|
9
|
+
|
10
|
+
OAUTH_ENDPOINT = "https://login.flowmailer.net".freeze
|
11
|
+
API_ENDPOINT = "https://api.flowmailer.net".freeze
|
12
|
+
|
13
|
+
attr_accessor :settings
|
14
|
+
|
15
|
+
def initialize(values)
|
16
|
+
self.settings = {}.merge!(values)
|
17
|
+
end
|
18
|
+
|
19
|
+
def deliver!(rails_mail)
|
20
|
+
MailConverter.new(rails_mail).recipients_as_json.each do |json|
|
21
|
+
response = submit_message(json)
|
22
|
+
rails_mail.message_id = response.headers["location"].split("/").last
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def path
|
29
|
+
"#{settings[:account_id]}/messages/submit"
|
30
|
+
end
|
31
|
+
|
32
|
+
def authorization_header
|
33
|
+
{Authorization: "Bearer #{access_token}"}
|
34
|
+
end
|
35
|
+
|
36
|
+
def submit_message(json)
|
37
|
+
retries = 0
|
38
|
+
begin
|
39
|
+
response = api_client.post(path, json, authorization_header)
|
40
|
+
|
41
|
+
raise ExpiredAccessTokenError if response.status == 401
|
42
|
+
raise DeliveryError, response.body unless response.success?
|
43
|
+
rescue ExpiredAccessTokenError
|
44
|
+
if (retries += 1) <= 3
|
45
|
+
fetch_new_access_token
|
46
|
+
retry
|
47
|
+
else
|
48
|
+
raise
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
response
|
53
|
+
end
|
54
|
+
|
55
|
+
def api_client
|
56
|
+
@api_client ||= Faraday.new(url: API_ENDPOINT) { |conn|
|
57
|
+
conn.request :json
|
58
|
+
conn.response :json, content_type: /\bjson$/
|
59
|
+
conn.adapter Faraday.default_adapter
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def access_token
|
64
|
+
if settings[:access_token]
|
65
|
+
settings[:access_token].call
|
66
|
+
else
|
67
|
+
@access_token ||= fetch_new_access_token
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def fetch_new_access_token
|
72
|
+
if settings[:fetch_new_access_token]
|
73
|
+
settings[:fetch_new_access_token].call
|
74
|
+
else
|
75
|
+
response = oauth_client.post(
|
76
|
+
"oauth/token",
|
77
|
+
client_id: settings[:client_id],
|
78
|
+
client_secret: settings[:client_secret],
|
79
|
+
grant_type: "client_credentials",
|
80
|
+
scope: "api"
|
81
|
+
)
|
82
|
+
if response.success?
|
83
|
+
@access_token = response.body["access_token"]
|
84
|
+
else
|
85
|
+
raise NoAccessTokenError, response.body
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def oauth_client
|
91
|
+
@oauth_client ||= Faraday.new(url: OAUTH_ENDPOINT) { |conn|
|
92
|
+
conn.request :url_encoded
|
93
|
+
conn.response :json, content_type: /\bjson$/
|
94
|
+
conn.adapter Faraday.default_adapter
|
95
|
+
}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flowmailer_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Brusman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionmailer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.4
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '1.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.7.4
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: faraday_middleware
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '13.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '13.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec-json_expectations
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.2'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '2.2'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: simplecov
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.19'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.19'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: webmock
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 3.10.0
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 3.10.0
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: standard
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 0.6.1
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 0.6.1
|
159
|
+
description: Send ActionMailer messages with the Flowmailer API
|
160
|
+
email:
|
161
|
+
- jonas@teamtailor.com
|
162
|
+
executables: []
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- CODE_OF_CONDUCT.md
|
167
|
+
- Gemfile
|
168
|
+
- Gemfile.lock
|
169
|
+
- LICENSE.txt
|
170
|
+
- README.md
|
171
|
+
- Rakefile
|
172
|
+
- bin/console
|
173
|
+
- bin/setup
|
174
|
+
- flowmailer_rails.gemspec
|
175
|
+
- lib/flowmailer_rails.rb
|
176
|
+
- lib/flowmailer_rails/mail_converter.rb
|
177
|
+
- lib/flowmailer_rails/mailer.rb
|
178
|
+
- lib/flowmailer_rails/railtie.rb
|
179
|
+
- lib/flowmailer_rails/version.rb
|
180
|
+
homepage: https://github.com/Teamtailor/flowmailer_rails
|
181
|
+
licenses:
|
182
|
+
- MIT
|
183
|
+
metadata:
|
184
|
+
homepage_uri: https://github.com/Teamtailor/flowmailer_rails
|
185
|
+
source_code_uri: https://github.com/Teamtailor/flowmailer_rails
|
186
|
+
changelog_uri: https://github.com/Teamtailor/flowmailer_rails/blob/master/CHANGELOG.md
|
187
|
+
post_install_message:
|
188
|
+
rdoc_options: []
|
189
|
+
require_paths:
|
190
|
+
- lib
|
191
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
requirements: []
|
202
|
+
rubygems_version: 3.0.3
|
203
|
+
signing_key:
|
204
|
+
specification_version: 4
|
205
|
+
summary: ActionMailer adapter for Flowmailer
|
206
|
+
test_files: []
|