PoshCode Archive  Artifact [d000cb71b7]

Artifact d000cb71b7feaa8f108e4b1b667a0e41048a7377de287c4af07256ca97af9ae1:

  • File Get-ShortURL.ps1 — part of check-in [f61488c21b] at 2018-06-10 12:57:00 on branch trunk — Uses the Bit.ly api to create a short url. Requires a login and api key from http://bit.ly (user: unknown size: 778)

# encoding: ascii
# api: powershell
# title: Get-ShortURL
# description: Uses the Bit.ly api to create a short url. Requires a login and api key from http://bit.ly
# version: 2.0.1
# type: function
# license: CC0
# function: Get-ShortURL
# x-poshcode-id: 1407
# x-archived: 2009-10-26T15:25:25
#
#
Function Get-ShortURL {
	Param($longURL, $login, $apiKey)	
	$url = "http://api.bit.ly/shorten?version=2.0.1&format=xml&longUrl=$longURL&login=$login&apiKey=$apikey"
	$request = [net.webrequest]::Create($url)
	$responseStream = new-object System.IO.StreamReader($request.GetResponse().GetResponseStream())
	$response = $responseStream.ReadToEnd()
	$responseStream.Close()
	
	$result = [xml]$response
	Write-Output $result.bitly.results.nodeKeyVal.shortUrl
}