Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class Project(name: String, description: String)
- def getScalaProjects: Seq[JsValue] = {
- val url = "https://api.github.com/search/repositories?q=scala"
- val gitScalaRepos = Source.fromURL(url).getLines
- val gitJSON = Try(Json.parse(gitScalaRepos.get mkString "n")) match {
- case Success(json) => json
- case Failure(f) => throw new AppException("Could not parse JSON.")
- }
- implicit val projectReads: Reads[Project] = (
- (JsPath "name").read[String] and
- (JsPath "description").read[String]
- )(Project.apply _)
- for {
- i <- 0 until 5
- p = (gitJSON "items")(i).validate[Project]
- p match {
- case s: JsSuccess[Project] => s.get
- case e: JsError => throw new AppException("Could not parse JSON: " +
- JsError.toFlatJson(e).toString())
- }
- } yield p
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement