diff options
| author | Michael Bleigh | 2010-04-02 10:54:55 -0400 | 
|---|---|---|
| committer | Michael Bleigh | 2010-04-02 10:54:55 -0400 | 
| commit | 8b574a910d0ee3964a4ff6dd9b59546383476d37 (patch) | |
| tree | e8ebf8534c662759860878388d983973aa2b9201 /lib | |
| parent | 97a08d085bd2cf49948f7864734e3985874277ec (diff) | |
| download | hcl-8b574a910d0ee3964a4ff6dd9b59546383476d37.tar.bz2 | |
Add support for free accounts.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hcl/app.rb | 1 | ||||
| -rw-r--r-- | lib/hcl/timesheet_resource.rb | 18 | 
2 files changed, 11 insertions, 8 deletions
| diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index 649089c..b208d11 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -133,6 +133,7 @@ EOM          config['login'] = ask("Email Address: ")          config['password'] = ask("Password: ") { |q| q.echo = false }          config['subdomain'] = ask("Subdomain: ") +        config['ssl'] = %w(y yes).include?(ask("Use SSL? (y/n): ").downcase)          TimesheetResource.configure config          write_config config        end diff --git a/lib/hcl/timesheet_resource.rb b/lib/hcl/timesheet_resource.rb index a589059..cb5e9bd 100644 --- a/lib/hcl/timesheet_resource.rb +++ b/lib/hcl/timesheet_resource.rb @@ -7,13 +7,14 @@ module HCl          self.login = opts['login']          self.password = opts['password']          self.subdomain = opts['subdomain'] +        self.ssl = opts['ssl']        else          yield self        end      end      # configuration accessors -    %w[ login password subdomain ].each do |config_var| +    %w[ login password subdomain ssl ].each do |config_var|        class_eval <<-EOC          def self.#{config_var}= arg            @@#{config_var} = arg @@ -29,29 +30,30 @@ module HCl      end      def self.get action -      https_do Net::HTTP::Get, action +      http_do Net::HTTP::Get, action      end      def self.post action, data -      https_do Net::HTTP::Post, action, data +      http_do Net::HTTP::Post, action, data      end -    def self.https_do method_class, action, data = nil -      https   = Net::HTTP.new "#{subdomain}.harvestapp.com", 443 +    def self.http_do method_class, action, data = nil +      https   = Net::HTTP.new "#{subdomain}.harvestapp.com", (ssl ? 443 : 80)        request = method_class.new "/#{action}" -      https.use_ssl = true +      https.use_ssl = ssl        request.basic_auth login, password        request.content_type = 'application/xml'        request['Accept']    = 'application/xml'        response = https.request request, data -      return response.body        if response.kind_of? Net::HTTPSuccess          response.body +      elsif response.kind_of? Net::HTTPFound +        raise "Redirected in the request. Perhaps your ssl configuration variable is set incorrectly?"        else          raise 'failure'        end      end - +          def id        @data[:id]      end | 
