-
Notifications
You must be signed in to change notification settings - Fork 1
/
job.ps1
53 lines (50 loc) · 1.32 KB
/
job.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
<#
.Synopsis
Call the Convenus API to get the room status.
.DESCRIPTION
Given a list of room, call the Convenus API to get the room status.
.EXAMPLE
"bojackson@hudl.com", "gordie@hudl.com" | Get-RoomStatus
#>
function Get-RoomStatus
{
[CmdletBinding()]
Param
(
# List of room
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string[]]
$Room
)
Begin
{
$result = @{}
}
Process
{
$url = "http://calendars/api/rooms/$Room/minutes/5"
$status = Invoke-RestMethod $url
$result += @{"$Room" = $status}
}
End
{
return $result
}
}
$jsonFile = "C:\Temp\devices.json"
$jsonObj = Get-Content $jsonFile -Raw | ConvertFrom-Json
$rooms=@{}
foreach ($p in $jsonObj.rooms.psobject.properties.name){
$rooms[$p]=$jsonObj.rooms.$p
}
$result = $rooms.Keys | Get-RoomStatus
foreach ($r in $result.GetEnumerator()){
$deviceId = $rooms[$($r.Name)]
$status = $r.Value
$url = "https://api.spark.io/v1/devices/$deviceId/led"
$postParams = @{access_token=$env:SparkCoreAccessToken;params="$status"}
Invoke-RestMethod $url -Method Post -Body $postParams
}