All Downloads are FREE. Search and download functionalities are using the official Maven repository.

oko_2.9.0-1.0.1.0.source-code.client.scala Maven / Gradle / Ivy

The newest version!
package hiroko

import dispatch._
import com.ning.http.client.{ AsyncHandler, RequestBuilder, Response }

object Client {
  val DefaultHeaders = Map("Accept" -> "application/json",
                           "User-Agent" -> "Hiroko/%s".format(BuildInfo.version))
  type Handler[T] = AsyncHandler[T]
  trait Completion {
    def apply[T](handler: Client.Handler[T]): Promise[T]
  }
}

/** a dispatch interface for https://api-docs.heroku.com/ */
case class Client(apikey: String, http: Http = Http)
  extends DefaultHosts
     with Methods {
   import Client._

  private [this] val credentials = BasicAuth(apikey)

  def request[T](req: RequestBuilder)(handler: Client.Handler[T]): Promise[T] =
    http(credentials.sign(req) <:< DefaultHeaders > handler)

  def complete(req: RequestBuilder): Client.Completion =
    new Client.Completion {
      override def apply[T](handler: Client.Handler[T]) =
        request(req)(handler)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy