Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Allow toggling of existing timers
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli Fatsi committed Oct 17, 2013
1 parent fe43f75 commit 1fdb8aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/harvest/api/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def all(date = ::Time.now, user = nil)
Harvest::TimeEntry.parse(JSON.parse(response.body)["day_entries"])
end

def toggle(id, user = nil)
response = request(:get, credentials, "/daily/timer/#{id}", :query => of_user_query(user))
Harvest::TimeEntry.parse(response.parsed_response).first
end

def create(entry, user = nil)
response = request(:post, credentials, '/daily/add', :body => entry.to_json, :query => of_user_query(user))
Harvest::TimeEntry.parse(response.parsed_response).first
Expand Down
19 changes: 18 additions & 1 deletion spec/functional/time_tracking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,22 @@
end
end

it 'allows toggling of timers'
it 'allows toggling of timers' do
cassette("time_tracking3") do
client = harvest.clients.create("name" => "Jane's Car Shop")
project = harvest.projects.create("name" => "Tracking Project", "client_id" => client.id)
harvest.projects.create_task(project, "A billable task")
task = harvest.tasks.all.detect {|t| t.name == "A billable task"}

entry = harvest.time.create("notes" => "Test api support", "hours" => 3, "spent_at" => "2009/12/28", "task_id" => task.id, "project_id" => project.id)

# start existing timer
started_entry = harvest.time.toggle(entry.id)
started_entry.timer_started_at.should_not == nil

# stop started timer
stopped_entry = harvest.time.toggle(started_entry.id)
stopped_entry.timer_started_at.should == nil
end
end
end

0 comments on commit 1fdb8aa

Please sign in to comment.