forked from tomtorggler/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogmytime.ps1
74 lines (63 loc) · 1.89 KB
/
logmytime.ps1
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
function Get-LogMyTimeEntries {
[CmdletBinding()]
param (
$Key = 'b4x4xrkjpy'
)
$apiResult = Invoke-LMTApiCall -Key $Key -Uri https://api.logmytime.de/V1/Api.svc/TimeEntries | Select-Object -ExpandProperty results
foreach ($te in $apiResult) {
$out = [ordered]@{
'LastChange' = (Get-Date $te.LastChangeTime)
'Client' = (Get-LogMyTimeProject -InputObject $te).Client
'Project' = (Get-LogMyTimeProject -InputObject $te).Project
'Comment' = $te.Comment
'DurationString' = $te.DurationString
'Billable' = $te.Billable
}
Write-Output (New-Object -TypeName psobject -Property $out) | Sort-Object -Property LastChange -Descending
}
}
function Get-LogMyTimeProject {
[CmdletBinding()]
param (
$InputObject
)
process {
foreach ($project in $($InputObject.project.__deferred.uri)) {
$p = Invoke-LMTApiCall -Uri $project
$result = @{
"Project" = $($p.Name)
"Client" = (Get-LogMyTimeClient -InputObject $p)
}
Write-Output (New-Object -TypeName psobject -Property $result)
}
}
}
function Get-LogMyTimeClient {
[CmdletBinding()]
param (
$InputObject
)
process {
$cl = Invoke-LMTApiCall -Uri $($InputObject.client.__deferred.uri)
$cl.Name
}
}
function Invoke-LMTApiCall {
[CmdletBinding()]
param (
$Uri,
$Key = 'b4x4xrkjpy'
)
begin {
$Headers = @{
'X-LogMyTimeApiKey' = $key
'User-Agent' = 'PowerShell'
'accept' = 'application/json'
}
}
process {
Invoke-RestMethod -Method Get -Headers $Headers -Uri $Uri | Select-Object -ExpandProperty d
}
end {
}
}