Skip to content

Instantly share code, notes, and snippets.

@hexx
Created March 15, 2012 08:46
Show Gist options
  • Save hexx/2043022 to your computer and use it in GitHub Desktop.
Save hexx/2043022 to your computer and use it in GitHub Desktop.
Post Tumblr
#!/usr/bin/env scalas
!#
/***
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch-http" % "0.8.8",
"net.databinder" %% "dispatch-oauth" % "0.8.8"
)
*/
import dispatch._
import dispatch.oauth.OAuth._
import dispatch.oauth.{ OAuth, Consumer }
object Tumblr {
val api = :/("api.tumblr.com") / "v2" / "blog"
val oauth = :/("www.tumblr.com") / "oauth"
}
val consumer = Consumer("YOUR CONSUMER KEY", "YOUR CONSUMER SECRET")
val username = "YOUR USERNAME"
val password = "YOUR PASSWORD"
val hostname = "YOUR HOSTNAME"
val title = "test title"
val body = "test body"
val http = new Http
val x_auth_params = Map("x_auth_mode" -> "client_auth", "x_auth_username" -> username, "x_auth_password" -> password)
val access_token_handler = Tumblr.oauth.secure / "access_token" << x_auth_params <@ (consumer, OAuth.oob) as_token
val access_token = http(access_token_handler)
val post_params = Map("type" -> "text", "title" -> title, "body" -> body)
val post_handler = Tumblr.api / hostname / "post" << post_params <@ (consumer, access_token) >|
http(post_handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment