IFTTT_Maker_PowerShell.psm1

Set-StrictMode -Version Latest
<#
    .SYNOPSIS
        Triggers an event on the IFTTT Maker Channel.
    .DESCRIPTION
        Send-Maker triggers an event on the IFTTT Maker Channel.
        The event can have up to 3 values that can be passed.
    .PARAMETER EventName
        The name of the event to trigger on the IFTTT Maker Channel.
    .PARAMETER Key
        The secret key you got from IFTTT for triggering events on the Maker Channel.
    .PARAMETER Value1
        First value passed to the event (ingredient Value1).
    .PARAMETER Value2
        Second value passed to the event (ingredient Value2).
    .PARAMETER Value3
        Third value passed to the event (ingredient Value3).
#>

function Send-IFTTMaker
{
    [CmdletBinding()]
    param
    (
        [ValidateNotNullOrEmpty()]
        [Parameter(Position=0,Mandatory=$true,HelpMessage="The secret key you got from IFTTT for triggering events on the Maker Channel.")]
        [string] $Key,

        [ValidateNotNullOrEmpty()]
        [Parameter(Position=1,Mandatory=$true,HelpMessage="The name of the event to trigger on the IFTTT Maker Channel")]
        [string] $EventName,
        
        [ValidateNotNullOrEmpty()]
        [Parameter(Position=2,ValueFromPipeline=$true,HelpMessage="First value passed to the event (ingredient Value1).")]
        [string] $Value1,
        
        [ValidateNotNullOrEmpty()]
        [Parameter(Position=3,HelpMessage="Second value passed to the event (ingredient Value2).")]
        [string] $Value2,
        
        [ValidateNotNullOrEmpty()]
        [Parameter(Position=4,HelpMessage="Third value passed to the event (ingredient Value3).")]
        [string] $Value3
    )

    $Site="https://maker.ifttt.com/trigger/"
    if(-not($Key)) { Throw �You must supply a value for -Key� }
    if(-not($EventName)) { Throw �You must supply a value for -EventName� }
    if(-not($Site)) { Throw �You must supply a value for -Site� }

    [uri]$MyURL = "$Site$EventName/with/key/$Key"
    
    $BodyDic= @{}
    if($Value1)
    {   $BodyDic.value1=$Value1
        if($Value2)
        {   $BodyDic.value2=$Value2
            if($Value3)
            {    $BodyDic.value3=$Value3}}}
    
        $BodyJson = ConvertTo-Json $BodyDic

    Invoke-WebRequest -Uri $MyURL -Method Post -ContentType "application/json" -Body $BodyJson
}