<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,9 +16,6 @@ end
 # parse command line options
 options = Clickatell::Utility::Options.parse(ARGV)
 
-# enable debugging if specified
-Clickatell::API.debug_mode = true if options.debugging_enabled
-
 # authenticate and load the API
 api = Clickatell::API.authenticate(options.api_key, options.username, options.password)
 </diff>
      <filename>bin/sms</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,9 @@ module Clickatell
       
       # Set to true to enable debugging (off by default)
       attr_accessor :debug_mode
+      
+      # Enable secure mode (SSL)
+      attr_accessor :secure_mode
     end
     
     # Creates a new API instance using the specified +auth options+.
@@ -79,7 +82,7 @@ module Clickatell
 
     protected
       def execute_command(command_name, parameters={}) #:nodoc:
-        CommandExecutor.new(auth_hash, self.class.debug_mode).execute(command_name, parameters)
+        CommandExecutor.new(auth_hash, self.class.secure_mode, self.class.debug_mode).execute(command_name, parameters)
       end
 
       def parse_response(raw_response) #:nodoc:</diff>
      <filename>lib/clickatell/api.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,7 +20,8 @@ module Clickatell
       protected
         def api_service_uri
           protocol = @options[:secure] ? 'https' : 'http'
-          return &quot;#{protocol}://#{API_SERVICE_HOST}/http/&quot;
+          port = @options[:secure] ? 443 : 80
+          return &quot;#{protocol}://#{API_SERVICE_HOST}:#{port}/http/&quot;
         end
     end
     </diff>
      <filename>lib/clickatell/api/command.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,15 @@
 require 'net/http'
+require 'net/https'
 
 module Clickatell
   class API
    
     # Used to run commands agains the Clickatell gateway.
     class CommandExecutor
-      def initialize(authentication_hash, debug=false)
+      def initialize(authentication_hash, secure=false, debug=false)
         @authentication_hash = authentication_hash
         @debug = debug
+        @secure = secure
       end
       
       # Builds a command object and sends it using HTTP GET. 
@@ -16,15 +18,23 @@ module Clickatell
       def execute(command_name, parameters={})
         request_uri = command(command_name, parameters)
         puts &quot;[debug] Sending request to #{request_uri}&quot; if @debug
-        Net::HTTP.get_response(request_uri)
+        get_response(request_uri).first
       end
       
       protected
         def command(command_name, parameters) #:nodoc:
-          Command.new(command_name).with_params(
+          Command.new(command_name, :secure =&gt; @secure).with_params(
             parameters.merge(@authentication_hash)
           )
         end
+        
+        def get_response(uri)
+          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 
   
   end</diff>
      <filename>lib/clickatell/api/command_executor.rb</filename>
    </modified>
    <modified>
      <diff>@@ -44,8 +44,13 @@ module Clickatell
                @options.show_status = true  
             end
             
+            opts.on('-S', '--secure',
+                &quot;Sends request using HTTPS&quot;) do
+                Clickatell::API.secure_mode = true
+              end
+            
             opts.on('-d', '--debug') do
-               @options.debugging_enabled = true
+               Clickatell::API.debug_mode = true
             end
           
             opts.on_tail('-h', '--help', &quot;Show this message&quot;) do</diff>
      <filename>lib/clickatell/utility/options.rb</filename>
    </modified>
    <modified>
      <diff>@@ -33,9 +33,25 @@ module Clickatell
   describe &quot;Command executor&quot; do
     it &quot;should create an API command with auth params and send it via HTTP get, returning the raw http response&quot; do
       executor = API::CommandExecutor.new(:session_id =&gt; '12345')
-      API::Command.should_receive(:new).with('cmdname').and_return(cmd=mock('command'))
-      cmd.should_receive(:with_params).with(:param_one =&gt; 'foo', :session_id =&gt; '12345').and_return(uri=mock('uri'))
-      Net::HTTP.should_receive(:get_response).with(uri).and_return(raw_response=mock('http response'))
+      API::Command.should_receive(:new).with('cmdname', :secure =&gt; false).and_return(cmd=mock('command'))
+      uri = stub('uri', :host =&gt; 'example.com', :port =&gt; 80, :scheme =&gt; 'http', :path =&gt; '/foo/bar', :query =&gt; 'a=b')
+      cmd.should_receive(:with_params).with(:param_one =&gt; 'foo', :session_id =&gt; '12345').and_return(uri)
+      Net::HTTP.should_receive(:new).with('example.com', 80).and_return(transport=mock('http'))
+      transport.should_receive(:use_ssl=).with(false)
+      transport.should_receive(:start).and_yield(yielded_transport=mock('http'))
+      yielded_transport.should_receive(:get).with('/foo/bar?a=b').and_return(raw_response=mock('http response'))
+      executor.execute('cmdname', :param_one =&gt; 'foo').should == raw_response
+    end
+    
+    it &quot;should create a secure API command and send command using HTTPS if secure is true&quot; do
+      executor = API::CommandExecutor.new({:session_id =&gt; '12345'}, secure=true)
+      API::Command.should_receive(:new).with('cmdname', :secure =&gt; true).and_return(cmd=mock('command'))
+      uri = stub('uri', :host =&gt; 'example.com', :port =&gt; 443, :scheme =&gt; 'https', :path =&gt; '/foo/bar', :query =&gt; 'a=b')
+      cmd.should_receive(:with_params).with(:param_one =&gt; 'foo', :session_id =&gt; '12345').and_return(uri)
+      Net::HTTP.should_receive(:new).with('example.com', 443).and_return(transport=mock('http'))
+      transport.should_receive(:use_ssl=).with(true)
+      transport.should_receive(:start).and_yield(yielded_transport=mock('http'))
+      yielded_transport.should_receive(:get).with('/foo/bar?a=b').and_return(raw_response=mock('http response'))
       executor.execute('cmdname', :param_one =&gt; 'foo').should == raw_response
     end
   end
@@ -43,7 +59,8 @@ module Clickatell
   describe &quot;API&quot; do
     before do
       API.debug_mode = false
-      API::CommandExecutor.should_receive(:new).with({:session_id =&gt; '1234'}, false).and_return(@executor = mock('command executor'))
+      API.secure_mode = false
+      API::CommandExecutor.should_receive(:new).with({:session_id =&gt; '1234'}, false, false).and_return(@executor = mock('command executor'))
       @api = API.new(:session_id =&gt; '1234')
     end
     
@@ -124,8 +141,20 @@ module Clickatell
   describe API, ' with no authentication options set' do
     it &quot;should build commands with no authentication options&quot; do
       API.debug_mode = false
+      API.secure_mode = false
+      api = API.new
+      API::CommandExecutor.should_receive(:new).with({}, false, false).and_return(executor=mock('command executor'))
+      executor.stub!(:execute)
+      api.ping('1234')
+    end
+  end
+  
+  describe API, ' in secure mode' do
+    it &quot;should execute commands securely&quot; do
+      API.debug_mode = false
+      API.secure_mode = true
       api = API.new
-      API::CommandExecutor.should_receive(:new).with({}, false).and_return(executor=mock('command executor'))
+      API::CommandExecutor.should_receive(:new).with({}, true, false).and_return(executor=mock('command executor'))
       executor.stub!(:execute)
       api.ping('1234')
     end</diff>
      <filename>spec/api_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>14aefba54fdb86c3469db556b59f9d4d8c6c87a4</id>
    </parent>
  </parents>
  <author>
    <name>luke</name>
    <email>luke@99183692-6b28-0410-aa2f-9dcdcacf4b0b</email>
  </author>
  <url>http://github.com/lukeredpath/clickatell/commit/ddf56f18877911474ea5e19d6a7cc83a7e86cca0</url>
  <id>ddf56f18877911474ea5e19d6a7cc83a7e86cca0</id>
  <committed-date>2007-09-10T13:45:16-07:00</committed-date>
  <authored-date>2007-09-10T13:45:16-07:00</authored-date>
  <message>Fixed SSL support and added --secure option to SMS utility

git-svn-id: svn://lukeredpath.co.uk/var/svn/opensource/clickatell/trunk@153 99183692-6b28-0410-aa2f-9dcdcacf4b0b</message>
  <tree>1c4905cf4b8a1cf11b3abaa20b7242672dc91d6b</tree>
  <committer>
    <name>luke</name>
    <email>luke@99183692-6b28-0410-aa2f-9dcdcacf4b0b</email>
  </committer>
</commit>
