actionmessage 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 240081935ff8db8aa9f48415da974a088afd2888
4
- data.tar.gz: d5dc250192ff286a4181abb8602e6f6ade11f0d3
3
+ metadata.gz: ce7496587f302af7f1961a4b08737a5644128544
4
+ data.tar.gz: c00de1183c0530935dde4bd471d22dcd2470f9b2
5
5
  SHA512:
6
- metadata.gz: f993a661c89c72745337d194c2f16705b15366354e27c921b21843a2bee638e4f9f842250dec03c810a42a0900900468069111f851542025af1080c1af298b47
7
- data.tar.gz: 69fc7546f24538cd834564908d8e75218db970442c40b4e4acab9ac8b9d83bd9af66c15e66b9b66a5f86f32b3faca33f1feb942ac2143819467716dc145e9f8b
6
+ metadata.gz: 6660e21bd4ff00d3d5421139ec3ca1ea7634bd7a3adea554cca9dbc4043d55117384b4ea6362592319a0daa174da3a503a830aff0b60bce1e5ded77d2f5c7962
7
+ data.tar.gz: 4bd24eb4d565c2e29196fbcc841676ed535dcd65a46fb687677a023cf879deb8c6b242a879523ece6aa4cd37010c2f6d0c92a6f8e68760b1502b44c461a8b924
data/.travis.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.4.0
3
4
  - 2.3.0
5
+ - 2.2.5
6
+ - 2.1.10
4
7
  before_install: gem install bundler -v 1.11.2
data/README.md CHANGED
@@ -9,7 +9,7 @@ Pull requests are more than welcome!
9
9
  [![codecov](https://codecov.io/gh/dballona/actionmessage/branch/master/graph/badge.svg)](https://codecov.io/gh/dballona/actionmessage)
10
10
  [![Code Climate](https://codeclimate.com/github/dballona/actionmessage/badges/gpa.svg)](https://codeclimate.com/github/dballona/actionmessage)
11
11
 
12
- ## Usage
12
+ ## Setup
13
13
 
14
14
  Install it using bundler:
15
15
 
@@ -24,27 +24,29 @@ If you're using Rails, place this on your environment file or application.rb
24
24
  require 'action_message/railtie'
25
25
 
26
26
  config.action_message = {
27
- from: "number to send from in international format, e.g.: +11231231234",
28
- adapter: {
29
- name: :twilio,
30
- credentials: {
31
- account_sid: 'MY TWILIO ACCOUNT SID'.freeze,
32
- auth_token: 'MY AUTH TOKEN'.freeze
33
- }
34
- }
27
+ from: "number to send from in international format, e.g.: +11231231234",
28
+ adapter: {
29
+ name: :twilio,
30
+ credentials: {
31
+ account_sid: 'MY TWILIO ACCOUNT SID'.freeze,
32
+ auth_token: 'MY AUTH TOKEN'.freeze
33
+ }
34
+ }
35
35
  }
36
36
  ```
37
37
 
38
+ ## Usage
39
+
38
40
  In order to generate your message class, you can either place this code
39
41
  under app/messages/welcome_message.rb or just use our generators by running
40
42
  the following command: `rails g message Welcome send_welcome_sms`
41
43
 
42
44
  ```ruby
43
45
  class WelcomeMessage < ActionMessage::Base
44
- def send_welcome_sms(name, phone_number_to_send_message)
45
- @name = name
46
- sms(to: phone_number_to_send_message)
47
- end
46
+ def send_welcome_sms(name, phone_number_to_send_message)
47
+ @name = name
48
+ sms(to: phone_number_to_send_message)
49
+ end
48
50
  end
49
51
  ```
50
52
 
@@ -53,3 +55,31 @@ Define your views under your view path, such as: app/views/welcome_message/send_
53
55
  ```html
54
56
  Welcome, <%= @name %>!
55
57
  ```
58
+
59
+ And to send is really simple!
60
+
61
+ ```ruby
62
+ name = 'John Doe'
63
+ phone = '+11231231234'
64
+
65
+ # To send right away:
66
+ WelcomeMessage.send_welcome_sms(name, phone).deliver_now
67
+
68
+ # To send through a background job
69
+ WelcomeMessage.send_welcome_sms(name, phone).deliver_later
70
+ ```
71
+
72
+ ## Interceptors
73
+
74
+ In order to prevent sending messages to a specific number or containing any specific text on it's body you can use Interceptors:
75
+
76
+ ```ruby
77
+ # You can use strings (exact comparison)
78
+ ActionMessage::Interceptor.register(to: 'number I want to prevent sending messages')
79
+
80
+ # Regular expressions
81
+ ActionMessage::Interceptor.register(body: /something innapropriate/i)
82
+
83
+ # Pass Multiple arguments on the same call
84
+ ActionMessage::Interceptor.register(to: '+11231231234', body: /anything/i)
85
+ ```
@@ -3,6 +3,7 @@ require 'abstract_controller'
3
3
  require 'action_message/adapters'
4
4
  require 'action_message/base'
5
5
  require 'action_message/delivery_job'
6
+ require 'action_message/interceptor'
6
7
  require 'action_message/message'
7
8
  require 'action_message/message_delivery'
8
9
  require 'action_message/version'
@@ -38,10 +38,10 @@ module ActionMessage
38
38
 
39
39
  def base_paths
40
40
  %w(
41
- app/views
42
- app/views/messages
43
- app/views/mailers
44
- app/views/application
41
+ app/views
42
+ app/views/messages
43
+ app/views/mailers
44
+ app/views/application
45
45
  app/views/layouts
46
46
  ).freeze
47
47
  end
@@ -67,13 +67,13 @@ module ActionMessage
67
67
 
68
68
  self.template_name = params[:template_name].presence || template_name
69
69
  self.template_path = params[:template_path].presence || template_path
70
-
70
+
71
71
  @_message_was_called = true
72
72
  lookup_context.view_paths = (lookup_context.view_paths.to_a + self.class.base_paths).flatten.uniq
73
73
 
74
74
  message.to = params[:to]
75
75
  message.debug = params[:debug]
76
- message.body = render(full_template_path)
76
+ message.body = params[:body] || render(full_template_path)
77
77
 
78
78
  message
79
79
  end
@@ -0,0 +1,35 @@
1
+ module ActionMessage
2
+ class Interceptor
3
+ cattr_accessor :blacklist
4
+ self.blacklist = {}
5
+
6
+ class << self
7
+ def register(conditions={})
8
+ raise TypeError, 'Invalid type. Please provide a hash object' unless conditions.methods.include?(:key)
9
+
10
+ conditions.each do |attribute, condition|
11
+ @@blacklist[attribute.to_sym] ||= []
12
+ @@blacklist[attribute.to_sym].push(condition)
13
+ end
14
+ end
15
+
16
+
17
+ def registered_for?(message)
18
+ @@blacklist.each do |attribute, conditions|
19
+ value = message.send(attribute.to_sym)
20
+
21
+ conditions.each do |condition|
22
+ return true if value.send(match_method_for(condition), condition)
23
+ end
24
+ end
25
+
26
+ return false
27
+ end
28
+
29
+ private
30
+ def match_method_for(condition)
31
+ condition.is_a?(Regexp)? :=~ : :==
32
+ end
33
+ end
34
+ end
35
+ end
@@ -14,8 +14,14 @@ module ActionMessage
14
14
  end
15
15
 
16
16
  def deliver
17
- unless debug?
18
- # add logger 'Sendimg message from "number" to "number"'
17
+ if debug?
18
+ # TODO: add log
19
+ return nil
20
+ elsif Interceptor.registered_for?(self)
21
+ # TODO: add log
22
+ return nil
23
+ else
24
+ # TODO: add logger 'Sending message from "number" to "number"'
19
25
  adapter.send_message(body, to: to)
20
26
  end
21
27
  end
@@ -1,3 +1,3 @@
1
1
  module ActionMessage
2
- VERSION = '0.0.12'.freeze
2
+ VERSION = '0.0.13'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmessage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Ballona
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-06 00:00:00.000000000 Z
11
+ date: 2017-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -160,6 +160,7 @@ files:
160
160
  - lib/action_message/adapters/twilio.rb
161
161
  - lib/action_message/base.rb
162
162
  - lib/action_message/delivery_job.rb
163
+ - lib/action_message/interceptor.rb
163
164
  - lib/action_message/message.rb
164
165
  - lib/action_message/message_delivery.rb
165
166
  - lib/action_message/railtie.rb