Class: Porteo::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/gateways/gateway.rb

Overview

Base class to implement any gateway needed to connect protocols and sending service gems.

It should not be used by itself but creating a child class which defines specific behavior based on a certain protocol and a gem.

Direct Known Subclasses

Mensario_gateway, Pony_gateway, Twitter_gateway

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gw_config = {}) ⇒ Gateway

Create a new instance of a gateway.

Parameters:

  • gw_config (Hash) (defaults to: {})

    Configuration options. This options set the sending parameters not the content of the message.



56
57
58
# File 'lib/gateways/gateway.rb', line 56

def initialize( gw_config = {} )
  @config = gw_config
end

Class Method Details

.connection_argument(*argument) ⇒ nil

Set required connection parameters for a specific gateway. This class method creates a new instance method which overwritte connection_argument.

Parameters:

  • argument (Array)

    Required connection arguments.

Returns:

  • (nil)


37
38
39
40
41
# File 'lib/gateways/gateway.rb', line 37

def self.connection_argument( *argument )
  define_method( :connection_arguments ) do
    argument
  end
end

Instance Method Details

#connection_argumentsArray

Required connection parameters. Its define which fields have to be present in order to send a valid message. This method is overwritten dynamically when a child gateway class is created and self.connection_arguments is called.

Returns:

  • (Array)

    Required connection parameters.



49
50
51
# File 'lib/gateways/gateway.rb', line 49

def connection_arguments
  []
end

#init_send(message) ⇒ nil

Initialize the send message process. Before sending the message it check if all required params are present.

Parameters:

  • message (Hash)

    Message sections to be sent.

Returns:

  • (nil)


74
75
76
# File 'lib/gateways/gateway.rb', line 74

def init_send( message )
  send_message_hook( message )
end

#send_message(message_sections) ⇒ nil

This method is abstract.
Note:

This method has to be overwritten.

Send a message defined in parameter

Parameters:

  • message_sections (Hash)

    Message content.

Returns:

  • (nil)

Raises:

  • (Exception)

    This method is not meant to be call but to be overwritten.



66
67
68
# File 'lib/gateways/gateway.rb', line 66

def send_message( message_sections )
  raise Exception, "Gateway Error. This method has to be overwritten. You are trying to send a message with a generic gateway."
end