summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorZack Hobson2009-07-20 15:25:25 -0700
committerZack Hobson2009-07-20 15:25:25 -0700
commit614c3b07bfd5ba18670e2af399247174770001f0 (patch)
treefefac7af4d2f04381c5ecb0da257b1859a6f9846 /lib
parent3a1103f72f5ef06ae6c9e1c6d6719968fbd1e091 (diff)
downloadhcl-614c3b07bfd5ba18670e2af399247174770001f0.tar.bz2
use net/https instead of curb
Diffstat (limited to 'lib')
-rw-r--r--lib/hcl.rb7
-rw-r--r--lib/hcl/day_entry.rb10
-rw-r--r--lib/hcl/task.rb3
-rw-r--r--lib/hcl/timesheet_resource.rb46
4 files changed, 34 insertions, 32 deletions
diff --git a/lib/hcl.rb b/lib/hcl.rb
index 1313024..66350c2 100644
--- a/lib/hcl.rb
+++ b/lib/hcl.rb
@@ -1,8 +1,10 @@
require 'yaml'
require 'rexml/document'
+require 'net/http'
+require 'net/https'
require 'rubygems'
-require 'curb'
+#require 'curb'
require 'chronic'
require 'hcl/timesheet_resource'
@@ -72,7 +74,8 @@ class HCl
def start *args
task = Task.find args.shift
puts "Starting timer for #{task}"
- puts task.start(*args)
+ day_entry = task.start(*args)
+ puts "Time is running on #{day_entry}"
end
def show *args
diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb
index 204ff5d..e23f7e9 100644
--- a/lib/hcl/day_entry.rb
+++ b/lib/hcl/day_entry.rb
@@ -5,7 +5,15 @@ class HCl
# defaults to today.
def self.all date = nil
url = date.nil? ? 'daily' : "daily/#{date.strftime '%j/%Y'}"
- doc = REXML::Document.new perform url
+ from_xml get(url)
+ end
+
+ def to_s
+ "#{client} #{project} #{task} (#{hours})"
+ end
+
+ def self.from_xml xml
+ doc = REXML::Document.new xml
Task.cache_tasks doc
doc.root.elements.collect('day_entries/day_entry') do |day|
new xml_to_hash(day)
diff --git a/lib/hcl/task.rb b/lib/hcl/task.rb
index 761991e..0874f51 100644
--- a/lib/hcl/task.rb
+++ b/lib/hcl/task.rb
@@ -27,7 +27,7 @@ class HCl
def start *args
notes = args.join ' '
- Task.send_data "/daily/add", <<-EOT
+ day = DayEntry.from_xml Task.post("daily/add", <<-EOT)
<request>
<notes>#{notes}</notes>
<hours></hours>
@@ -36,6 +36,7 @@ class HCl
<spent_at type="date">#{Date.today}</spent_at>
</request>
EOT
+ return day
end
end
end
diff --git a/lib/hcl/timesheet_resource.rb b/lib/hcl/timesheet_resource.rb
index e13735e..381fe53 100644
--- a/lib/hcl/timesheet_resource.rb
+++ b/lib/hcl/timesheet_resource.rb
@@ -26,40 +26,30 @@ class HCl
@data = params
end
- def self.perform action
- client = session action
- if client.http_get
- client.body_str
- else
- raise "failed"
- end
+ def self.get action
+ https_do Net::HTTP::Get, action
+ end
+
+ def self.post action, data
+ https_do Net::HTTP::Post, action, data
end
- def self.send_data action, data
- client = session action
- client.multipart_form_post = true
- data_field = Curl::PostField.file('data','data') { data }
- if client.http_post data_field
- client.body_str
+ def self.https_do method_class, action, data = nil
+ https = Net::HTTP.new "#{subdomain}.harvestapp.com", 443
+ request = method_class.new "/#{action}"
+ https.use_ssl = true
+ 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
else
- raise "failed"
+ raise 'failure'
end
end
- def self.session action
- client = Curl::Easy.new("https://#{subdomain}.harvestapp.com/#{action}")
- client.headers['Accept'] = 'application/xml'
- client.headers['Content-Type'] = 'application/xml'
- client.http_auth_types = Curl::CURLAUTH_BASIC
- client.userpwd = "#{login}:#{password}"
- client
- #client = Patron::Session.new
- #client.timeout = 10
- #client.username = login
- #client.password = password
- #if client.get "https://#{subdomain}.harvestapp.com/#{action}"
- end
-
def id
@data[:id]
end