11package com .fortysevendeg .github4s .free .interpreters
22
3- import cats .{ApplicativeError , ~> , Eval }
3+ import cats .{MonadError , ApplicativeError , ~> , Eval }
44import com .fortysevendeg .github4s .{HttpClient , GithubConfig }
55import com .fortysevendeg .github4s .api .{Auth , Repos }
6- import com .fortysevendeg .github4s .app .{C01 , C02 , GitHub4s }
6+ import com .fortysevendeg .github4s .app .{COGH01 , COGH02 , GitHub4s }
77import com .fortysevendeg .github4s .free .algebra ._
88import io .circe .Decoder
99
1010trait Interpreters [M [_]] {
1111
1212 implicit def interpreters (
1313 implicit
14- A : ApplicativeError [M , Throwable ],
15- C : GithubConfig
14+ A : MonadError [M , Throwable ]
1615 ): GitHub4s ~> M = {
17- val repositoryAndUserInterpreter : C01 ~> M = repositoryOpsInterpreter or userOpsInterpreter
18- val c01nterpreter : C02 ~> M = requestOpsInterpreter or repositoryAndUserInterpreter
16+ val repositoryAndUserInterpreter : COGH01 ~> M = repositoryOpsInterpreter or userOpsInterpreter
17+ val c01nterpreter : COGH02 ~> M = requestOpsInterpreter or repositoryAndUserInterpreter
1918 val all : GitHub4s ~> M = authOpsInterpreter or c01nterpreter
2019 all
2120 }
@@ -25,29 +24,29 @@ trait Interpreters[M[_]] {
2524
2625 /** Lifts Repository Ops to an effect capturing Monad such as Task via natural transformations
2726 */
28- def repositoryOpsInterpreter (implicit A : ApplicativeError [M , Throwable ], C : GithubConfig ): RepositoryOp ~> M = new (RepositoryOp ~> M ) {
27+ def repositoryOpsInterpreter (implicit A : ApplicativeError [M , Throwable ]): RepositoryOp ~> M = new (RepositoryOp ~> M ) {
2928 def apply [A ](fa : RepositoryOp [A ]): M [A ] = fa match {
30- case GetRepo (owner, repo) ⇒ A .pureEval(Eval .later(Repos .get(owner, repo)))
31- case ListCommits (owner, repo, sha, path, author, since, until, pagination) ⇒ A .pureEval(Eval .later(Repos .listCommits(owner, repo, sha, path, author, since, until, pagination)))
29+ case GetRepo (owner, repo, accessToken ) ⇒ A .pureEval(Eval .later(Repos .get(accessToken, owner, repo)))
30+ case ListCommits (owner, repo, sha, path, author, since, until, pagination, accessToken ) ⇒ A .pureEval(Eval .later(Repos .listCommits(accessToken, owner, repo, sha, path, author, since, until, pagination)))
3231 }
3332 }
3433
3534 /** Lifts User Ops to an effect capturing Monad such as Task via natural transformations
3635 */
37- def userOpsInterpreter (implicit A : ApplicativeError [M , Throwable ], C : GithubConfig ): UserOp ~> M = new (UserOp ~> M ) {
36+ def userOpsInterpreter (implicit A : ApplicativeError [M , Throwable ]): UserOp ~> M = new (UserOp ~> M ) {
3837
3938 import com .fortysevendeg .github4s .api .Users
4039
4140 def apply [A ](fa : UserOp [A ]): M [A ] = fa match {
42- case GetUser (username) ⇒ A .pureEval(Eval .later(Users .get(username)))
43- case GetAuthUser () ⇒ A .pureEval(Eval .later(Users .getAuth))
44- case GetUsers (since, pagination) ⇒ A .pureEval(Eval .later(Users .getUsers(since, pagination)))
41+ case GetUser (username, accessToken ) ⇒ A .pureEval(Eval .later(Users .get(accessToken, username)))
42+ case GetAuthUser (accessToken ) ⇒ A .pureEval(Eval .later(Users .getAuth(accessToken) ))
43+ case GetUsers (since, pagination, accessToken ) ⇒ A .pureEval(Eval .later(Users .getUsers(accessToken, since, pagination)))
4544 }
4645 }
4746
4847 /** Lifts Auth Ops to an effect capturing Monad such as Task via natural transformations
4948 */
50- def authOpsInterpreter (implicit A : ApplicativeError [M , Throwable ], C : GithubConfig ): AuthOp ~> M = new (AuthOp ~> M ) {
49+ def authOpsInterpreter (implicit A : ApplicativeError [M , Throwable ]): AuthOp ~> M = new (AuthOp ~> M ) {
5150 def apply [A ](fa : AuthOp [A ]): M [A ] = fa match {
5251 case NewAuth (username, password, scopes, note, client_id, client_secret) ⇒ A .pureEval(Eval .later(Auth .newAuth(username, password, scopes, note, client_id, client_secret)))
5352 case AuthorizeUrl (client_id, redirect_uri, scopes) => A .pureEval(Eval .later(Auth .authorizeUrl(client_id, redirect_uri, scopes)))
@@ -57,11 +56,11 @@ trait Interpreters[M[_]] {
5756
5857 /** Lifts Request Ops to an effect capturing Monad such as Task via natural transformations
5958 */
60- def requestOpsInterpreter (implicit App : ApplicativeError [M , Throwable ], C : GithubConfig ): RequestOp ~> M = new (RequestOp ~> M ) {
59+ def requestOpsInterpreter (implicit App : ApplicativeError [M , Throwable ]): RequestOp ~> M = new (RequestOp ~> M ) {
6160 def apply [A ](fa : RequestOp [A ]): M [A ] = fa match {
62- case Next (url : String , decoder : Decoder [A ]) ⇒ {
61+ case Next (url : String , decoder : Decoder [A ], accessToken ) ⇒ {
6362 // implicit val d: Decoder[A] = decoder
64- App .pureEval(Eval .later(httpClient.getByUrl(url, decoder)))
63+ App .pureEval(Eval .later(httpClient.getByUrl(accessToken, url, decoder)))
6564 }
6665 }
6766 }
0 commit comments