Skip to content

Instantly share code, notes, and snippets.

@dhoss
Last active August 29, 2015 14:26
Show Gist options
  • Save dhoss/70950b6b4105f150d8ef to your computer and use it in GitHub Desktop.
Save dhoss/70950b6b4105f150d8ef to your computer and use it in GitHub Desktop.
json issues
// we want to be asynchronous here because we are doing several API calls
def crawlProjectRepos(project: String) = {
implicit val commitReads: Reads[Commit] = (
(JsPath \ "id").read[Long] and
(JsPath \ "gitId").read[String] and
(JsPath \ "message").read[String] and
(JsPath \ "author" \ "name").read[String] and
(JsPath \ "author" \ "emailAddress").read[String] and
(JsPath \ "authorTimestamp").read[Option[DateTime]](Reads.optionWithNull(jodaDateReads("yyyy-MM-dd'T'HH:mm:ss'Z")))
)(Commit.apply _)
Logger.info("crawling " + project + " by API")
val repos = reposFor(project)
val commits = for (repo <- repos)
yield for (c <- callApi(buildCommitUrl(project, repo)))
yield RepositoryCommitList(repo, (c \ "values").as[List[Commit]])
// create a Future.sequence to make sure the requests are run in parallel
// and then run them, returning a Future
Future.sequence(commits)
}
[info] Compiling 2 Scala sources to /home/devin/projects/blaster/target/scala-2.11/classes...
[error] /home/devin/projects/blaster/app/clients/Stash.scala:64: overloaded method value apply with alternatives:
[error] [B](f: B => (Long, String, String, String, String, Option[org.joda.time.DateTime]))(implicit fu: play.api.libs.functional.ContravariantFunctor[play.api.libs.json.Reads])play.api.libs.json.Reads[B] <and>
[error] [B](f: (Long, String, String, String, String, Option[org.joda.time.DateTime]) => B)(implicit fu: play.api.libs.functional.Functor[play.api.libs.json.Reads])play.api.libs.json.Reads[B]
[error] cannot be applied to ((Long, String, String, String, String, Option[org.joda.time.DateTime], Option[Long], Option[org.joda.time.DateTime], Option[org.joda.time.DateTime]) => models.Commit)
[error] (JsPath \ "author" \ "emailAddress").read[String] and
[error] ^
package models
import org.joda.time.DateTime
case class Project(id: Long, name: String, createdAt: Option[DateTime], updatedAt: Option[DateTime])
case class Repository(id: Long, name: String, project: Long, createdAt: Option[DateTime], updatedAt: Option[DateTime])
case class Commit(id: Long, gitId: String, message: String, author: String, email: String, authorTimestamp: Option[DateTime], repository: Option[Long], createdAt: Option[DateTime], updatedAt: Option[DateTime])
case class RepositoryCommitList(repository: String, commits: List[Commit])
{
"values": [
{
"id": "8bb06a99ce1725e57a1640492fe87aad1da7a3a5",
"displayId": "8bb06a99ce1",
"author": {
"name": "daustin",
"emailAddress": "daustin@***",
"id": 1242,
"displayName": "Devin Austin",
"active": true,
"slug": "daustin",
"type": "NORMAL",
"link": {
"url": "\/users\/daustin",
"rel": "self"
},
"links": {
"self": [
{
"href": "http:\/\/****\/users\/daustin"
}
]
}
},
"authorTimestamp": 1437512040000,
"message": "tiny text change",
"parents": [
{
"id": "ee9aa2d2011d91c9c6fef02333e1a8718cf23f8d",
"displayId": "ee9aa2d2011"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment