-
Notifications
You must be signed in to change notification settings - Fork 4
/
TogglTimeEntry.php
77 lines (71 loc) · 3.49 KB
/
TogglTimeEntry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
class TogglTimeEntry extends Toggl{
public static $fields = array(
"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)
"billable", // (boolean, not required, default false, available for pro workspaces)
"start", // time entry start time (string, required, ISO 8601 date and time)
"stop", // time entry stop time (string, not 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)
"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", // timestamp that is sent in the response, indicates the time item was last updated
);
public static function createATimeEntry(array $params = array()){
foreach ($params as $name => $param){
if (array_search($name, self::$fields) === false){
return "Invalid Parameter: $name";
}
$params["time_entry"][$name] = $param;
unset($params[$name]);
}
$params['method'] = "POST";
$params['url'] = "https://www.toggl.com/api/v8/time_entries";
return self::send($params);
}
public static function startATimeEntry(array $params = array()){
foreach ($params as $name => $param){
if (array_search($name, self::$fields) === false){
return "Invalid Parameter: $name";
}
$params["time_entry"][$name] = $param;
unset($params[$name]);
}
$params['method'] = "POST";
$params['url'] = "https://www.toggl.com/api/v8/time_entries/start";
return self::send($params);
}
public static function getTimeEntryDetails($time_entry_id, array $params = array()){
foreach ($params as $name => $param){
if (array_search($name, self::$fields) === false){
return "Invalid Parameter: $name";
}
}
$params['method'] = "GET";
$params['url'] = "https://www.toggl.com/api/v8/time_entries/$time_entry_id";
return self::send($params);
}
public static function deleteATimeEntry($time_entry_id, array $params = array()){
foreach ($params as $name => $param){
if (array_search($name, self::$fields) === false){
return "Invalid Parameter: $name";
}
}
$params['method'] = "POST";
$params['url'] = "https://www.toggl.com/api/v8/time_entries/$time_entry_id";
return self::send($params);
}
public static function getTimeEntriesStartedInASpecificTimeRange(array $params = array()){
foreach ($params as $name => $param){
if (array_search($name, self::$fields) === false){
return "Invalid Parameter: $name";
}
}
$params['method'] = "GET";
$params['url'] = "https://www.toggl.com/api/v8/time_entries";
return self::send($params);
}
}