我正在为 REST Web 服务编写一个包装器,并且我希望拥有强类型的 Scala API。
以下是我目前正在做的事情:
def getMentions(count: Option[Int] = None,
sinceID: Option[TweetID] = None,
maxID: Option[TweetID] = None,
trimUser: Option[Boolean] = None,
contributorDetails: Option[Boolean] = None,
includeEntities: Option[Boolean] = None) : List[Tweet] = {
val parameters = Map("count" -> count,
"since_id" -> sinceID,
"max_id" -> maxID,
"trim_user" -> trimUser,
"contributor_details" -> contributorDetails,
"include_entities" -> includeEntities)
/*
* Convert parameters, which is a Map[String,Any] to a Map[String,String]
* (Removing Nones) and pass it to an object in charge of generating the request.
*/
...
}
这种方法是有效的,但它需要我手动生成parameters
地图。如果我能够访问表示参数及其值的 Map,那么我所做的将会更加清晰。