1- {-# LANGUAGE RecordWildCards #-}
2-
31-----------------------------------------------------------------------------
42-- |
53-- License : BSD-3-Clause
@@ -10,31 +8,36 @@ module GitHub.Data.RateLimit where
108import GitHub.Internal.Prelude
119import Prelude ()
1210
11+ data Limits = Limits
12+ { limitsMax :: ! Int
13+ , limitsRemaining :: ! Int
14+ , limitsReset :: ! Int -- TODO: change to proper type
15+ }
16+ deriving (Show , Data , Typeable , Eq , Ord , Generic )
17+
18+ instance NFData Limits where rnf = genericRnf
19+ instance Binary Limits
20+
21+ instance FromJSON Limits where
22+ parseJSON = withObject " Limits" $ \ obj -> Limits
23+ <$> obj .: " limit"
24+ <*> obj .: " remaining"
25+ <*> obj .: " reset"
1326
1427data RateLimit = RateLimit
15- { coreLimit :: ! Int
16- , coreRemaining :: ! Int
17- , coreReset :: ! Int
18- , searchLimit :: ! Int
19- , searchRemaining :: ! Int
20- , searchReset :: ! Int
28+ { rateLimitCore :: Limits
29+ , rateLimitSearch :: Limits
30+ , rateLimitGraphQL :: Limits
2131 }
2232 deriving (Show , Data , Typeable , Eq , Ord , Generic )
2333
2434instance NFData RateLimit where rnf = genericRnf
2535instance Binary RateLimit
2636
2737instance FromJSON RateLimit where
28- parseJSON = withObject " RateLimit" $ \ o -> do
29- resources <- o .: " resources"
30- core <- resources .: " core"
31- coreLimit <- core .: " limit"
32- coreRemaining <- core .: " remaining"
33- coreReset <- core .: " reset"
34-
35- search <- resources .: " search"
36- searchLimit <- search .: " limit"
37- searchRemaining <- search .: " remaining"
38- searchReset <- search .: " reset"
39-
40- return RateLimit {.. }
38+ parseJSON = withObject " RateLimit" $ \ obj -> do
39+ resources <- obj .: " resources"
40+ RateLimit
41+ <$> resources .: " core"
42+ <*> resources .: " search"
43+ <*> resources .: " graphql"
0 commit comments