Created
December 15, 2012 16:55
-
-
Save roulupen/4297073 to your computer and use it in GitHub Desktop.
Google API URL Shortening by ColdFusion
This file contains 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
<cffunction name="shortenURLByGoogleAPI" access="public" returntype="Struct" hint="Takes long url as input parameter returns a struct containing both short and long url"> | |
<cfargument name="longURL" required="true" type="string" hint="Long URL value" /> | |
<cfset var httpReturnStruct = structNew() /> | |
<cfset var inputParameter = {"longUrl" = arguments.longURL } /> | |
<cfhttp url="https://www.googleapis.com/urlshortener/v1/url" method="post" result="httpReturnStruct"> | |
<cfhttpparam type="header" name="Content-Type" value="application/json" /> | |
<cfhttpparam type="body" value="#serializeJSON(inputParameter)#" /> | |
</cfhttp> | |
<cfreturn deserializeJSON(httpReturnStruct.Filecontent.toString()) /> | |
</cffunction> | |
<cffunction name="expandURLByGoogleAPI" access="public" returntype="Struct" hint="Takes short url as input parameter returns a struct containing both short and long url"> | |
<cfargument name="shortURL" required="true" type="string" hint="Short URL value" /> | |
<cfset var httpReturnStruct = structNew() /> | |
<cfhttp url="https://www.googleapis.com/urlshortener/v1/url" method="get" result="httpReturnStruct"> | |
<cfhttpparam type="header" name="Content-Type" value="application/json" /> | |
<cfhttpparam type="url" name="shortUrl" value="#arguments.shortURL#" /> | |
</cfhttp> | |
<cfreturn deserializeJSON(httpReturnStruct.Filecontent.toString()) /> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment