Sha256: 9a1137ed7606722db77106c115870a2d3d3c25cef50e32d427ff907ede8e9960

Contents?: true

Size: 846 Bytes

Versions: 1

Compression:

Stored size: 846 Bytes

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, opts={})
        @command_name = command_name
        @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}=#{value}" }.sort.join('&')
        return URI.parse(File.join(api_service_uri, @command_name + URI.encode(param_string)))
      end

      protected
        def api_service_uri
          protocol = @options[:secure] ? 'https' : 'http'
          return "#{protocol}://#{API_SERVICE_HOST}/http/"
        end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clickatell-0.4.0 lib/clickatell/api/command.rb