File tree Expand file tree Collapse file tree
main/scala/io/chrisdavenport/github
test/scala/io/chrisdavenport/github/endpoints/miscellaneous.scala
example/src/main/scala/io/chrisdavenport/github Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package io .chrisdavenport .github .data
2+
3+ import cats .implicits ._
4+ import io .circe .Decoder
5+ import io .circe .HCursor
6+
7+ object RateLimit {
8+ final case class Limits (
9+ max : Int ,
10+ remaining : Int ,
11+ reset : Int
12+ )
13+ object Limits {
14+ implicit val decoder = new Decoder [Limits ]{
15+ def apply (c : HCursor ): Decoder .Result [Limits ] =
16+ (
17+ c.downField(" limit" ).as[Int ],
18+ c.downField(" remaining" ).as[Int ],
19+ c.downField(" reset" ).as[Int ]
20+ ).mapN(Limits .apply)
21+ }
22+ }
23+
24+ final case class RateLimit (
25+ core : Limits ,
26+ search : Limits ,
27+ graphQL : Limits ,
28+ integrationManifest : Limits
29+ )
30+ object RateLimit {
31+ implicit val decoder = new Decoder [RateLimit ]{
32+ def apply (c : HCursor ): Decoder .Result [RateLimit ] = {
33+ val base = c.downField(" resources" )
34+ (
35+ base.downField(" core" ).as[Limits ],
36+ base.downField(" search" ).as[Limits ],
37+ base.downField(" graphql" ).as[Limits ],
38+ base.downField(" integration_manifest" ).as[Limits ]
39+ ).mapN(RateLimit .apply)
40+ }
41+ }
42+
43+ }
44+ }
Original file line number Diff line number Diff line change 1+ package io .chrisdavenport .github .endpoints .miscellaneous
2+
3+
4+ import cats .effect ._
5+ import org .http4s ._
6+ import org .http4s .implicits ._
7+
8+ import io .chrisdavenport .github .data .{RateLimit => DRateLimit }
9+ import io .chrisdavenport .github .Auth
10+ import io .chrisdavenport .github .internals .GithubMedia ._
11+ import io .chrisdavenport .github .internals .RequestConstructor
12+
13+ object RateLimit {
14+
15+ /**
16+ * Get your current rate limit status
17+ **/
18+ def rateLimit [F [_]: Sync ](
19+ auth : Option [Auth ]
20+ ) = RequestConstructor .runRequestWithNoBody[F , DRateLimit .RateLimit ](
21+ auth,
22+ Method .GET ,
23+ uri " rate_limit "
24+ )
25+
26+ }
Original file line number Diff line number Diff line change 1+ package io .chrisdavenport .github .endpoints .miscellaneous
2+
3+ import org .specs2 .mutable .Specification
4+
5+ import cats .effect ._
6+ import cats .effect .specs2 .CatsEffect
7+
8+
9+ import io .circe .literal ._
10+ import org .http4s ._
11+ import org .http4s .implicits ._
12+ import org .http4s .client ._
13+ import org .http4s .circe ._
14+ import org .http4s .dsl .io ._
15+
16+ class RateLimitSpec extends Specification with CatsEffect {
17+
18+ " RateLimit" should {
19+
20+ " return a valid rate-limit response" in {
21+ RateLimit .rateLimit[IO ](None )
22+ .run(Client .fromHttpApp(rateLimit.orNotFound))
23+ .attempt
24+ .map(_ must beRight)
25+ }
26+
27+ }
28+
29+ val rateLimit : HttpRoutes [IO ] = HttpRoutes .of {
30+ case GET -> Root / " rate_limit" =>
31+ Ok (
32+ json """
33+ {
34+ "resources": {
35+ "core": {
36+ "limit": 5000,
37+ "remaining": 4999,
38+ "reset": 1372700873
39+ },
40+ "search": {
41+ "limit": 30,
42+ "remaining": 18,
43+ "reset": 1372697452
44+ },
45+ "graphql": {
46+ "limit": 5000,
47+ "remaining": 4993,
48+ "reset": 1372700389
49+ },
50+ "integration_manifest": {
51+ "limit": 5000,
52+ "remaining": 4999,
53+ "reset": 1551806725
54+ }
55+ },
56+ "rate": {
57+ "limit": 5000,
58+ "remaining": 4999,
59+ "reset": 1372700873
60+ }
61+ }
62+ """
63+ )
64+ }
65+
66+ }
Original file line number Diff line number Diff line change @@ -16,13 +16,11 @@ object Main extends IOApp {
1616
1717 auth = OAuth (authLine)
1818
19- // out <- Resource.liftF(
20- // Users.getAllUsers[IO](None, None)
21- // .run(c)
22- // .evalTap(s => IO(println(s)))
23- // .compile
24- // .drain
25- // )
19+ _ <- Resource .liftF(
20+ endpoints.miscellaneous.RateLimit .rateLimit[IO ](auth.some)
21+ .run(c)
22+ .flatTap(a => IO (println(a)))
23+ )
2624 // out <- liftPrint(endpoints.Users.userInfoAuthenticatedUser[IO](auth).run(c))
2725 // out <- liftPrint(endpoints.Users.ownerInfoFor[IO]("http4s", auth.some).run(c))
2826 // _ <- liftPrint(endpoints.Repositories.repository[IO]("http4s", "http4s", auth.some).run(c))
You can’t perform that action at this time.
0 commit comments