-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockify.psm1
More file actions
50 lines (41 loc) · 1.79 KB
/
Clockify.psm1
File metadata and controls
50 lines (41 loc) · 1.79 KB
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
# BC for < PS v3
if(!$PSScriptRoot) { $PSScriptRoot = Split-Path -parent $MyInvocation.MyCommand.Path; }
pushd $PSScriptRoot;
# Get the Clockify API key
$apiKey = Get-Content -Raw -Path "Clockify.key";
popd
function Stop-Clock
{
# Get user info
$resp = Invoke-WebRequest -Headers @{ "X-Api-Key" = $apiKey } -ContentType "application/json" -Uri "https://api.clockify.me/api/v1/user"
$clockifyUser = ConvertFrom-Json $resp.Content;
$defaultWorkspace = $clockifyUser.defaultWorkspace;
$clockifyUserId = $clockifyUser.id;
# Set end time to now UTC/Zulu time format
$endTime = @{ end = [DateTime]::UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ") };
$endTimeJson = ConvertTo-Json $endTime;
# Update the time entry on the server
Invoke-WebRequest -Headers @{ "X-Api-Key" = $apiKey } -ContentType "application/json" -Method PATCH -Uri "https://api.clockify.me/api/v1/workspaces/$defaultWorkspace/user/$clockifyUserId/time-entries" -Body $endTimeJson;
}
function Start-Clock
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Description
)
# Get user info
$resp = Invoke-WebRequest -Headers @{ "X-Api-Key" = $apiKey } -ContentType "application/json" -Uri "https://api.clockify.me/api/v1/user"
$clockifyUser = ConvertFrom-Json $resp.Content;
$defaultWorkspace = $clockifyUser.defaultWorkspace;
# Set description and start time
$startInfo = @{ start = [DateTime]::UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ"); description = $Description };
$startInfoJson = ConvertTo-Json $startInfo;
# Start timer on the server
Invoke-WebRequest -Headers @{ "X-Api-Key" = $apiKey } `
-ContentType "application/json" `
-Method POST `
-Uri "https://api.clockify.me/api/v1/workspaces/$defaultWorkspace/time-entries" `
-Body $startInfoJson;
}