Skip to content

Commit 6078c99

Browse files
committed
Get-TogglAuthHeader - refactoring
1 parent 28fa0e1 commit 6078c99

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

Tests/Toggl.API.Tests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ Describe 'Toggl.API.Tests' {
88
It "should generate correct authorization header" {
99
$expected = 'Basic MTIzYTEyYWJjZDFhYjEyMzRkODZhNDcxZTkxNjI5NWM6YXBpX3Rva2Vu'
1010

11-
$header = Get-TogglAuthHeader -ApiKey 123a12abcd1ab1234d86a471e916295c
11+
$header = Get-TogglAuthHeader -ApiToken 123a12abcd1ab1234d86a471e916295c
1212
$header.ContainsKey('Authorization') | Should -Be $true
1313
$header.Authorization | Should Not BeNullOrEmpty
1414
$header.Authorization | Should -BeExactly $expected
1515
}
1616

17-
It "given apiKey=<apiKey>, it throws exception" -TestCases @(
18-
@{ apiKey = "" }
19-
@{ apiKey = $null }
17+
It "given apiToken=<apiToken>, it throws exception" -TestCases @(
18+
@{ apiToken = "" }
19+
@{ apiToken = $null }
2020
) {
21-
{ Get-TogglAuthHeader -ApiKey '' } | Should Throw "Cannot bind argument to parameter 'ApiKey' because it is an empty string."
21+
{ Get-TogglAuthHeader -ApiToken '' } | Should Throw "Cannot bind argument to parameter 'ApiToken' because it is an empty string."
2222
}
2323
}
2424
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function Get-TogglAuthHeader {
22
param (
33
[Parameter(Mandatory)]
4-
[string] $ApiKey
4+
[string] $ApiToken
55
)
66

7-
return @{ Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("$ApiKey`:api_token")) }
7+
return @{ Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("$ApiToken`:api_token")) }
88
}

Toggl.API/Toggl.API.psm1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
$Global:TogglBaseUrl = "https://api.track.toggl.com/api/v9"
2+
$Global:TogglReportsBaseUrl = "https://api.track.toggl.com/reports/api/v3"
3+
14
#Get public and private function definition files.
25
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public -Recurse -Filter *.ps1 -ErrorAction SilentlyContinue )
36
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private -Recurse -Filter *.ps1 -ErrorAction SilentlyContinue )

0 commit comments

Comments
 (0)