Class Clickatell::API
In: lib/clickatell/api/command.rb
lib/clickatell/api/command_executor.rb
lib/clickatell/api/error.rb
lib/clickatell/api/message_status.rb
lib/clickatell/api.rb
Parent: Object

This module provides the core implementation of the Clickatell HTTP service.

Methods

Classes and Modules

Class Clickatell::API::Command
Class Clickatell::API::CommandExecutor
Class Clickatell::API::Error
Class Clickatell::API::FakeHttpResponse
Class Clickatell::API::MessageStatus

Attributes

api_service_host  [RW]  Allow customizing URL
auth_options  [RW] 
debug_mode  [RW]  Set to true to enable debugging (off by default)
secure_mode  [RW]  Enable secure mode (SSL)
test_mode  [RW]  Set to true to test message sending; this will not actually send messages but will collect sent messages in a testable collection. (off by default)

Public Class methods

Authenticates using the given credentials and returns an API instance with the authentication options set to use the resulting session_id.

[Source]

# File lib/clickatell/api.rb, line 11
      def authenticate(api_id, username, password)
        api = self.new
        session_id = api.authenticate(api_id, username, password)
        api.auth_options = { :session_id => session_id }
        api
      end

Creates a new API instance using the specified +auth options+. auth_options is a hash containing either a :session_id or :username, :password and :api_key.

Some API calls (authenticate, ping etc.) do not require any auth_options. auth_options can be updated using the accessor methods.

[Source]

# File lib/clickatell/api.rb, line 42
    def initialize(auth_options={})
      @auth_options = auth_options
    end

Public Instance methods

Returns the number of credits remaining as a float.

[Source]

# File lib/clickatell/api.rb, line 103
    def account_balance
      response = execute_command('getbalance', 'http')
      parse_response(response)['Credit'].to_f
    end

Authenticates using the specified credentials. Returns a session_id if successful which can be used in subsequent API calls.

[Source]

# File lib/clickatell/api.rb, line 49
    def authenticate(api_id, username, password)
      response = execute_command('auth', 'http',
        :api_id => api_id,
        :user => username,
        :password => password
      )
      parse_response(response)['OK']
    end

Returns the status of a message. Use message ID returned from original send_message call.

[Source]

# File lib/clickatell/api.rb, line 97
    def message_status(message_id)
      response = execute_command('querymsg', 'http', :apimsgid => message_id)
      parse_response(response)['Status']
    end

Pings the service with the specified session_id to keep the session alive.

[Source]

# File lib/clickatell/api.rb, line 60
    def ping(session_id)
      execute_command('ping', 'http', :session_id => session_id)
    end

Sends a message message_text to recipient. Recipient number should have an international dialing prefix and no leading zeros (unless you have set a default prefix in your clickatell account centre).

Additional options:

   :from - the from number/name
   :set_mobile_originated - mobile originated flag

Returns a new message ID if successful.

[Source]

# File lib/clickatell/api.rb, line 74
    def send_message(recipient, message_text, opts={})
      valid_options = opts.only(:from, :mo, :callback)
      valid_options.merge!(:req_feat => '48') if valid_options[:from]
      valid_options.merge!(:mo => '1') if opts[:set_mobile_originated]
      recipient = recipient.join(",")if recipient.is_a?(Array)
      response = execute_command('sendmsg', 'http',
        {:to => recipient, :text => message_text}.merge(valid_options)
      ) 
      response = parse_response(response)
      response.is_a?(Array) ? response.map { |r| r['ID'] } : response['ID']
    end

[Source]

# File lib/clickatell/api.rb, line 86
    def send_wap_push(recipient, media_url, notification_text='', opts={})
      valid_options = opts.only(:from)
      valid_options.merge!(:req_feat => '48') if valid_options[:from]
      response = execute_command('si_push', 'mms',
        {:to => recipient, :si_url => media_url, :si_text => notification_text, :si_id => 'foo'}.merge(valid_options)
      )
      parse_response(response)['ID']
    end

[Source]

# File lib/clickatell/api.rb, line 108
    def sms_requests
      @sms_requests ||= []
    end

[Validate]