Created
May 19, 2013 20:14
-
-
Save xuwei-k/5608828 to your computer and use it in GitHub Desktop.
scalaj-http Request Endo
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
libraryDependencies ++= Seq( | |
"org.scalaj" %% "scalaj-http" % "0.3.7", | |
"org.scalaz" %% "scalaz-core" % "7.0.0" | |
) | |
scalaVersion := "2.10.1" | |
licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT")) |
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 javax.net.ssl.SSLSocketFactory | |
import scalaj.http.Http.Request | |
import scalaj.http.{Token, HttpOptions} | |
import scalaj.http.HttpOptions.HttpOption | |
import scalaz.Endo | |
trait RequestEndo{ | |
def params(p: (String, String)*): Endo[Request] = Endo(_.params(p.toList)) | |
def params(p: List[(String, String)]): Endo[Request] = Endo(_.params(p)) | |
def headers(p: (String, String)*): Endo[Request] = Endo(_.headers(p.toList)) | |
def headers(p: List[(String, String)]): Endo[Request] = Endo(_.headers(p)) | |
def param(key: String, value: String): Endo[Request] = Endo(_.param(key, value)) | |
def header(key: String, value: String): Endo[Request] = Endo(_.header(key, value)) | |
def options(o: HttpOption*): Endo[Request] = Endo(_.options(o.toList)) | |
def auth(user: String, password: String): Endo[Request] = Endo(_.auth(user, password)) | |
def oauth(consumer: Token): Endo[Request] = Endo(_.oauth(consumer)) | |
def oauth(consumer: Token, token: Token): Endo[Request] = Endo(_.oauth(consumer, token)) | |
def oauth(consumer: Token, token: Token, verifier: String): Endo[Request] = | |
Endo(_.oauth(consumer, token, verifier)) | |
def oauth(consumer: Token, token: Option[Token], verifier: Option[String]): Endo[Request] = | |
Endo(_.oauth(consumer, token, verifier)) | |
def proxy(host: String, port: Int): Endo[Request] = Endo(_.proxy(host, port)) | |
def method(method: String): Endo[Request] = options(HttpOptions.method(method)) | |
def connTimeout(timeout: Int): Endo[Request] = options(HttpOptions.connTimeout(timeout)) | |
def readTimeout(timeout: Int): Endo[Request] = options(HttpOptions.readTimeout(timeout)) | |
val allowUnsafeSSL: Endo[Request] = options(HttpOptions.allowUnsafeSSL) | |
def sslSocketFactory(sslSocketFactory: SSLSocketFactory): Endo[Request] = | |
options(HttpOptions.sslSocketFactory(sslSocketFactory)) | |
} | |
object RequestEndo extends RequestEndo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment