Forked from anarcher/twitter_dispatch_example.scala
Created
December 18, 2011 01:22
-
-
Save tjweir/1492048 to your computer and use it in GitHub Desktop.
twitter dispatch example scala
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
scala> import dispatch._ | |
import dispatch._ | |
scala> import Http._ | |
import Http._ | |
scala> import json.Js._ | |
import json.Js._ | |
scala> import twitter._ | |
import twitter._ | |
scala> val http = new Http | |
http: dispatch.Http = dispatch.Http@1776426 | |
scala> var res = http(Search("#scala")) | |
INF: [console logger] dispatch: GET http://search.twitter.com/search.json?q=%23scala | |
scala> var item = res.head | |
item: dispatch.json.JsObject = {"from_user" : "bigmound", "to_user_id" : null, "profile_image_url" : "http:// | |
scala> item match { | |
| case Status.text(text) => println(text) | |
| } | |
http://ow.ly/2sXhU http://ow.ly/2sXi3 #scala | |
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
scala> import search._ | |
import search._ | |
scala> TwitterSearch("#니가_진짜_스칼라에_원하는게_모야") | |
INF: [console logger] dispatch: GET http://search.twitter.com/search.json?q=%23%EB%8B%88%EA%B0%80_%EC%A7%84%EC%A7%9C_%EC%8A%A4%EC%B9%BC%EB%9D%BC%EC%97%90_%EC%9B%90%ED%95%98%EB%8A%94%EA%B2%8C_%EB%AA%A8%EC%95%BC | |
res0: dispatch.Http.HttpPackage[List[dispatch.json.JsObject]] = List() | |
scala> val l = TwitterSearch("#scala") | |
INF: [console logger] dispatch: GET http://search.twitter.com/search.json?q=%23scala | |
l: dispatch.Http.HttpPackage[List[dispatch.json.JsObject]] = ... | |
scala> import dispatch.twitter._ | |
import dispatch.twitter._ | |
scala> for (i <- l) { | |
| val Search.from_user(user),Search.text(text) = i | |
| println("%s : %s \n%s".format(user,text,"-" * 100)) | |
| } | |
etorreborre : functional koans in #scala http://bit.ly/dbZDZT (switch branch for other languages) | |
---------------------------------------------------------------------------------------------------- | |
unixland : RT @Rubbish: RT @betehess: wow, #ensime just works now ♥ #scala #emacs #sbt #win | |
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
import dispatch._ | |
import dispatch.json.JsHttp._ | |
import dispatch.json.Js | |
import dispatch.json.Js._ | |
val s = :/("stream.twitter.com") / "1/statuses/filter.json" << Map("track" -> "#scalaqna") as ("username","password") | |
object Result extends Js { | |
val text = 'text ? str | |
} | |
futures.DefaultFuture.future { | |
http(s >> { | |
(stm,charset) => { | |
import java.io._ | |
println("start") | |
val reader: BufferedReader = new BufferedReader(new InputStreamReader(stm,charset)) | |
var line = reader.readLine() | |
while (line != null) { | |
line = reader.readLine() | |
println(line) | |
val jsres = Js(line) | |
val Result.text(text) = jsres | |
println("text="+text) | |
} | |
stm.close | |
} | |
}) | |
} |
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
import dispatch._ | |
val s = :/("stream.twitter.com") / "1/statuses/filter.json" | |
<< Map("track" -> "#scalaqna") as ("username","password") | |
val http = new Http | |
futures.DefaultFuture.future { | |
http(s >>> System.out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment