Skip to content

Instantly share code, notes, and snippets.

@Molnfront
Last active December 15, 2015 03:39
Show Gist options
  • Save Molnfront/5195851 to your computer and use it in GitHub Desktop.
Save Molnfront/5195851 to your computer and use it in GitHub Desktop.
This gist will POST to StackMob and create a new schema if it does not exist and post two messages. Based on an implementation of Harry Klein´s (http://oauth.riaforge.org/) oAuth for ColdFusion. It uses oAuth 1.0 for signing requests. Tested on Railo Server 4.0.2, with PostgreSQL on OSX 10.7.5. For this to work you do not need a database. If you…
<cfprocessingdirective pageencoding="utf-8" />
<!--- cfcontent is also important for unicode --->
<cfcontent type="text/html charset=utf-8">
<!--- set up the parameters --->
<cfset sConsumerKey = 'yourPublickey'> <!--- Paste your dev or prod keys here --->
<cfset sConsumerSecret = 'youPrivatekey'> <!--- Paste your dev or prod keys here --->
<cfset OAUTH_VERIFIER = '' /> <!--- You get back these when doing oauth registration --->
<cfset token = '' /> <!--- You get back these when doing oauth registrationt --->
<cfset tokenSecret = '' /> <!--- You get back these when doing oauth registration --->
<!--- set up the required objects including signature method--->
<cfset oReqSigMethodSHA = CreateObject("component", "oauth.oauthsignaturemethod_hmac_sha1")>
<cfset oToken = CreateObject("component", "oauth.oauthtoken").init(sKey = token, sSecret = tokenSecret)>
<cfset oConsumer = CreateObject("component", "oauth.oauthconsumer").init(sKey = sConsumerKey, sSecret = sConsumerSecret)>
<cfset oReq = CreateObject("component", "oauth.oauthrequest").fromConsumerAndToken(
oConsumer = oConsumer,
oToken = oToken,
sHttpMethod = "POST",
sHttpURL = 'https://api.stackmob.com/chatmessage')> <!--- This will create the schema if it´s not exists! --->
<cfset oReq.signRequest(
oSignatureMethod = oReqSigMethodSHA,
oConsumer = oConsumer,
oToken = oToken)> <!--- Sign the request --->
<!--- Tested with some crap, to see that utf-8 works! --->
<cfset theMess = serializeJson([
{
"message": "hello world! åäö ÅÄÖ",
"author": "johndoeÅÖ"
},
{
"message": "goodbye world!",
"author": "johndoe€"
}
])>
<cfhttp url="#oReq.GETNORMALIZEDHTTPURL()#" method="POST" charset="utf-8">
<cfhttpparam encoded="no" type="CGI" name="accept" value="application/vnd.stackmob+json; version=0">
<cfhttpparam type="header" name="authorization" value="#oReq.TOHEADER()#" />
<cfhttpparam type="body" value="#theMess#" encoded="no">
</cfhttp>
<cfdump var="#cfhttp#" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment