Sha256: 8f932d403aa40c96b3c33f7389c2580eda2bd9bdcbb8b1a53ceffc5cb7bd2512

Contents?: true

Size: 952 Bytes

Versions: 1

Compression:

Stored size: 952 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, 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}=#{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'
          port = @options[:secure] ? 443 : 80
          return "#{protocol}://#{API_SERVICE_HOST}:#{port}/#{@service}/"
        end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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