11package nelson
22
3- import argonaut .Argonaut .{ casecodec1 , casecodec4 }
3+ import argonaut .Argonaut .{casecodec1 , casecodec2 , casecodec4 }
44import argonaut .{CodecJson , DecodeJson , EncodeJson }
55import nelson .Github ._
66import org .http4s
77import org .http4s ._
88import org .http4s .argonaut ._
99import org .http4s .client .Client
1010import org .http4s .headers .Authorization
11+ import scalaz ._ , Scalaz ._
1112import scalaz .concurrent .Task
12- import scalaz .~>
13- import java .net .{ MalformedURLException , URI }
13+ import java .net .{MalformedURLException , URI }
1414
1515object Gitlab {
1616
@@ -31,11 +31,25 @@ object Gitlab {
3131 case GetUser (token : AccessToken ) =>
3232 fetch[Github .User ](cfg.userEndpoint) { uri =>
3333 http4s.Request (
34- headers = Headers (Authorization (OAuth2BearerToken (token.value))),
34+ headers = Headers (Header (" PRIVATE-TOKEN" , token.value)),
35+ // headers = Headers(Authorization(OAuth2BearerToken(token.value))),
3536 uri = uri)
3637 }
37- case GetUserOrgKeys (token : AccessToken ) => ???
38- case GetOrganizations (keys : List [Github .OrgKey ], t : AccessToken ) => ???
38+ case GetUserOrgKeys (token : AccessToken ) =>
39+ fetch[List [Github .OrgKey ]](cfg.userOrgsEndpoint) { uri =>
40+ http4s.Request (
41+ headers = Headers (Header (" PRIVATE-TOKEN" , token.value)),
42+ uri = uri)
43+ }
44+ case GetOrganizations (keys : List [Github .OrgKey ], t : AccessToken ) =>
45+ Nondeterminism [Task ].gatherUnordered(
46+ keys.map(key => fetch[Organization ](cfg.orgEndpoint(key.slug)) { uri =>
47+ http4s.Request (
48+ headers = Headers (Header (" PRIVATE-TOKEN" , t.value)),
49+ uri = uri)
50+ })
51+ )
52+ // fetch[List[Organization]](cfg.orgEndpoint())
3953 case GetReleaseAssetContent (asset : Github .Asset , t : AccessToken ) => ???
4054 case GetRelease (slug : Slug , releaseId : ID , t : AccessToken ) => ???
4155 case GetUserRepositories (t : AccessToken ) => ???
@@ -55,6 +69,21 @@ object Gitlab {
5569 casecodec4(Github .User .apply, Github .User .unapply
5670 )(" username" , " avatar_url" , " name" , " email" )
5771
72+ implicit lazy val GithubOrg : CodecJson [Github .OrgKey ] =
73+ casecodec2(Github .OrgKey .apply, Github .OrgKey .unapply)(" id" , " full_path" )
74+
75+ // implicit lazy val OrganizationCodec: CodecJson[Organization] =
76+ // casecodec4(Organization.apply, Organization.unapply)("id", "name", "full_path", "avatar_url")
77+
78+ implicit lazy val OrganizationDecoder : DecodeJson [Organization ] =
79+ DecodeJson (c =>
80+ ((c --\ " id" ).as[Long ] |@|
81+ (c --\ " name" ).as[Option [String ]] |@|
82+ (c --\ " full_path" ).as[String ]
83+ // (c --\ "avatar_url").as[URI]
84+ ) { case (id, name, login) => Organization (id, name, login, new URI (" https://localhost:8080" )) } // TODO
85+ )
86+
5887 implicit lazy val AccessTokenCodec : CodecJson [AccessToken ] =
5988 casecodec1(AccessToken .apply, AccessToken .unapply)(" access_token" )
6089
0 commit comments