oko_2.9.0-1.0.1.0.source-code.client.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hiroko_2.9.0-1 Show documentation
Show all versions of hiroko_2.9.0-1 Show documentation
An interface for the Heroku API
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)
}
}