diff options
| author | Zack Hobson | 2013-11-19 11:57:08 -0800 |
|---|---|---|
| committer | Zack Hobson | 2013-11-19 11:57:08 -0800 |
| commit | 9b09db55bae0bf9c20e07c4d939c639e6373640e (patch) | |
| tree | 2e0e97cedb96d6ca18368c1e392a07b98a1b101f | |
| parent | 19fbf0cd25b7db54cbafc18658364a69fa0983a8 (diff) | |
| download | hcl-9b09db55bae0bf9c20e07c4d939c639e6373640e.tar.bz2 | |
Cancel a timesheet entry, closes #13
| -rw-r--r-- | lib/hcl/commands.rb | 17 | ||||
| -rw-r--r-- | lib/hcl/day_entry.rb | 9 | ||||
| -rw-r--r-- | lib/hcl/timesheet_resource.rb | 4 |
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}" |
