-
Notifications
You must be signed in to change notification settings - Fork 40
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
Juan José Vázquez
committed
Oct 13, 2017
1 parent
9164534
commit 53b53d8
Showing
1 changed file
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package nelson | ||
|
||
import argonaut.Argonaut.casecodec4 | ||
import argonaut.{CodecJson, DecodeJson, EncodeJson} | ||
import nelson.Github._ | ||
import org.http4s | ||
import org.http4s.argonaut._ | ||
import org.http4s.{EntityDecoder, Header, Headers, Uri} | ||
import org.http4s.client.Client | ||
import scalaz.concurrent.Task | ||
import scalaz.~> | ||
import java.net.URI | ||
|
||
object Gitlab { | ||
|
||
final class GitlabHttp(cfg: GitlabConfig, http4sClient: Client) extends (GithubOp ~> Task) { | ||
def apply[A](in: GithubOp[A]): Task[A] = in match { | ||
case GetAccessToken(fromCode: String) => ??? | ||
case GetUser(token: AccessToken) => | ||
Uri.fromString(cfg.userEndpoint).map { uri => | ||
http4s.Request( | ||
headers = Headers(Header(cfg.headers.PrivateToken, token.value)), | ||
uri = uri | ||
) | ||
}.fold(t => Task.fail(new Exception(t.message)), http4sClient.expect[Github.User]) | ||
case GetUserOrgKeys(token: AccessToken) => ??? | ||
case GetOrganizations(keys: List[Github.OrgKey], t: AccessToken) => ??? | ||
case GetReleaseAssetContent(asset: Github.Asset, t: AccessToken) => ??? | ||
case GetRelease(slug: Slug, releaseId: ID, t: AccessToken) => ??? | ||
case GetUserRepositories(t: AccessToken) => ??? | ||
case GetFileFromRepository(slug: Slug, path: String, tagOrBranch: String, t: AccessToken) => ??? | ||
case GetRepoWebHooks(slug: Slug, t: AccessToken) => ??? | ||
case PostRepoWebHook(slug: Slug, hook: Github.WebHook, t: AccessToken) => ??? | ||
case DeleteRepoWebHook(slug: Slug, id: Long, t: AccessToken) => ??? | ||
} | ||
} | ||
|
||
final case class GitlabConfig(domain: String) { | ||
val api = s"https://$domain/api/v4" | ||
val userEndpoint = s"$api/user" | ||
object headers { | ||
final val PrivateToken = "PRIVATE-TOKEN" | ||
} | ||
} | ||
|
||
implicit def genericEntityDecoder[A: DecodeJson]: EntityDecoder[A] = jsonOf[A] | ||
|
||
implicit lazy val GithubUser: CodecJson[Github.User] = | ||
casecodec4(Github.User.apply, Github.User.unapply | ||
)("username", "avatar_url", "name", "email") | ||
|
||
implicit lazy val UriToJson: EncodeJson[URI] = | ||
implicitly[EncodeJson[String]].contramap(_.toString) | ||
|
||
implicit lazy val JsonToUri: DecodeJson[URI] = | ||
implicitly[DecodeJson[String]].map(new URI(_)) | ||
} |