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

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



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

def all(date = ::Time.now, user = nil)
  date = ::Time.parse(date) if String === date
  response = request(:get, credentials, "/daily/#{date.yday}/#{date.year}", :query => of_user_query(user))
  Harvest::TimeEntry.parse(JSON.parse(response.body)["day_entries"])
end

- (Object) create(entry)



16
17
18
19
# File 'lib/harvest/api/time.rb', line 16

def create(entry)
  response = request(:post, credentials, '/daily/add', :body => entry.to_json)
  Harvest::TimeEntry.parse(response.parsed_response).first
end

- (Object) delete(entry, user = nil)



26
27
28
29
# File 'lib/harvest/api/time.rb', line 26

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

- (Object) find(id, user = nil)



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

- (Object) update(entry, user = nil)



21
22
23
24
# File 'lib/harvest/api/time.rb', line 21

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