bmc 1.0.0 → 1.2.1

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: 1f44e62a2b31e04cc714d58d89b5bf5752a26cb99b2e9013da86a5a7c7b52a15
4
- data.tar.gz: 71693371c8912830ecbdbde9a6582c357dd0fdf63c8233ab1fc8c1e52723e828
3
+ metadata.gz: a59bab32c76657e73db1aaef5bb4e81c1ed6aa9543b94e5dc85f5054eec729a8
4
+ data.tar.gz: 4df9be0caa78db86d8a62cc8398defd99524e5b57db38c5ce9aa8f710db89053
5
5
  SHA512:
6
- metadata.gz: 4a865f824ca4aa26d2cb0d0e92360d4aa88f7a0e8cfa7a10d32d35875bfe4a33c53c7cd6f0809da4810c613426b9a56b8d7b3e29fad162f5e816f5137cbe7496
7
- data.tar.gz: a3febb518d32c8bccbb22b414fad2bbbe3473c4689b66d76cf7836b5bde532be34e0b22485c344dd24c59d70b0522e214357e50379ee3b60b1aaf78b44946748
6
+ metadata.gz: 77820c96a79cb697a80fa0d75d64820faa8e2af8d1a194286abfb7894cb32dbc1fcc1b5a194cb43d6910408ca882b1b52a0fdde30b777d1c92e160ca3217a3c2
7
+ data.tar.gz: '038cb8ed69f9e6790c08d01ea3f706ef1a22b1372b51ca5ab315d821d01cddf90b4663798e5f48d3c96e6db952d19e8d9638ed3084daafc0ecff86aa085d7e1a'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## Next version
4
+
5
+ ## v1.2.1
6
+ - Rails 7 + Ruby 3.1 compatibility
7
+
8
+ ## v1.2.0
9
+ - Remove FCM
10
+
11
+ ## v1.1.0
12
+ - SMS strategies rewrite
13
+
14
+ ## v1.0.1
15
+ - I18n changes
16
+
3
17
  ## v1.0.0
4
18
 
5
19
  - Fork from agilibox
@@ -57,7 +57,7 @@ module BMC::BootstrapHelper
57
57
  end
58
58
 
59
59
  content_tag(card_tag, class: card_classes) do
60
- [header_html, body_html, footer_html].compact.sum
60
+ [header_html, body_html, footer_html].compact.sum("".html_safe)
61
61
  end
62
62
  end
63
63
  end
@@ -19,6 +19,6 @@ module BMC::FormHelper
19
19
 
20
20
  return if query_values.empty?
21
21
 
22
- query_values.sum { |k, v| tag.input(type: "hidden", name: k, value: v) }
22
+ query_values.sum("".html_safe) { |k, v| tag.input(type: "hidden", name: k, value: v) }
23
23
  end
24
24
  end
@@ -102,7 +102,7 @@ module BMC::TextHelper
102
102
  container_css_class = ["info", ("blank" if value.blank?)]
103
103
 
104
104
  content_tag(tag, class: container_css_class) do
105
- [html_label, separator_html, html_value].sum
105
+ [html_label, separator_html, html_value].sum("".html_safe)
106
106
  end
107
107
  end # def info
108
108
 
@@ -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
@@ -24,7 +24,6 @@ en:
24
24
  close : "Close"
25
25
  lock : "Lock"
26
26
  unlock : "Unlock"
27
- snooze : "Snooze"
28
27
  alert : "Alert"
29
28
  complete : "Complete"
30
29
  done : "Done"
@@ -63,8 +62,6 @@ en:
63
62
  comment : "Comment"
64
63
  add_line : "Add line"
65
64
  remove_line: "Remove line"
66
- pay : "Pay"
67
- paid : "Payd"
68
65
  continue : "Continue"
69
66
  rename : "Rename"
70
67
  email : "Send by email"
@@ -3,7 +3,7 @@ fr:
3
3
  actions : "Actions"
4
4
  index : "Liste"
5
5
  list : "Liste"
6
- new : "Nouveau"
6
+ new : "Créer"
7
7
  create : "Créer"
8
8
  read : "Afficher"
9
9
  show : "Afficher"
@@ -24,7 +24,6 @@ fr:
24
24
  close : "Fermer"
25
25
  lock : "Fermer"
26
26
  unlock : "Ouvrir"
27
- snooze : "Reporter"
28
27
  alert : "Alerter"
29
28
  complete : "Marquer terminé"
30
29
  done : "Terminer"
@@ -63,8 +62,6 @@ fr:
63
62
  comment : "Commenter"
64
63
  add_line : "Ajouter une ligne"
65
64
  remove_line: "Supprimer la ligne"
66
- pay : "Payer"
67
- paid : "Payée"
68
65
  continue : "Continuer"
69
66
  rename : "Renommer"
70
67
  email : "Envoyer par email"
@@ -6,7 +6,6 @@ en:
6
6
  address : "Address"
7
7
  address1 : "Address"
8
8
  address2 : "Address (rest)"
9
- addressable : "Origin"
10
9
  amount : "Amount"
11
10
  attachable : "Origin"
12
11
  attachment : "Attachment"
@@ -21,13 +20,11 @@ en:
21
20
  comment : "Comment"
22
21
  commentable : "Origin"
23
22
  comments : "Comments"
24
- corporation_name : "Name"
25
23
  count : "Number"
26
24
  country : "Country"
27
25
  created_at : "Created at"
28
26
  current_avatar : "Current avatar"
29
27
  customer : "Customer"
30
- customer_guid : "Customer"
31
28
  data : "Data"
32
29
  date : "Date"
33
30
  date_begin : "Date begin"
@@ -44,7 +41,6 @@ en:
44
41
  email_subject : "Subject"
45
42
  email_to : "Recipient"
46
43
  facebook : "Facebook"
47
- fax : "Fax"
48
44
  file : "File"
49
45
  first_name : "First name"
50
46
  id : "Id"
@@ -59,7 +55,6 @@ en:
59
55
  month : "Month"
60
56
  name : "Name"
61
57
  number : "Number"
62
- paid : "Paid ?"
63
58
  password : "Password"
64
59
  password_confirmation : "Password (confirm)"
65
60
  phone : "Phone"
@@ -6,7 +6,6 @@ fr:
6
6
  address : "Adresse"
7
7
  address1 : "Adresse"
8
8
  address2 : "Adresse (suite)"
9
- addressable : "Origine"
10
9
  amount : "Montant"
11
10
  attachable : "Origine"
12
11
  attachment : "Pièce jointe"
@@ -21,13 +20,11 @@ fr:
21
20
  comment : "Commentaire"
22
21
  commentable : "Origine"
23
22
  comments : "Commentaires"
24
- corporation_name : "Nom"
25
23
  count : "Nombre"
26
24
  country : "Pays"
27
25
  created_at : "Créé le"
28
26
  current_avatar : "Avatar actuel"
29
27
  customer : "Client"
30
- customer_guid : "Client"
31
28
  data : "Informations"
32
29
  date : "Date"
33
30
  date_begin : "Date de début"
@@ -44,7 +41,6 @@ fr:
44
41
  email_subject : "Object"
45
42
  email_to : "Destinataire"
46
43
  facebook : "Facebook"
47
- fax : "Fax"
48
44
  file : "Fichier"
49
45
  first_name : "Prénom"
50
46
  id : "Id"
@@ -59,7 +55,6 @@ fr:
59
55
  month : "Mois"
60
56
  name : "Nom"
61
57
  number : "Nombre"
62
- paid : "Payée ?"
63
58
  password : "Mot de passe"
64
59
  password_confirmation : "Mot de passe (confirmer)"
65
60
  phone : "Téléphone"
@@ -9,8 +9,6 @@ en:
9
9
  extension_white_list_error : "This file type is not supported"
10
10
 
11
11
  filters:
12
- all_customers: "All customers"
13
- all_owners: "All all owners"
14
12
  date_begin: "Date begin"
15
13
  date_end: "Date end"
16
14
 
@@ -9,8 +9,6 @@ fr:
9
9
  extension_white_list_error : "Ce type de fichier n'est pas prit en charge"
10
10
 
11
11
  filters:
12
- all_customers: "Tous les clients"
13
- all_owners: "Tout le monde"
14
12
  date_begin: "Date début"
15
13
  date_end: "Date fin"
16
14
 
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
@@ -12,9 +12,7 @@ module BMC
12
12
  initializer "inflections" do
13
13
  ActiveSupport::Inflector.inflections(:en) do |inflect|
14
14
  inflect.acronym "BMC"
15
- inflect.acronym "FCM"
16
15
  inflect.acronym "SMS"
17
- inflect.acronym "SNS"
18
16
  inflect.acronym "UUID"
19
17
  inflect.acronym "XLSX"
20
18
  end
data/lib/bmc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BMC
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.1"
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.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
- - agilidée
7
+ - Benoit MARTIN-CHAVE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-06 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails-i18n
@@ -147,10 +147,9 @@ 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
- - app/libs/bmc/fcm/notifier.rb
153
- - app/libs/bmc/fcm/request.rb
154
153
  - app/libs/bmc/mini_model_serializer/serialize.rb
155
154
  - app/libs/bmc/mini_model_serializer/serializer.rb
156
155
  - app/libs/bmc/monkey.rb
@@ -172,9 +171,9 @@ files:
172
171
  - app/serializers/bmc/serializers/xlsx.rb
173
172
  - app/sms/bmc/sms.rb
174
173
  - app/sms/bmc/sms/application_sms.rb
174
+ - app/sms/bmc/sms/deliver_job.rb
175
175
  - app/sms/bmc/sms/message.rb
176
- - app/sms/bmc/sms/strategies/amazon_sns.rb
177
- - app/sms/bmc/sms/strategies/base.rb
176
+ - app/sms/bmc/sms/strategies/amazon.rb
178
177
  - app/sms/bmc/sms/strategies/test.rb
179
178
  - app/sorters/bmc/sorter.rb
180
179
  - app/views/bmc/search/_form.html.slim
@@ -229,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
228
  - !ruby/object:Gem::Version
230
229
  version: '0'
231
230
  requirements: []
232
- rubygems_version: 3.1.6
231
+ rubygems_version: 3.3.3
233
232
  signing_key:
234
233
  specification_version: 4
235
234
  summary: BMC
@@ -1,32 +0,0 @@
1
- class BMC::FCM::Notifier
2
- attr_reader :to, :title, :body, :badge, :sound, :data
3
-
4
- # rubocop:disable Metrics/ParameterLists
5
- def initialize(to:, title: nil, body:, badge: 0, sound: "default", data: {})
6
- super()
7
- @to = to
8
- @title = title
9
- @body = body
10
- @badge = badge
11
- @sound = sound
12
- @data = data
13
- end
14
- # rubocop:enable Metrics/ParameterLists
15
-
16
- def call
17
- BMC::FCM::Request.call(
18
- :to => to,
19
- :notification => {
20
- :title => title,
21
- :body => body,
22
- :badge => badge,
23
- :sound => sound,
24
- },
25
- :data => data,
26
- )
27
- end
28
-
29
- def self.call(...)
30
- new(...).call
31
- end
32
- end
@@ -1,54 +0,0 @@
1
- class BMC::FCM::Request
2
- extend AttrExtras.mixin
3
-
4
- URL = "https://fcm.googleapis.com/fcm/send"
5
-
6
- class << self
7
- attr_writer :api_key
8
-
9
- def api_key
10
- @api_key ||= ENV["FCM_API_KEY"]
11
- end
12
- end
13
-
14
- attr_reader_initialize :request_body
15
-
16
- attr_reader :response_json
17
-
18
- def self.call(...)
19
- new(...).call
20
- end
21
-
22
- def call
23
- response_body = HTTParty.post(URL,
24
- :body => request_body.to_json,
25
- :headers => {
26
- "Content-Type" => "application/json",
27
- "Authorization" => "key=#{self.class.api_key}",
28
- },
29
- ).body
30
-
31
- @response_json = JSON.parse(response_body).deep_symbolize_keys
32
-
33
- self
34
- rescue JSON::ParserError
35
- @response_json = {success: 0, failure: 1, results: [{:error => "InvalidJsonResponse"}]}
36
- self
37
- end
38
-
39
- def ok?
40
- response_json[:success].positive? && response_json[:failure].zero?
41
- end
42
-
43
- def error?
44
- !ok?
45
- end
46
-
47
- def errors
48
- response_json[:results].pluck(:error).compact
49
- end
50
-
51
- def invalid_token?
52
- errors.include?("NotRegistered") || errors.include?("InvalidRegistration")
53
- end
54
- end
@@ -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