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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64f8cd00d69f9f1fec849416f724c7334eb2a9be8fafc4efe145e559e367b673
4
- data.tar.gz: 617c5037874bf257ca62470730cbc6b851a2660b94c2192303fe248d13e02b3a
3
+ metadata.gz: 610c3313a3499ea6c4b1ab3b3d801ee892cfcce32e5adacf8b935a2032506f71
4
+ data.tar.gz: 0db6265466d7b9f388b2a73b299b51b138fde69c89b08a67f8bc9fb67cef405d
5
5
  SHA512:
6
- metadata.gz: 449b81c574ae681471b08c97477b78f05c33db7108fc2ac159de61c9b383e594cce65bffd5ae59a1cb2968cb1e6fbc4a6fadb69320ce2bc8462c242d38095c20
7
- data.tar.gz: d9526288891a456f704ecbac6e15e9707803fc590afe0d6c09f0cf9d5b66ee7c2a74e764916e7715d0510ddb686554a93e83f09b79d345ed52aefcbc1ac49c70
6
+ metadata.gz: acc8116f3b1beff954b12fe0558aa3023172f5e8720316b8dd3f851b60258f774a2d002fd72c84a5fbe1f65c3c6761c967bef7e38f32e5a79c61625fe6e9fd36
7
+ data.tar.gz: 915fe7c88c4c6d7b201a9a8b70482207cf6f2b55a80222602825ebf33ceae0ebf0a0f0bf38dfe8d4781de2d20e40ff09b6b0ea32c5bec05c03afd9a480d9c4ce
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## v1.1.0
6
+ - SMS strategies rewrite
7
+
5
8
  ## v1.0.1
6
9
  - I18n changes
7
10
 
@@ -0,0 +1,2 @@
1
+ class BMC::ApplicationJob < BMC.parent_job
2
+ end
@@ -0,0 +1,5 @@
1
+ class BMC::SMS::DeliverJob < BMC::ApplicationJob
2
+ def perform(data)
3
+ BMC::SMS.strategy.call(data)
4
+ end
5
+ end
@@ -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
- strategy.call(data)
9
+ BMC::SMS::DeliverJob.perform_now(data)
19
10
  end
20
11
 
21
- # TODO : Delay
22
12
  def deliver_later
23
- deliver_now
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 < BMC::SMS::Strategies::Base
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
- def strategy=(value)
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
@@ -14,7 +14,6 @@ module BMC
14
14
  inflect.acronym "BMC"
15
15
  inflect.acronym "FCM"
16
16
  inflect.acronym "SMS"
17
- inflect.acronym "SNS"
18
17
  inflect.acronym "UUID"
19
18
  inflect.acronym "XLSX"
20
19
  end
data/lib/bmc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BMC
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
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.1
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-06 00:00:00.000000000 Z
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/amazon_sns.rb
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
@@ -1,15 +0,0 @@
1
- class BMC::SMS::Strategies::Base
2
- attr_reader :data
3
-
4
- def initialize(data)
5
- @data = data
6
- end
7
-
8
- def call
9
- raise NotImplementedError
10
- end
11
-
12
- def self.call(...)
13
- new(...).call
14
- end
15
- end