Skip to content

@tjweir /gist:1501796 forked from tommorris/gist:437512
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
talking to oauth-out-of-band fireeagle using scala's databinder dispatch oauth
// Welcome to Scala version 2.7.5.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).
// Type in expressions to have them evaluated.
// Type :help for more information.
scala> import dispatch._
import dispatch._
scala> import oauth._
import oauth._
scala> import OAuth._
import OAuth._
scala> import scala.xml._
import scala.xml._
scala> val fe = (:/("fireeagle.yahooapis.com") / "oauth").secure
fe: dispatch.Request = dispatch.Request@65370ce9
scala> val oauth = Consumer("[seekrit!]", "[also seekrit!]")
oauth: dispatch.oauth.Consumer = Consumer([secret!],[secret!])
scala> val h = new Http
h: dispatch.Http = dispatch.Http@1045651b
scala> val request_token = h(fe / "request_token" << Map("oauth_callback" -> "oob") <@ oauth as_token)
// INF: [console logger] dispatch: POST https://fireeagle.yahooapis.com/oauth/request_token
request_token: dispatch.oauth.Token = Token([secret],[secret])
scala> request_token
res0: dispatch.oauth.Token = Token([secret],[secret])
scala> fe / "authorize" <<? request_token
res1: dispatch.Request = dispatch.Request@57ced290
scala> (fe / "authorize" <<? request_token).to_uri
res2: java.net.URI = https://fireeagle.yahooapis.com/oauth/authorize?oauth_token=[secret]
// At this point, the loyal user went off to the relevant URL and authenticated with the application.
// He returned with an OAuth verification token. What a nice user.
scala> val access_token = h(fesecure / "access_token" << Map("oauth_verifier" -> "KXfQgG") <@ (oauth, request_token) as_token)
// INF: [console logger] dispatch: POST https://fireeagle.yahooapis.com/oauth/access_token
access_token: dispatch.oauth.Token = Token([more secret],[omg secret])
scala> val feapi = (:/("fireeagle.yahooapis.com") / "api" / "0.1").secure
feapi: dispatch.Request = dispatch.Request@16dba1f7
scala> val location = XML.loadString(h(feapi / "user" <@ (oauth, access_token) as_str))
// INF: [console logger] dispatch: GET https://fireeagle.yahooapis.com/api/0.1/user
location: scala.xml.Elem =
<rsp stat="ok" xmlns:georss="http://www.georss.org/georss">
<user token="azfpzT5ah3Ol" located-at="2010-06-14T02:20:47-07:00" readable="true" writable="true">
<location-hierarchy timezone="Europe/London" string="23424975|24554868|12602173|26788690|26352313">
<location best-guess="true">
<georss:point>51.130219 0.262814</georss:point>
...
scala> location \\ "location"
res4: scala.xml.NodeSeq =
<location best-guess="true" xmlns:georss="http://www.georss.org/georss">
<georss:point>51.130219 0.262814</georss:point>
<label></label>
<level>0</level>
<level-name>exact</level-name>
<located-at>2010-06-14T02:20:47-07:00</located-at>
<name>Station Approach, Tunbridge Wells, TN1 1</name>
<normal-name>S...
/* and once again, this time just as a script without the repl */
import dispatch._
import oauth._
import OAuth._
import scala.xml._
val fe = (:/("fireeagle.yahooapis.com") / "oauth").secure
val oauth = Consumer("[seekrit!]", "[also seekrit!]")
val h = new Http
val request_token = h(fe / "request_token" << Map("oauth_callback" -> "oob") <@ oauth as_token)
fe / "authorize" <<? request_token
(fe / "authorize" <<? request_token).to_uri
// At this point, the loyal user went off to the relevant URL and authenticated with the application.
// He returned with an OAuth verification token. What a nice user.
val access_token = h(fesecure / "access_token" << Map("oauth_verifier" -> "KXfQgG") <@ (oauth, request_token) as_token)
val feapi = (:/("fireeagle.yahooapis.com") / "api" / "0.1").secure
val location = XML.loadString(h(feapi / "user" <@ (oauth, access_token) as_str))
location \\ "location"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.