eco-helpers 3.0.14 → 3.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -2
- data/eco-helpers.gemspec +15 -14
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +6 -0
- data/lib/eco/api/common/session/mailer/aws_provider.rb +85 -0
- data/lib/eco/api/common/session/mailer/provider_base.rb +61 -0
- data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +117 -0
- data/lib/eco/api/common/session/mailer.rb +42 -71
- data/lib/eco/api/session/batch/errors.rb +2 -2
- data/lib/eco/api/session/batch.rb +66 -28
- data/lib/eco/api/session/config/api.rb +96 -37
- data/lib/eco/api/session/config/apis/enviro_spaces.rb +106 -0
- data/lib/eco/api/session/config/apis/one_off.rb +94 -0
- data/lib/eco/api/session/config/apis/service_up.rb +37 -0
- data/lib/eco/api/session/config/apis/space_helpers.rb +41 -0
- data/lib/eco/api/session/config/apis.rb +81 -132
- data/lib/eco/api/session/config.rb +21 -3
- data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +19 -8
- data/lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +3 -7
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +6 -2
- data/lib/eco/cli/config/options_set.rb +10 -7
- data/lib/eco/cli/scripting/args_helpers.rb +18 -9
- data/lib/eco/cli_default/options.rb +8 -0
- data/lib/eco/cli_default/people.rb +3 -3
- data/lib/eco/language/basic_logger.rb +4 -2
- data/lib/eco/version.rb +1 -1
- metadata +37 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb3a3362dc59886aca4136df89d2fbaabc5fddceab410a52556eb0c01bea4357
|
4
|
+
data.tar.gz: b66f988b6cc4dc9d1123860835c5163a96f1315fc9b94c9950a4c68d13f23bf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 466af194495d8d185602b19ef32641123dccc29da95f0fd8347925112b510909061b613f49eeed986a25d25fbd9e319366f70fafa560247cfd889a04cde28c3c
|
7
|
+
data.tar.gz: 60c260b8c85efc6be8b695ecf0097f8dbc203b2162296848f9fe012f4fd0c9f4ebaa926ee55a0c2b59b6e7225274d6a2030f2e3433351d482d4bd25fd3bc700e
|
data/CHANGELOG.md
CHANGED
@@ -2,15 +2,34 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [3.0.
|
5
|
+
## [3.0.15] - 2024-10-01
|
6
6
|
|
7
7
|
### Added
|
8
8
|
|
9
|
+
- Support for **api** credential **spaces** (i.e. `uat`, etc.)
|
10
|
+
- `Eco::API::Session::Config::Api`
|
11
|
+
- `Eco::API::Session::Config::Apis`
|
12
|
+
|
9
13
|
### Changed
|
10
14
|
|
15
|
+
- moved default mailer provider to `SendGrid`
|
16
|
+
- upgrade core **gem** `ecoportal-api`
|
17
|
+
- chain `-batch-mode`
|
18
|
+
- `Eco::API::Session::Batch` print actual error message.
|
19
|
+
- `Eco::API::UseCases::GraphQL::Helpers::Base::ErrorHandling` to treat `exit` as its own category `exiting?`
|
20
|
+
- **Added** `exception?` method which is `true` if there was an `exception` or an `exit`
|
21
|
+
- `Eco::API::Session::Config#add_api`: added chaining capability via `add_space` method
|
22
|
+
- In a block it will use same params as root definition
|
23
|
+
- As a chained command, it will only define a new `space` for that enviro `name`
|
24
|
+
|
11
25
|
### Fixed
|
12
26
|
|
13
|
-
-
|
27
|
+
- `SCR#get_arg` when the option can be invoked in multiple ways
|
28
|
+
- `Eco::API::Session::Batch#offer_retry_on`
|
29
|
+
- Remove repetitive backtrace
|
30
|
+
- `Eco::API::UseCases::GraphQL::Samples::Location::Command::Service::TreeUpdate#email_digest` to include a bit of backtrace when there is an exception
|
31
|
+
- `Eco::API::UseCases::GraphQL::Samples::Location::Command::DSL#inputs`
|
32
|
+
- Moved **:error** `log` to only capture request errors alone.
|
14
33
|
|
15
34
|
## [3.0.13] - 2024-09-10
|
16
35
|
|
data/eco-helpers.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
lib = File.expand_path('lib', __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
|
-
require
|
5
|
+
require './lib/eco/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'eco-helpers'
|
9
9
|
spec.version = Eco::VERSION
|
10
10
|
spec.platform = Gem::Platform::RUBY
|
11
|
-
spec.authors = [
|
12
|
-
spec.email = [
|
11
|
+
spec.authors = ['Oscar Segura']
|
12
|
+
spec.email = ['oscar@ecoportal.co.nz']
|
13
13
|
|
14
14
|
spec.summary = "eco-helpers to manage people api cases"
|
15
15
|
spec.homepage = "https://www.ecoportal.com"
|
@@ -25,14 +25,14 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
#spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
27
|
#spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ['lib']
|
29
29
|
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
30
|
+
spec.add_development_dependency 'rake', '>= 13.0.3', '< 14'
|
31
|
+
spec.add_development_dependency 'redcarpet', '>= 3.6.0', '< 4'
|
32
|
+
spec.add_development_dependency 'rspec', '>= 3.12.0', '< 4'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 1'
|
34
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0'
|
35
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
36
36
|
|
37
37
|
spec.add_dependency 'amatch', '>= 0.4.1', '< 0.5'
|
38
38
|
spec.add_dependency 'aws-sdk-s3', '>= 1.142.0', '< 2'
|
@@ -40,9 +40,9 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_dependency 'bcrypt_pbkdf', '~> 1.0'
|
41
41
|
spec.add_dependency 'docx', '>= 0.8.0', '< 0.9'
|
42
42
|
spec.add_dependency 'dotenv', '~> 3'
|
43
|
-
spec.add_dependency 'ecoportal-api', '~> 0.10'
|
44
|
-
spec.add_dependency 'ecoportal-api-graphql', '~> 0.4',
|
45
|
-
spec.add_dependency 'ecoportal-api-v2', '~> 2.0',
|
43
|
+
spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.3'
|
44
|
+
spec.add_dependency 'ecoportal-api-graphql', '~> 0.4', '>= 0.4.2'
|
45
|
+
spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.10'
|
46
46
|
spec.add_dependency 'ed25519', '~> 1.2'
|
47
47
|
spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
|
48
48
|
spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
|
@@ -54,6 +54,7 @@ Gem::Specification.new do |spec|
|
|
54
54
|
spec.add_dependency 'roo', '>= 2.10.1', '< 2.11'
|
55
55
|
spec.add_dependency 'roo-xls', '>= 1.2.0', '< 1.3'
|
56
56
|
spec.add_dependency 'rubyzip', '>= 2.3.2', '< 2.4'
|
57
|
+
spec.add_dependency 'sendgrid-ruby', '~> 6.7.0'
|
57
58
|
end
|
58
59
|
|
59
60
|
# rubocop:enable Gemspec/DevelopmentDependencies
|
@@ -34,6 +34,7 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
34
34
|
return nil if blank?(value)
|
35
35
|
return value if value.is_a?(String)
|
36
36
|
return nil unless [Date, Time].any? {|type| value.is_a?(type)}
|
37
|
+
|
37
38
|
value&.strftime('%Y-%m-%d')
|
38
39
|
rescue TypeError, Date::Error
|
39
40
|
nil
|
@@ -42,6 +43,7 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
42
43
|
def date?(value)
|
43
44
|
return true if value.nil?
|
44
45
|
return true if value.to_s.strip.empty?
|
46
|
+
|
45
47
|
Date.parse(value)
|
46
48
|
true
|
47
49
|
rescue TypeError, Date::Error
|
@@ -51,11 +53,13 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
51
53
|
def valid_range?(date)
|
52
54
|
return true if date.nil?
|
53
55
|
return false unless min_date <= date
|
56
|
+
|
54
57
|
max_date >= date
|
55
58
|
end
|
56
59
|
|
57
60
|
def wrong!(value, attr:, desc: "Can't make a date out of")
|
58
61
|
return if wrong(attr).key?(value)
|
62
|
+
|
59
63
|
wrong(attr)[value] = value
|
60
64
|
log(:warn) { "#{desc} '#{value}' for '#{attr}'" }
|
61
65
|
nil
|
@@ -64,6 +68,7 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
64
68
|
def wrong(attr = nil)
|
65
69
|
@wrong ||= {}
|
66
70
|
return @wrong if attr.nil?
|
71
|
+
|
67
72
|
@wrong[attr] ||= {}
|
68
73
|
end
|
69
74
|
|
@@ -78,6 +83,7 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
78
83
|
def blank?(value)
|
79
84
|
return true if value.nil?
|
80
85
|
return true if value.to_s.strip.empty?
|
86
|
+
|
81
87
|
false
|
82
88
|
end
|
83
89
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# rubocop:disable Naming/MethodParameterName
|
2
|
+
module Eco
|
3
|
+
module API
|
4
|
+
module Common
|
5
|
+
module Session
|
6
|
+
class Mailer
|
7
|
+
class AwsProvider < ProviderBase
|
8
|
+
def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil)
|
9
|
+
ses.send_email(
|
10
|
+
destination: fetch_destination(to: to, cc: cc, bcc: bcc),
|
11
|
+
source: fetch_from,
|
12
|
+
message: {
|
13
|
+
subject: {
|
14
|
+
charset: "UTF-8",
|
15
|
+
data: subject
|
16
|
+
},
|
17
|
+
body: {
|
18
|
+
# NOTE: (html) will let you send html instead
|
19
|
+
# you can use both at once if you like
|
20
|
+
text: {
|
21
|
+
charset: "UTF-8",
|
22
|
+
data: body
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean] whether or not the mailer is configured for usage.
|
30
|
+
def configured?
|
31
|
+
fetch_access_key_id && fetch_secret_access_key && fetch_region
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def credentials
|
37
|
+
@credentials ||= {
|
38
|
+
id: 'AWS_ACCESS_KEY_ID',
|
39
|
+
key: 'AWS_SECRET_ACCESS_KEY'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def ses
|
44
|
+
require 'aws-sdk-ses'
|
45
|
+
@ses ||= Aws::SES::Client.new(
|
46
|
+
access_key_id: fetch_access_key_id,
|
47
|
+
secret_access_key: fetch_secret_access_key,
|
48
|
+
region: fetch_region
|
49
|
+
)
|
50
|
+
rescue StandardError => err
|
51
|
+
log(:error) {
|
52
|
+
"Trying to send an email with wrong email configuration: #{err}"
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def fetch_destination(to: nil, cc: nil, bcc: nil)
|
57
|
+
{
|
58
|
+
to_addresses: [fetch_to(to)].flatten.compact.uniq
|
59
|
+
}.tap do |dest|
|
60
|
+
cc = [cc].flatten.compact.uniq
|
61
|
+
bcc = [bcc].flatten.compact.uniq
|
62
|
+
dest.merge!(cc_addresses: cc) unless cc.empty?
|
63
|
+
dest.merge!(bcc_addresses: bcc) unless bcc.empty?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def fetch_region
|
68
|
+
config.mailer.region || ENV['AWS_REGION']
|
69
|
+
end
|
70
|
+
|
71
|
+
def fetch_server
|
72
|
+
config.mailer.server
|
73
|
+
end
|
74
|
+
|
75
|
+
def fetch_message_id_domain
|
76
|
+
config.mailer.message_id_domain
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# rubocop:enable Naming/MethodParameterName
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Session
|
5
|
+
class Mailer
|
6
|
+
class ProviderBase
|
7
|
+
class << self
|
8
|
+
def to_desc(to: nil, cc: nil, bcc: nil)
|
9
|
+
cc_to = [cc].flatten.compact.uniq
|
10
|
+
bcc_to = [bcc].flatten.compact.uniq
|
11
|
+
{ to_addresses: [to].flatten.compact.uniq }.tap do |dest|
|
12
|
+
dest.merge!(cc_addresses: cc_to) unless cc_to.empty?
|
13
|
+
dest.merge!(bcc_addresses: bcc_to) unless bcc_to.empty?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
include Eco::Language::AuxiliarLogger
|
19
|
+
|
20
|
+
attr_reader :config
|
21
|
+
|
22
|
+
def initialize(config, logger:)
|
23
|
+
@config = config
|
24
|
+
@logger = logger
|
25
|
+
end
|
26
|
+
|
27
|
+
def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil) # rubocop:disable Lint/UnusedMethodArgument
|
28
|
+
raise "You must implement this method"
|
29
|
+
end
|
30
|
+
|
31
|
+
def fetch_to(value = nil)
|
32
|
+
value || config.mailer.to
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def credentials
|
38
|
+
raise "You must implement this method"
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_from(value = nil)
|
42
|
+
value || config.mailer.from
|
43
|
+
end
|
44
|
+
|
45
|
+
def fetch_access_key_id
|
46
|
+
env_mail(:id) || config.mailer.access_key_id
|
47
|
+
end
|
48
|
+
|
49
|
+
def fetch_secret_access_key
|
50
|
+
env_mail(:key) || config.mailer.secret_access_key
|
51
|
+
end
|
52
|
+
|
53
|
+
def env_mail(prop)
|
54
|
+
ENV[credentials[prop]]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# rubocop:disable Naming/MethodParameterName
|
2
|
+
module Eco
|
3
|
+
module API
|
4
|
+
module Common
|
5
|
+
module Session
|
6
|
+
class Mailer
|
7
|
+
class SendgridProvider < ProviderBase
|
8
|
+
def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil)
|
9
|
+
return false unless sendgrid
|
10
|
+
|
11
|
+
data = to_data(
|
12
|
+
subject: subject,
|
13
|
+
body: body,
|
14
|
+
to: to,
|
15
|
+
cc: cc,
|
16
|
+
bcc: bcc
|
17
|
+
)
|
18
|
+
|
19
|
+
mailer._("send").post(request_body: data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_to(value = nil)
|
23
|
+
emails = [super].flatten.compact
|
24
|
+
to_email_model(emails)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Boolean] whether or not the mailer is configured for usage.
|
28
|
+
def configured?
|
29
|
+
fetch_secret_access_key
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def credentials
|
35
|
+
@credentials ||= {
|
36
|
+
id: 'SENDGRID_ACCESS_ID',
|
37
|
+
key: 'SENDGRID_ACCESS_KEY'
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_data(subject:, body:, to: nil, cc: nil, bcc: nil)
|
42
|
+
{
|
43
|
+
"personalizations" => [
|
44
|
+
{
|
45
|
+
"to" => fetch_to(to).flatten,
|
46
|
+
"subject" => subject
|
47
|
+
}.tap do |pers|
|
48
|
+
merge_if('cc', cc, target: pers)
|
49
|
+
merge_if('bcc', bcc, target: pers)
|
50
|
+
end
|
51
|
+
],
|
52
|
+
"from" => fetch_from,
|
53
|
+
"content" => [
|
54
|
+
{
|
55
|
+
"type" => "text/plain",
|
56
|
+
"value" => body
|
57
|
+
}
|
58
|
+
]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def mailer
|
63
|
+
@mailer ||= sendgrid&.client&.mail
|
64
|
+
end
|
65
|
+
|
66
|
+
def sendgrid
|
67
|
+
require 'sendgrid-ruby'
|
68
|
+
extend(::SendGrid) unless is_a?(SendGrid)
|
69
|
+
|
70
|
+
@sendgrid ||= SendGrid::API.new(
|
71
|
+
api_key: fetch_secret_access_key
|
72
|
+
)
|
73
|
+
rescue StandardError => err
|
74
|
+
log(:error) {
|
75
|
+
"Trying to send an email with wrong email configuration: #{err}"
|
76
|
+
}
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_email_model(value)
|
81
|
+
case value
|
82
|
+
when Array
|
83
|
+
value.map do |val|
|
84
|
+
to_email_model(val)
|
85
|
+
end.compact
|
86
|
+
else
|
87
|
+
return if value.to_s.strip.empty?
|
88
|
+
|
89
|
+
{
|
90
|
+
"email" => value
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def merge_if(key, data, target: {})
|
96
|
+
return if data.to_s.strip.empty?
|
97
|
+
|
98
|
+
key_data = to_email_model(data)
|
99
|
+
|
100
|
+
return if key_data.nil?
|
101
|
+
return if key_data.empty?
|
102
|
+
|
103
|
+
target.merge!({key.to_s => key_data})
|
104
|
+
end
|
105
|
+
|
106
|
+
def fetch_from(value = nil)
|
107
|
+
email = [super].flatten.compact.first
|
108
|
+
to_email_model(email)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# rubocop:enable Naming/MethodParameterName
|
@@ -1,4 +1,8 @@
|
|
1
1
|
# rubocop:disable Naming/MethodParameterName
|
2
|
+
|
3
|
+
require_relative 'mailer/provider_base'
|
4
|
+
require_relative 'mailer/aws_provider'
|
5
|
+
require_relative 'mailer/sendgrid_provider'
|
2
6
|
module Eco
|
3
7
|
module API
|
4
8
|
module Common
|
@@ -6,12 +10,17 @@ module Eco
|
|
6
10
|
class Mailer
|
7
11
|
include Eco::Language::AuxiliarLogger
|
8
12
|
|
13
|
+
DEFAULT_PROVIDER = :sendgrid
|
14
|
+
|
15
|
+
attr_reader :provider
|
16
|
+
|
9
17
|
# @param enviro [Eco::API::Common::Session::Environment]
|
10
|
-
def initialize(enviro:)
|
18
|
+
def initialize(enviro:, provider: DEFAULT_PROVIDER)
|
11
19
|
msg = "Required Environment object (enviro:). Given: #{enviro.class}"
|
12
20
|
raise msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
13
21
|
|
14
|
-
@enviro
|
22
|
+
@enviro = enviro
|
23
|
+
@provider = provider || DEFAULT_PROVIDER
|
15
24
|
end
|
16
25
|
|
17
26
|
# Sends an email
|
@@ -19,25 +28,27 @@ module Eco
|
|
19
28
|
# @param subject [String] subject of the email
|
20
29
|
# @param body [String] `html` or plain text message
|
21
30
|
def mail(subject:, body:, to: nil, cc: nil, bcc: nil)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
}
|
38
|
-
}
|
31
|
+
return false unless (serv = service)
|
32
|
+
|
33
|
+
unless serv.configured?
|
34
|
+
msg = "Mailer: You are missing configuration parameters "
|
35
|
+
msg << "for '#{provider}'. Review your .env file"
|
36
|
+
log(:error) { msg }
|
37
|
+
return false
|
38
|
+
end
|
39
|
+
|
40
|
+
serv.send_mail(
|
41
|
+
subject: subject,
|
42
|
+
body: body,
|
43
|
+
to: to,
|
44
|
+
cc: cc,
|
45
|
+
bcc: bcc
|
39
46
|
).tap do |response|
|
40
|
-
|
47
|
+
next unless response
|
48
|
+
|
49
|
+
to_addr = serv.fetch_to(to)
|
50
|
+
# msg = "Sent email (MessageId: #{response.message_id}) to #{fetch_destination(to: to, cc: cc, bcc: bcc)}"
|
51
|
+
msg = "Sent email #{ProviderBase.to_desc(to: to_addr, cc: cc, bcc: bcc)}"
|
41
52
|
puts msg
|
42
53
|
log(:debug) { msg }
|
43
54
|
end
|
@@ -45,21 +56,18 @@ module Eco
|
|
45
56
|
|
46
57
|
private
|
47
58
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
log(:
|
58
|
-
|
59
|
-
}
|
59
|
+
def service
|
60
|
+
case provider
|
61
|
+
when :aws
|
62
|
+
AwsProvider.new(config, logger: logger)
|
63
|
+
when :sendgrid
|
64
|
+
SendgridProvider.new(config, logger: logger)
|
65
|
+
else
|
66
|
+
msg = "Unknown mail provider '#{provider}'"
|
67
|
+
puts msg
|
68
|
+
log(:debug) { msg }
|
69
|
+
nil
|
60
70
|
end
|
61
|
-
|
62
|
-
@ses
|
63
71
|
end
|
64
72
|
|
65
73
|
def logger
|
@@ -69,43 +77,6 @@ module Eco
|
|
69
77
|
def config
|
70
78
|
@enviro.config || {}
|
71
79
|
end
|
72
|
-
|
73
|
-
def fetch_destination(to: nil, cc: nil, bcc: nil)
|
74
|
-
cc_to = [cc].flatten.compact.uniq
|
75
|
-
bcc_to = [bcc].flatten.compact.uniq
|
76
|
-
{ to_addresses: [fetch_to(to)].flatten }.tap do |dest|
|
77
|
-
dest.merge!(cc_addresses: cc_to) unless cc_to.empty?
|
78
|
-
dest.merge!(bcc_addresses: bcc_to) unless bcc_to.empty?
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def fetch_to(value = nil)
|
83
|
-
value || config.mailer.to
|
84
|
-
end
|
85
|
-
|
86
|
-
def fetch_from(value = nil)
|
87
|
-
value || config.mailer.from
|
88
|
-
end
|
89
|
-
|
90
|
-
def fetch_access_key_id
|
91
|
-
config.mailer.access_key_id || ENV['AWS_ACCESS_KEY_ID']
|
92
|
-
end
|
93
|
-
|
94
|
-
def fetch_secret_access_key
|
95
|
-
config.mailer.secret_access_key || ENV['AWS_SECRET_ACCESS_KEY']
|
96
|
-
end
|
97
|
-
|
98
|
-
def fetch_region
|
99
|
-
config.mailer.region || ENV['AWS_REGION']
|
100
|
-
end
|
101
|
-
|
102
|
-
def fetch_server
|
103
|
-
config.mailer.server
|
104
|
-
end
|
105
|
-
|
106
|
-
def fetch_message_id_domain
|
107
|
-
config.mailer.message_id_domain
|
108
|
-
end
|
109
80
|
end
|
110
81
|
end
|
111
82
|
end
|
@@ -116,7 +116,7 @@ module Eco
|
|
116
116
|
msgs = strs
|
117
117
|
|
118
118
|
if msgs.empty?
|
119
|
-
"There were no errors for the current batch '#{method}'!! ;)"
|
119
|
+
"There were no errors for the current batch '#{method}'!! ;) "
|
120
120
|
else
|
121
121
|
"There were #{msgs.length} errors:\n" + msgs.join("\n")
|
122
122
|
end
|
@@ -127,7 +127,7 @@ module Eco
|
|
127
127
|
|
128
128
|
if msgs.empty?
|
129
129
|
log(:info) {
|
130
|
-
"There were no errors for the current batch '#{method}'!! ;)"
|
130
|
+
"There were no errors for the current batch '#{method}'!! ;) "
|
131
131
|
}
|
132
132
|
else
|
133
133
|
msg = "There were #{msgs.length} errors:\n"
|