I'm trying to make a scala interface to the spotify API. I'm using it to learn Scala. I come from mostly a python background.
import dispatch._, Defaults._
trait Request {
val name: String
val endpoint: String
}
case class Track(name: String) extends Request {
override val endpoint = "track.json"
}
case class Album(name: String) extends Request {
override val endpoint = "album.json"
}
case class Artist(name: String) extends Request {
override val endpoint = "artist.json"
}
object Spotify {
def getResponse(req: Request) = {
val params = Map("q" -> req.name)
val spotifyUrl = host("ws.spotify.com")
spotifyUrl / "search"/ "1" / req.endpoint <<? params
}
val foo = Album("foo")
val songs = Http(getResponse(foo) OK as.String)
}
I feel like getResponse
should be in the Request trait, or something since it's generic enough to only need the overridden endpoint
- but not sure.
Any general recommendations on structuring this sort of thing would be helpful.