I am trying to make a post request to Pusher api, but I am having trouble returning the right type, I a type mismatch; found : scala.concurrent.Future[play.api.libs.ws.Response] required: play.api.libs.ws.Response
def trigger(channel:String, event:String, message:String): ws.Response = {
val domain = "api.pusherapp.com"
val url = "/apps/"+appId+"/channels/"+channel+"/events";
val body = message
val params = List(
("auth_key", key),
("auth_timestamp", (new Date().getTime()/1000) toInt ),
("auth_version", "1.0"),
("name", event),
("body_md5", md5(body))
).sortWith((a,b) => a._1 < b._1 ).map( o => o._1+"="+URLEncoder.encode(o._2.toString)).mkString("&");
val signature = sha256(List("POST", url, params).mkString("\n"), secret.get);
val signatureEncoded = URLEncoder.encode(signature, "UTF-8");
implicit val timeout = Timeout(5 seconds)
WS.url("http://"+domain+url+"?"+params+"&auth_signature="+signatureEncoded).post(body
}
The request you are making with post
is asynchronous. That call returns immediately, but does not return a Response
object. Instead, it returns a Future[Response]
object, which will contain the Response
object once the http request is completed asynchronously.
If you want to block execution until the request is completed, do:
val f = Ws.url(...).post(...)
Await.result(f)
See more about futures here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With