actionmessage 0.0.0 → 0.0.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
  SHA1:
3
- metadata.gz: 1e8dd0c9af288515843fff286e349e99643de21b
4
- data.tar.gz: 7d20e3d3d5bd082368b09ea9444e4cf368b9b6c1
3
+ metadata.gz: 195c072ea0df8b8382477070273029b215d4cb43
4
+ data.tar.gz: d58b267cd8d77e3c1135b4ef1225f1dc2f65cbf8
5
5
  SHA512:
6
- metadata.gz: 54b804f67897116c2348740c98590b45fe94978f88fa5cb89570a7ff5dbf7399d530444a2dd489aeb4d08db95834b3b3f97e54ab80d3ec3d493f2464531a6f8f
7
- data.tar.gz: 571c203e8f113b75b7cd8bc9949d4935695aefaa4fc37c833f38ff4ea6953a958e7795c07e087b1c0d20c190a762236240011275dcc6a154bcea8a7946e8389c
6
+ metadata.gz: 8310e5bb7a9e40aa423377fc94620b796701268a408e47cf0b0614d67e9a5d6f23e984564bababf37a85eb09a5a8e0371ac2443aad805e64bb287ccd38a344cf
7
+ data.tar.gz: a95b89cdcfa0c46d589287dec9275378bc8eccaa3365297524eb2315b7b92e98dd5c7cb0499900fec2e7ce0339e6544b29664b40a9c8ca2300cf7220769a08a0
data/README.md CHANGED
@@ -20,7 +20,9 @@ require 'action_message'
20
20
 
21
21
  If you're using Rails, place this on your environment file or application.rb
22
22
  ```ruby
23
- ActionMessage::Base.default_options = {
23
+ require 'action_message/railtie'
24
+
25
+ config.action_message = {
24
26
  from: "number to send from in international format, e.g.: +11231231234",
25
27
  adapter: {
26
28
  name: :twilio,
@@ -42,7 +44,7 @@ class MerchantMessage < ActionMessage::Base
42
44
  end
43
45
  ```
44
46
 
45
- Define your views under app/views/merchant_message/send_welcome_sms.text.erb
47
+ Define your views under your view path, such as: app/views/merchant_message/send_welcome_sms.text.erb
46
48
  ```html
47
49
  Welcome, <%= @name %>!!!
48
50
  ```
@@ -53,7 +55,6 @@ TODO:
53
55
  - Add background processing (deliver_later);
54
56
  - Log instrumentation with ActiveSupport;
55
57
  - Add generators;
56
- - Add a Railtie;
57
58
  - Add delivery methods;
58
59
  - Add test helpers;
59
60
  - Add more adapters;
@@ -4,11 +4,22 @@ require 'action_message/adapters/twilio'
4
4
 
5
5
  module ActionMessage
6
6
  module Adapters
7
- class << self
8
- def adapter
9
- adapter_params = ActionMessage::Base.default_params[:adapter]
10
- const_get(adapter_params[:name].to_s.capitalize).new(adapter_params[:credentials])
11
- end
12
- end
13
- end
7
+ class << self
8
+ def adapter_klass
9
+ @@adapter_klass ||= adapter_params[:name].to_s.capitalize
10
+ end
11
+
12
+ def adapter_params
13
+ @@adapter_params ||= ActionMessage::Base.default_params[:adapter]
14
+ end
15
+
16
+ def adapter_credentials
17
+ @@adapter_credentials ||= adapter_params[:credentials]
18
+ end
19
+
20
+ def adapter
21
+ @@adapter ||= const_get(adapter_klass).new(adapter_credentials)
22
+ end
23
+ end
24
+ end
14
25
  end
@@ -1,6 +1,9 @@
1
1
  module ActionMessage
2
+ include ActionMessage::Adapters
3
+
2
4
  class Message
3
5
  attr_accessor :headers, :action, :args, :body, :to, :debug
6
+ attr_reader :adapter
4
7
 
5
8
  def initialize
6
9
  @adapter = Adapters.adapter
@@ -12,7 +15,7 @@ module ActionMessage
12
15
 
13
16
  def deliver
14
17
  puts "Sending message \"#{body}\" to number #{to}" # TODO: Switch to a decent logger
15
- @adapter.send_message(body, to: to) unless debug?
18
+ adapter.send_message(body, to: to) # unless debug?
16
19
  end
17
20
  end
18
21
  end
@@ -0,0 +1,23 @@
1
+ require "action_message"
2
+ require "rails"
3
+
4
+ module ActionMessage
5
+ class Railtie < Rails::Railtie # :nodoc:
6
+ config.action_message = ActiveSupport::OrderedOptions.new
7
+ config.eager_load_namespaces << ActionMessage
8
+
9
+ initializer "action_message.set_configs" do |app|
10
+ paths = app.config.paths
11
+ options = app.config.action_message
12
+
13
+ ActiveSupport.on_load(:action_message) do
14
+ options.each { |k,v| send("#{k}=", v) }
15
+ end
16
+ end
17
+
18
+ config.after_initialize do |app|
19
+ ActionMessage::Base.default_options = app.config.action_message
20
+ end
21
+ end
22
+ end
23
+
@@ -1,3 +1,3 @@
1
1
  module ActionMessage
2
- VERSION = "0.0.0".freeze
2
+ VERSION = "0.0.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmessage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Ballona
@@ -121,6 +121,7 @@ files:
121
121
  - lib/action_message/base.rb
122
122
  - lib/action_message/message.rb
123
123
  - lib/action_message/message_delivery.rb
124
+ - lib/action_message/railtie.rb
124
125
  - lib/action_message/version.rb
125
126
  homepage: http://github.com/dballona/actionmessage
126
127
  licenses: