This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
92 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package hedgehog.clients.github | ||
|
||
import play.api.libs.functional.syntax._ | ||
import play.api.libs.json.{Reads, __} | ||
|
||
import hedgehog.models.{GithubOrg, Account, GithubUser, Repo, ProgrammingLang} | ||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2014 | ||
* See LICENSE.txt for details. | ||
*/ | ||
object GithubReades { | ||
|
||
val accountReads: Reads[Account] = ( | ||
(__ \ "type").read[String] ~ | ||
(__ \ "login").read[String] ~ | ||
(__ \ "avatar_url").readNullable[String] | ||
) apply { | ||
(accountType, login, avatarUrl) => accountType match { | ||
case "User" => GithubUser(login, avatarUrl) | ||
case "Organization" => GithubOrg(login, avatarUrl) | ||
case _ => throw new FormatError(s"Unknown owner type "+ accountType) | ||
} | ||
} | ||
|
||
val repoReads: Reads[Repo] = ( | ||
(__ \ "name").read[String] ~ | ||
(__ \ "owner").read[Account](accountReads) ~ | ||
(__ \ "description").readNullable[String] ~ | ||
(__ \ "private").read[Boolean] ~ | ||
(__ \ "language").readNullable[String] | ||
) apply { | ||
(name, owner, description, isPrivate, lang) => { | ||
Repo( | ||
name, | ||
owner, | ||
description = description, | ||
isPrivate = Some(isPrivate), | ||
primaryLang = lang.map(l => ProgrammingLang(l.toLowerCase)) | ||
) | ||
} | ||
} | ||
|
||
val repoSeqReads: Reads[Seq[Repo]] = Reads.seq[Repo](repoReads) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters