Created
January 11, 2019 16:04
-
-
Save brettmillerb/de44294739266900c43a6a4d547f7edc to your computer and use it in GitHub Desktop.
Twitch User Events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-TwitchEvent { | |
[CmdletBinding(DefaultParameterSetName = 'Standard')] | |
param ( | |
[Parameter(Mandatory, | |
ParameterSetName = 'Standard')] | |
[string] | |
$UserName, | |
[Parameter(Mandatory, | |
ParameterSetName = 'Pipeline', | |
ValueFromPipeline, | |
ValueFromPipelineByPropertyName)] | |
[psobject] | |
$InputObject, | |
[switch] | |
$ShowArchive, | |
$Token = $Script:Token | |
) | |
process { | |
foreach ($user in $InputObject) { | |
$streamsUri = "{0}/streams?user_login={1}" -f $Script:Uri, $user.UserName | |
$archiveUri = "{0}/videos?user_id={1}" -f $Script:Uri, $user.UserID | |
$streamsResults = Invoke-RestMethod -Uri $streamsUri -Headers $script:Headers | |
$archiveResults = Invoke-RestMethod -Uri $archiveUri -Headers $script:Headers | |
if ($streamsResults.data) { | |
"Streaming Live Now" | |
[PSCustomObject]@{ | |
UserName = $streamsResults.data.user_name | |
StreamTitle = $streamsResults.data.title | |
ViewerCount = $streamsResults.data.viewer_count | |
StartedAt = $streamsResults.data.started_at | |
} | |
} | |
else { | |
"No Live Stream Available" | |
} | |
if ($ShowArchive) { | |
"Archive Videos" | |
$archiveResults.data | ForEach-Object { | |
[PSCustomObject]@{ | |
UserName = $_.user_name | |
StreamTitle = $_.title | |
Url = $_.url | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-TwitchUser { | |
param ( | |
[string] | |
$UserName, | |
$Token = $Script:Token | |
) | |
$usersUri = "{0}/users/?login={1}" -f $script:Uri, $UserName | |
try { | |
Invoke-RestMethod -Uri $usersUri -Method Get -Headers $Script:Headers | | |
Select-Object -ExpandProperty Data | ForEach-Object { | |
[PSCustomObject]@{ | |
UserId = $_.id | |
UserName = $_.display_name | |
Description = $_.description | |
ViewCount = $_.view_count | |
} | |
} | |
} | |
catch { | |
$_ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-TwitchConfiguration { | |
[CmdletBinding()] | |
param ( | |
[string] | |
$Token | |
) | |
$Script:Token = $Token | |
$Script:Uri = "https://api.twitch.tv/helix" | |
$Script:Headers = @{"Client-ID" = $Token} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment