Public/API/Get-SteamNews.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
75
76
77
78
79
80
81
82
83
84
85
86
function Get-SteamNews {
    <#
    .SYNOPSIS
    Returns the latest news of a game specified by its AppID.

    .DESCRIPTION
    Returns the latest news of a game specified by its AppID.

    .PARAMETER AppID
    AppID of the game you want the news of.

    .PARAMETER Count
    How many news entries you want to get returned.

    .PARAMETER MaxLength
    Maximum length of each news entry.

    .PARAMETER OutputFormat
    Format of the output. Options are json (default), xml or vdf.

    .EXAMPLE
    Get-SteamNews -AppID 440

    Lists number of news that are available for the AppID.

    .EXAMPLE
    Get-SteamNews -AppID 440 -Count 1

    Retrieves 1 (the latest) news item for the AppID 440.

    .INPUTS
    int64

    .OUTPUTS
    Returns a string that is either formatted as json, xml or vdf.

    An appnews object containing:

    appid, the AppID of the game you want news of

    newsitems, an array of news item information:
    - An ID, title and url.
    - A shortened excerpt of the contents (to maxlength characters), terminated by "..." if longer than maxlength.
    - A comma-separated string of labels and UNIX timestamp.

    .NOTES
    Author: Frederik Hjorslelv Nylander

    .LINK
    https://hjorslev.github.io/SteamPS/Get-SteamNews.html
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true,
            HelpMessage = 'AppID of the game you want the news of.')]
        [int]$AppID,

        [Parameter(Mandatory = $false,
            HelpMessage = 'How many news entries you want to get returned.')]
        [int]$Count,

        [Parameter(Mandatory = $false,
            HelpMessage = 'Maximum length of each news entry.')]
        [int]$MaxLength,

        [Parameter(Mandatory = $false,
            HelpMessage = 'Format of the output. Options are json (default), xml or vdf.')]
        [ValidateSet('json', 'xml', 'vdf')]
        [string]$OutputFormat = 'json'
    )

    begin {
        Write-Verbose -Message "[BEGIN ] Starting: $($MyInvocation.MyCommand)"
    }

    process {
        $Request = Invoke-WebRequest -Uri "http://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=$AppID&count=$Count&maxlength=$MaxLength&format=$OutputFormat" -UseBasicParsing

        Write-Output -InputObject $Request.Content
    } # Process

    end {
        Write-Verbose -Message "[END ] Ending: $($MyInvocation.MyCommand)"
    }
} # Cmdlet