-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKayakoAPI.psm1
More file actions
55 lines (45 loc) · 1.56 KB
/
Copy pathKayakoAPI.psm1
File metadata and controls
55 lines (45 loc) · 1.56 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
51
52
53
54
55
# Stop if we don't have an API secret file
if(!(test-path "$psscriptroot\secret")){ write-error "Missing secret file." ; break }
# Dot source functions with progress...
"$psscriptroot/Functions" | foreach-object {
$c = split-path $_ -leaf
$i = get-childitem $_ -rec -file -inc *.ps1 | sort-object name
if($i){
0..$($i.count -1)| foreach-object {
$n = ( $_ / $i.count ) * 100
write-progress "Loading $(split-path $psscriptroot -leaf) ..." -status $c -currentoperation $i[$_].name -percentcomplete $n
. $i[$_].fullname
}
write-progress "Complete!" -completed
}
}
# Read secret and parse into config
$config = @{
epoch = get-date '1/1/1970 5:00AM'
tz_offset = (get-timezone).baseutcoffset.hours
time_properties = @(
'lastactivity'
'creationtime'
'nextreplydue'
'laststaffreply'
'lastuserreply'
'dateline'
)
}
foreach($line in (get-content "$psscriptroot\secret")){
$k = $line.split('=')[0]
$v = $line.split('=')[1..$($line.split('=').count)] -join '='
if($k -eq 'server'){
$proto = ($v.split('/')|?{$_})[0]
$host = ($v.split('/')|?{$_})[1]
$api = 'api/index.php?'
$v = "$proto//$host/$api"
}
$config.add($k.trim(), $v.trim())
}
if(!$config.server -or !$config.apikey -or !$config.secret){
write-error "Invalid secret file. Must include server URL, API Key, and Secret key."
break
}
# Set TLS version 1.2
[net.servicepointmanager]::securityprotocol = [net.securityprotocoltype]::tls12