Module: IfreeSms::Callbacks

Included in:
Manager
Defined in:
lib/ifree_sms/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#_incoming_messageObject

Provides access to the callback array for incoming_message :api: private



29
30
31
# File 'lib/ifree_sms/callbacks.rb', line 29

def _incoming_message
  @_incoming_message ||= []
end

#_run_callbacks(kind, *args) ⇒ Object

Hook to _run_callbacks asserting for conditions.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ifree_sms/callbacks.rb', line 5

def _run_callbacks(kind, *args) #:nodoc:
  options = args.last # Last callback arg MUST be a Hash

  send("_#{kind}").each do |callback, conditions|
    invalid = conditions.find do |key, value|
      value.is_a?(Array) ? !value.include?(options[key]) : (value != options[key])
    end

    callback.call(*args) unless invalid
  end
end

#incoming_message(options = {}, method = :push, &block) ⇒ Object

A callback that runs after message created Example:

IfreeSms::Manager.incoming_message do |env, opts|
end

Raises:

  • (BlockNotGiven)


22
23
24
25
# File 'lib/ifree_sms/callbacks.rb', line 22

def incoming_message(options = {}, method = :push, &block)
  raise BlockNotGiven unless block_given?
  _incoming_message.send(method, [block, options])
end