summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZack Hobson2013-11-19 11:57:08 -0800
committerZack Hobson2013-11-19 11:57:08 -0800
commit9b09db55bae0bf9c20e07c4d939c639e6373640e (patch)
tree2e0e97cedb96d6ca18368c1e392a07b98a1b101f
parent19fbf0cd25b7db54cbafc18658364a69fa0983a8 (diff)
downloadhcl-9b09db55bae0bf9c20e07c4d939c639e6373640e.tar.bz2
Cancel a timesheet entry, closes #13
-rw-r--r--lib/hcl/commands.rb17
-rw-r--r--lib/hcl/day_entry.rb9
-rw-r--r--lib/hcl/timesheet_resource.rb4
3 files changed, 30 insertions, 0 deletions
diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb
index 00ab7b1..eb83dcd 100644
--- a/lib/hcl/commands.rb
+++ b/lib/hcl/commands.rb
@@ -24,6 +24,23 @@ module HCl
nil
end
+ def cancel
+ entry = DayEntry.with_timer || DayEntry.last
+ if entry
+ if entry.cancel
+ puts "Deleted entry #{entry}."
+ else
+ puts "Failed to delete #{entry}!"
+ exit 1
+ end
+ else
+ puts 'Nothing to cancel.'
+ exit 1
+ end
+ end
+ alias_method :oops, :cancel
+ alias_method :nvm, :cancel
+
def unset key
@settings.delete key
write_settings
diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb
index 6237fea..214fbe0 100644
--- a/lib/hcl/day_entry.rb
+++ b/lib/hcl/day_entry.rb
@@ -23,6 +23,15 @@ module HCl
end
end
+ def cancel
+ begin
+ DayEntry.delete("daily/delete/#{id}")
+ rescue TimesheetResource::Failure
+ return false
+ end
+ true
+ end
+
def notes
super || @data[:notes] = ''
end
diff --git a/lib/hcl/timesheet_resource.rb b/lib/hcl/timesheet_resource.rb
index fd6257b..c4a62f6 100644
--- a/lib/hcl/timesheet_resource.rb
+++ b/lib/hcl/timesheet_resource.rb
@@ -37,6 +37,10 @@ module HCl
http_do Net::HTTP::Post, action, data
end
+ def self.delete action
+ http_do Net::HTTP::Delete, action
+ end
+
def self.http_do method_class, action, data = nil
https = Net::HTTP.new "#{subdomain}.harvestapp.com", (ssl ? 443 : 80)
request = method_class.new "/#{action}"