PoshCode Archive  Artifact [7844cfaf54]

Artifact 7844cfaf542c08b3a0e27dae13c6ba3b5d260b3e92311faeaf669ae20713d8c1:

  • File Get-TinyUrl.ps1 — part of check-in [2d5eb6e619] at 2018-06-10 14:08:57 on branch trunk — Get a short url, using tiny-url api for shortening (user: Alvaro Torres size: 1734)

# encoding: ascii
# api: powershell
# title: Get-TinyUrl
# description: Get a short url, using tiny-url api for shortening
# version: 0.1
# type: function
# author: Alvaro Torres
# license: CC0
# function: Get-TinyUrl
# x-poshcode-id: 6140
# x-archived: 2016-09-09T00:45:18
# x-published: 2016-12-18T00:09:00
#
#
function Get-TinyUrl
{
    [CmdletBinding()]
    [OutputType([string])]
    Param
    (
        [Parameter(Mandatory,ValueFromPipeline=$true)]
        [string]
        $Url,

        [ValidateSet('xml','json', 'text')]
        [string]
        $Format = 'text',

        #Provider String List => http://tiny-url.info/open_api.html#provider_list
        [ValidateSet('0_mk', '0l_ro', '2u_lc', '3le_ru', '888_hn', '9mp_com', 'ad_vu', 'b54_in', 'bb-h_me', 'bim_im', 'bit_ly', 'chilp_it', 'clicky_me', 'cmprs_me', 'cort_as', 'crum_bs', 'curt_cc', 'cut_by', 'dfly_pk', 'dft_ba', 'di_gd', 'dlvr_it', 'dok_do', 'doo_ly', 'dssurl_com')]        
        [string]
        $Provider = '0_mk'
    )

    #Use a Proxy if any configured
    $SystemProxy = ([System.Net.WebProxy]::GetDefaultProxy().Address.AbsoluteUri)
    
    #Request API Key => http://tiny-url.info/request_api_key.html
    $TinyUrlApiKey = 'YOUR-APIKEY'
    $TinyUrlApiUrl = 'http://tiny-url.info/api/v1/create'

    #API Documentation => http://tiny-url.info/open_api.html
    $RequestUrl = 'http://tiny-url.info/api/v1/create?apikey={0}&provider={1}&format={2}&url={3}' -f $TinyUrlApiKey, $Provider, $Format, $Url
    Write-Debug $RequestUrl
   Invoke-RestMethod -Uri $RequestUrl -Method Get -Proxy $SystemProxy | Write-Output
}

#'https://msdn.microsoft.com/es-es/library/system.uri(v=vs.110).aspx' | Get-TinyUrl