Class: ActionShortMessage::ShortMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/action_short_message/short_message.rb

Overview

include ActionShortMessage::Adapters

Constant Summary collapse

@@delivery_notification_observers =

Initialize the observers and interceptors arrays

[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/action_short_message/short_message.rb', line 5

def action
  @action
end

#debugObject

Returns the value of attribute debug.



5
6
7
# File 'lib/action_short_message/short_message.rb', line 5

def debug
  @debug
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/action_short_message/short_message.rb', line 5

def message
  @message
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/action_short_message/short_message.rb', line 5

def options
  @options
end

#raise_delivery_errorsObject

Returns the value of attribute raise_delivery_errors.



5
6
7
# File 'lib/action_short_message/short_message.rb', line 5

def raise_delivery_errors
  @raise_delivery_errors
end

#sms_provider(method = nil, settings = {}) ⇒ Object (readonly)

Returns the value of attribute sms_provider.



6
7
8
# File 'lib/action_short_message/short_message.rb', line 6

def sms_provider
  @sms_provider
end

#toObject

Returns the value of attribute to.



5
6
7
# File 'lib/action_short_message/short_message.rb', line 5

def to
  @to
end

Class Method Details

.delivery_adaptersObject



36
# File 'lib/action_short_message/short_message.rb', line 36

def self.delivery_adapters; end

.register_observer(observer) ⇒ Object

You can register an object to be informed of every short message that is sent through this method.

Your object needs to respond to a single method #delivered_message(message) which receives the short message that is sent.



20
21
22
# File 'lib/action_short_message/short_message.rb', line 20

def self.register_observer(observer)
  @@delivery_notification_observers << observer unless @@delivery_notification_observers.include?(observer)
end

.unregister_observer(observer) ⇒ Object

Unregister the given observer, allowing short message to resume operations without it.



26
27
28
# File 'lib/action_short_message/short_message.rb', line 26

def self.unregister_observer(observer)
  @@delivery_notification_observers.delete(observer)
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/action_short_message/short_message.rb', line 38

def debug?
  !!@debug
end

#deliverObject



42
43
44
45
46
47
# File 'lib/action_short_message/short_message.rb', line 42

def deliver
  ActiveSupport::Notifications.instrument('deliver.action_short_message', { messagage: message, to: to }) do
    @sms_provider.send_message(message, options.merge(to: to))
  end
  inform_observers
end

#inform_observersObject



30
31
32
33
34
# File 'lib/action_short_message/short_message.rb', line 30

def inform_observers
  @@delivery_notification_observers.each do |observer|
    observer.delivered_message(self)
  end
end