The end goal is to connect two query parameters that are being passed to a Play! web service request. It looks like:
WS
.url(requestUri)
.withQueryString(finalQueries)
I attempted to use a couple operators but it failed like so:
val finalQueries = queryParams match {
case Some(queries) =>
tokenParam ++ queries
case None =>
tokenParam
}
Error: value ++ is not a member of (String, String)
The API documentation shows that withQueryString accepts a (String, String)*
I’m a little confused with Play!’s withQueryString method since it does appear to complete replace the entire query string every time I access it. Any way to decently combine query strings?
Edit: A sample query string is below (the type syntax and its final appearance are a little confusing…):
val queryString = ("timeMin" -> "2012-08-20T01%3A11%3A06.000Z")
from your code, it seems to me that
queryParamsshould beOption[(String, String)], and from the error message,tokenParammust be(String, String)I think you can try this:
it works because
Optioncan be treated asSeq, eg:Seq(1, 2) ++ Some(3)will becomeSeq(1, 2, 3)andSeq(1, 2) ++ Nonewill be justSeq(1, 2)and then
.withQueryStringaccepts a(String, String)*means you can call it like.withQueryString(param1, param2, andMore),or you can call it with a
Seqand tell the compiler to treat it like anythingRepeated by writing: _*at the end of theSeqlike.withQueryString(Seq(param1, param2, andMore): _*)