Class: Harvest::API::Time

Inherits:
Base
  • Object
show all
Defined in:
lib/harvest/api/time.rb

Instance Attribute Summary

Attributes inherited from Base

#credentials

Instance Method Summary collapse

Methods inherited from Base

api_model, #initialize

Constructor Details

This class inherits a constructor from Harvest::API::Base

Instance Method Details

#all(date = ::Time.now, user = nil) ⇒ Object



10
11
12
# File 'lib/harvest/api/time.rb', line 10

def all(date = ::Time.now, user = nil)
  Harvest::TimeEntry.parse(daily(date, user)["day_entries"])
end

#create(entry, user = nil) ⇒ Object



23
24
25
26
# File 'lib/harvest/api/time.rb', line 23

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
end

#delete(entry, user = nil) ⇒ Object



33
34
35
36
# File 'lib/harvest/api/time.rb', line 33

def delete(entry, user = nil)
  request(:delete, credentials, "/daily/delete/#{entry.to_i}", :query => of_user_query(user))
  entry.id
end

#find(id, user = nil) ⇒ Object



5
6
7
8
# File 'lib/harvest/api/time.rb', line 5

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

#toggle(id, user = nil) ⇒ Object



18
19
20
21
# File 'lib/harvest/api/time.rb', line 18

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

#trackable_projects(date = ::Time.now, user = nil) ⇒ Object



14
15
16
# File 'lib/harvest/api/time.rb', line 14

def trackable_projects(date = ::Time.now, user = nil)
  Harvest::TrackableProject.parse(daily(date, user)["projects"])
end

#update(entry, user = nil) ⇒ Object



28
29
30
31
# File 'lib/harvest/api/time.rb', line 28

def update(entry, user = nil)
  request(:put, credentials, "/daily/update/#{entry.to_i}", :body => entry.to_json, :query => of_user_query(user))
  find(entry.id, user)
end