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) ⇒ Object



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

def all(date = ::Time.now)
  date = ::Time.parse(date) if String === date
  response = request(:get, credentials, "/daily/#{date.yday}/#{date.year}")
  Harvest::TimeEntry.parse(response.body)
end

#create(entry) ⇒ Object



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

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

#delete(entry) ⇒ Object



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

def delete(entry)
  request(:delete, credentials, "/daily/delete/#{entry.to_i}")
  entry.id
end

#find(id) ⇒ Object



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

def find(id)
  response = request(:get, credentials, "/daily/show/#{id}")
  Harvest::TimeEntry.parse(response.body, :single => true)
end

#update(entry) ⇒ Object



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

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