Class Clickatell::API::CommandExecutor
In: lib/clickatell/api/command_executor.rb
Parent: Object

Used to run commands agains the Clickatell gateway.

Methods

Public Class methods

[Source]

# File lib/clickatell/api/command_executor.rb, line 15
      def initialize(authentication_hash, secure=false, debug=false, test_mode=false)
        @authentication_hash = authentication_hash
        @debug = debug
        @secure = secure
        @test_mode = test_mode
        
        allow_request_recording if @test_mode
      end

Public Instance methods

Builds a command object and sends it using HTTP GET. Will output URLs as they are requested to stdout when debugging is enabled.

[Source]

# File lib/clickatell/api/command_executor.rb, line 31
      def execute(command_name, service, parameters={})
        request_uri = command(command_name, service, parameters)
        puts "[debug] Sending request to #{request_uri}" if @debug
        get_response(request_uri).first
      end

[Source]

# File lib/clickatell/api/command_executor.rb, line 24
      def in_test_mode?
        @test_mode
      end

Protected Instance methods

[Source]

# File lib/clickatell/api/command_executor.rb, line 44
        def get_response(uri)
          if in_test_mode?
            sms_requests << uri
            [FakeHttpResponse.new]
          else
            http = Net::HTTP.new(uri.host, uri.port)
            http.use_ssl = (uri.scheme == 'https')
            http.start do |http|
              resp, body = http.get([uri.path, uri.query].join('?'))
            end
          end
        end

[Validate]