Sha256: 65709c810ceb75db30c8de3a47414cdd09fd0bb26b6370d5ed33f360cf460f33

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module Clickatell
  class API

    # Represents a Clickatell HTTP gateway command in the form 
    # of a complete URL (the raw, low-level request).
    class Command
      API_SERVICE_HOST = 'api.clickatell.com'

      def initialize(command_name, service = 'http', opts={})
        @command_name = command_name
        @service = service
        @options = { :secure => false }.merge(opts)
      end
  
      # Returns a URL for the given parameters (a hash).
      def with_params(param_hash)
        param_string = '?' + param_hash.map { |key, value| "#{key}=#{CGI.escape(value)}" }.sort.join('&')
        return URI.parse(File.join(api_service_uri, @command_name + param_string))
      end

      protected
        def api_service_uri
          protocol = @options[:secure] ? 'https' : 'http'
          api_service_host = (Clickatell::API.api_service_host.blank? ? API_SERVICE_HOST : Clickatell::API.api_service_host)
          return "#{protocol}://#{api_service_host}/#{@service}/"
        end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
commonthread-clickatell-0.5.1 lib/clickatell/api/command.rb