bmc 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/app/jobs/bmc/application_job.rb +2 -0
- data/app/sms/bmc/sms/deliver_job.rb +5 -0
- data/app/sms/bmc/sms/message.rb +2 -12
- data/app/sms/bmc/sms/strategies/amazon.rb +38 -0
- data/app/sms/bmc/sms/strategies/test.rb +2 -2
- data/app/sms/bmc/sms.rb +1 -25
- data/lib/bmc/config.rb +9 -0
- data/lib/bmc/engine.rb +0 -1
- data/lib/bmc/version.rb +1 -1
- metadata +5 -4
- data/app/sms/bmc/sms/strategies/amazon_sns.rb +0 -48
- data/app/sms/bmc/sms/strategies/base.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 610c3313a3499ea6c4b1ab3b3d801ee892cfcce32e5adacf8b935a2032506f71
|
4
|
+
data.tar.gz: 0db6265466d7b9f388b2a73b299b51b138fde69c89b08a67f8bc9fb67cef405d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc8116f3b1beff954b12fe0558aa3023172f5e8720316b8dd3f851b60258f774a2d002fd72c84a5fbe1f65c3c6761c967bef7e38f32e5a79c61625fe6e9fd36
|
7
|
+
data.tar.gz: 915fe7c88c4c6d7b201a9a8b70482207cf6f2b55a80222602825ebf33ceae0ebf0a0f0bf38dfe8d4781de2d20e40ff09b6b0ea32c5bec05c03afd9a480d9c4ce
|
data/CHANGELOG.md
CHANGED
data/app/sms/bmc/sms/message.rb
CHANGED
@@ -5,21 +5,11 @@ class BMC::SMS::Message
|
|
5
5
|
@data = data
|
6
6
|
end
|
7
7
|
|
8
|
-
def strategy=(value)
|
9
|
-
@strategy = BMC::SMS.parse_strategy(value)
|
10
|
-
end
|
11
|
-
|
12
|
-
def strategy(value = :no_argument)
|
13
|
-
self.strategy = value unless value == :no_argument
|
14
|
-
@strategy || BMC::SMS.strategy
|
15
|
-
end
|
16
|
-
|
17
8
|
def deliver_now
|
18
|
-
|
9
|
+
BMC::SMS::DeliverJob.perform_now(data)
|
19
10
|
end
|
20
11
|
|
21
|
-
# TODO : Delay
|
22
12
|
def deliver_later
|
23
|
-
|
13
|
+
BMC::SMS::DeliverJob.perform_later(data)
|
24
14
|
end
|
25
15
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class BMC::SMS::Strategies::Amazon
|
2
|
+
attr_reader :region, :access_key_id, :secret_access_key
|
3
|
+
|
4
|
+
# rubocop:disable Layout/LineLength
|
5
|
+
def initialize(region: nil, access_key_id: nil, secret_access_key: nil)
|
6
|
+
@region = region || ENV["SNS_REGION"] || ENV["AWS_REGION"]
|
7
|
+
@access_key_id = access_key_id || ENV["SNS_ACCESS_KEY_ID"] || ENV["AWS_ACCESS_KEY_ID"]
|
8
|
+
@secret_access_key = secret_access_key || ENV["SNS_SECRET_ACCESS_KEY"] || ENV["AWS_SECRET_ACCESS_KEY"]
|
9
|
+
end
|
10
|
+
# rubocop:enable Layout/LineLength
|
11
|
+
|
12
|
+
def client
|
13
|
+
@client ||= Aws::SNS::Client.new(
|
14
|
+
:region => region,
|
15
|
+
:access_key_id => access_key_id,
|
16
|
+
:secret_access_key => secret_access_key,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(data)
|
21
|
+
from = data[:from] || BMC::SMS.default_from
|
22
|
+
|
23
|
+
client.publish(
|
24
|
+
:phone_number => data[:to],
|
25
|
+
:message => data[:body],
|
26
|
+
:message_attributes => {
|
27
|
+
"AWS.SNS.SMS.SenderID" => {
|
28
|
+
:data_type => "String",
|
29
|
+
:string_value => from,
|
30
|
+
},
|
31
|
+
"AWS.SNS.SMS.SMSType" => {
|
32
|
+
:data_type => "String",
|
33
|
+
:string_value => "Transactional",
|
34
|
+
},
|
35
|
+
},
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class BMC::SMS::Strategies::Test
|
1
|
+
class BMC::SMS::Strategies::Test
|
2
2
|
def self.deliveries
|
3
3
|
@deliveries ||= []
|
4
4
|
end
|
5
5
|
|
6
|
-
def call
|
6
|
+
def call(data)
|
7
7
|
self.class.deliveries << data
|
8
8
|
Rails.logger.info "New SMS sent : #{data.inspect}"
|
9
9
|
end
|
data/app/sms/bmc/sms.rb
CHANGED
@@ -1,35 +1,11 @@
|
|
1
1
|
module BMC::SMS
|
2
2
|
class << self
|
3
|
-
|
4
|
-
@strategy = parse_strategy(value)
|
5
|
-
end
|
6
|
-
|
7
|
-
def strategy
|
8
|
-
@strategy ||= default_strategy
|
9
|
-
end
|
3
|
+
attr_accessor :strategy
|
10
4
|
|
11
5
|
attr_writer :default_from
|
12
6
|
|
13
7
|
def default_from
|
14
8
|
@default_from ||= Rails.application.class.to_s.chomp("::Application")
|
15
9
|
end
|
16
|
-
|
17
|
-
def parse_strategy(value)
|
18
|
-
if value.is_a?(Symbol)
|
19
|
-
"BMC::SMS::Strategies::#{value.to_s.camelcase}".constantize
|
20
|
-
else
|
21
|
-
value
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def default_strategy
|
28
|
-
if Rails.env.development? || Rails.env.test?
|
29
|
-
BMC::SMS::Strategies::Test
|
30
|
-
else
|
31
|
-
BMC::SMS::Strategies::AmazonSNS
|
32
|
-
end
|
33
|
-
end
|
34
10
|
end # class << self
|
35
11
|
end
|
data/lib/bmc/config.rb
CHANGED
@@ -8,6 +8,15 @@ class << BMC
|
|
8
8
|
].map(&:safe_constantize).compact.first
|
9
9
|
end
|
10
10
|
|
11
|
+
attr_writer :parent_job
|
12
|
+
|
13
|
+
def parent_job
|
14
|
+
@parent_job ||= [
|
15
|
+
"ApplicationJob",
|
16
|
+
"ActiveJob::Base",
|
17
|
+
].map(&:safe_constantize).compact.first
|
18
|
+
end
|
19
|
+
|
11
20
|
attr_writer :parent_mailer
|
12
21
|
|
13
22
|
def parent_mailer
|
data/lib/bmc/engine.rb
CHANGED
data/lib/bmc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agilidée
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails-i18n
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- app/helpers/bmc/sorting_helper.rb
|
148
148
|
- app/helpers/bmc/text_helper.rb
|
149
149
|
- app/helpers/h.rb
|
150
|
+
- app/jobs/bmc/application_job.rb
|
150
151
|
- app/jobs/concerns/bmc/setup_job_concern.rb
|
151
152
|
- app/libs/bmc/collection_update.rb
|
152
153
|
- app/libs/bmc/fcm/notifier.rb
|
@@ -172,9 +173,9 @@ files:
|
|
172
173
|
- app/serializers/bmc/serializers/xlsx.rb
|
173
174
|
- app/sms/bmc/sms.rb
|
174
175
|
- app/sms/bmc/sms/application_sms.rb
|
176
|
+
- app/sms/bmc/sms/deliver_job.rb
|
175
177
|
- app/sms/bmc/sms/message.rb
|
176
|
-
- app/sms/bmc/sms/strategies/
|
177
|
-
- app/sms/bmc/sms/strategies/base.rb
|
178
|
+
- app/sms/bmc/sms/strategies/amazon.rb
|
178
179
|
- app/sms/bmc/sms/strategies/test.rb
|
179
180
|
- app/sorters/bmc/sorter.rb
|
180
181
|
- app/views/bmc/search/_form.html.slim
|
@@ -1,48 +0,0 @@
|
|
1
|
-
class BMC::SMS::Strategies::AmazonSNS < BMC::SMS::Strategies::Base
|
2
|
-
class << self
|
3
|
-
attr_writer :sns_region
|
4
|
-
|
5
|
-
def sns_region
|
6
|
-
@sns_region ||= (ENV["SNS_REGION"] || ENV["AWS_REGION"])
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_writer :sns_access_key_id
|
10
|
-
|
11
|
-
def sns_access_key_id
|
12
|
-
@sns_access_key_id ||= (ENV["SNS_ACCESS_KEY_ID"] || ENV["AWS_ACCESS_KEY_ID"])
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_writer :sns_secret_access_key
|
16
|
-
|
17
|
-
def sns_secret_access_key
|
18
|
-
@sns_secret_access_key ||= (ENV["SNS_SECRET_ACCESS_KEY"] || ENV["AWS_SECRET_ACCESS_KEY"])
|
19
|
-
end
|
20
|
-
end # class << self
|
21
|
-
|
22
|
-
def client
|
23
|
-
@client ||= Aws::SNS::Client.new(
|
24
|
-
:region => self.class.sns_region,
|
25
|
-
:access_key_id => self.class.sns_access_key_id,
|
26
|
-
:secret_access_key => self.class.sns_secret_access_key,
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
def call
|
31
|
-
from = data[:from] || BMC::SMS.default_from
|
32
|
-
|
33
|
-
client.publish(
|
34
|
-
:phone_number => data[:to],
|
35
|
-
:message => data[:body],
|
36
|
-
:message_attributes => {
|
37
|
-
"AWS.SNS.SMS.SenderID" => {
|
38
|
-
:data_type => "String",
|
39
|
-
:string_value => from,
|
40
|
-
},
|
41
|
-
"AWS.SNS.SMS.SMSType" => {
|
42
|
-
:data_type => "String",
|
43
|
-
:string_value => "Transactional",
|
44
|
-
},
|
45
|
-
},
|
46
|
-
)
|
47
|
-
end
|
48
|
-
end
|