Module: Toggl::Api::TimeEntry
- Included in:
- Base
- Defined in:
- lib/toggl_api/api/time_entry.rb
Instance Method Summary collapse
-
#create_time_entry(options) ⇒ Object
description: (string, required) wid: workspace ID (integer, required if pid or tid not supplied) pid: project ID (integer, not required) tid: task ID (integer, not required) start: time entry start time (string, required, ISO 8601 date and time) duration: time entry duration in seconds.
- #delete_time_entry(tid) ⇒ Object
-
#get_time_entries(start_date = nil, end_date = nil) ⇒ Object
(also: #time_entries)
default return last 9 days time entries.
- #get_time_entry(tid) ⇒ Object (also: #time_entry)
- #iso8601_date(date) ⇒ Object
- #start_time_entry(options) ⇒ Object
- #stop_time_entry(tid) ⇒ Object
- #update_time_entry(tid, options) ⇒ Object (also: #bulk_update_time_entries)
Instance Method Details
#create_time_entry(options) ⇒ Object
description: (string, required)
*wid*: workspace ID (integer, required if pid or tid not supplied)
*pid*: project ID (integer, not required)
*tid*: task ID (integer, not required)
*start*: time entry start time (string, required, ISO 8601 date and time)
*duration*: time entry duration in seconds. If the time entry is currently running, the duration attribute contains a negative value, denoting the start of the time entry in seconds since epoch (Jan 1 1970). The correct duration can be calculated as current_time + duration, where current_time is the current time in seconds since epoch. (integer, required)
*created_with*: the name of your client app (string, required)
stop: time entry stop time (string, not required, ISO 8601 date and time)
billable: (boolean, not required, default false, available for pro workspaces)
tags: a list of tag names (array of strings, not required)
duronly: should Toggl show the start and stop time of this time entry? (boolean, not required)
at: that is sent in the response, indicates the time item was last updated
18 19 20 21 |
# File 'lib/toggl_api/api/time_entry.rb', line 18 def create_time_entry() = .merge({:created_with => "Toggl Api Ruby Gem #{Toggl::VERSION}"}) post "/time_entries", (.key?(:time_entry) ? : {:time_entry => }) end |
#delete_time_entry(tid) ⇒ Object
66 67 68 |
# File 'lib/toggl_api/api/time_entry.rb', line 66 def delete_time_entry(tid) delete "/time_entries/#{tid}" end |
#get_time_entries(start_date = nil, end_date = nil) ⇒ Object Also known as: time_entries
default return last 9 days time entries
49 50 51 52 53 54 |
# File 'lib/toggl_api/api/time_entry.rb', line 49 def get_time_entries(start_date=nil, end_date=nil) = Hash.new ["start_date"] = iso8601_date(start_date) if start_date ["end_date"] = iso8601_date(end_date) if end_date get "/time_entries", end |
#get_time_entry(tid) ⇒ Object Also known as: time_entry
32 33 34 |
# File 'lib/toggl_api/api/time_entry.rb', line 32 def get_time_entry(tid) get "/time_entries/#{tid}" end |
#iso8601_date(date) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/toggl_api/api/time_entry.rb', line 37 def iso8601_date(date) case date when Time,Date iso = date.to_datetime.iso8601 when String iso = DateTime.parse(date).iso8601 else raise ArgumentError, "Can't convert #{date.class} to ISO-8601 Date/Time" end end |
#start_time_entry(options) ⇒ Object
23 24 25 26 |
# File 'lib/toggl_api/api/time_entry.rb', line 23 def start_time_entry() = Hashie::Mash.new post "/time_entries/start", (.key?(:time_entry) ? : {:time_entry => }) end |
#stop_time_entry(tid) ⇒ Object
28 29 30 |
# File 'lib/toggl_api/api/time_entry.rb', line 28 def stop_time_entry(tid) put "/time_entries/#{tid}/stop" end |
#update_time_entry(tid, options) ⇒ Object Also known as: bulk_update_time_entries
58 59 60 61 62 |
# File 'lib/toggl_api/api/time_entry.rb', line 58 def update_time_entry(tid,) tid = tid.join(",") if tid.is_a? Array = Hashie::Mash.new put "/time_entries/#{tid}", (.key?(:time_entry) ? : {:time_entry => }) end |