{-# LANGUAGE OverloadedStrings #-}
module Fedora.Bodhi
( bodhiBuild
, bodhiBuilds
, bodhiComment
, bodhiComments
, bodhiCSRF
, bodhiOverride
, bodhiOverrides
, bodhiOverrideDates
, bodhiPackages
, bodhiRelease
, bodhiReleases
, bodhiUpdate
, bodhiUpdates
, bodhiUser
, bodhiUsers
, lookupKey
, lookupKey'
, queryBodhi
, makeKey
, makeItem
, maybeKey
, Query
, QueryItem
) where
import Data.Aeson.Types
import Data.Text (Text)
import Data.Time.LocalTime
import Network.HTTP.Query
server :: String
server :: String
server = "bodhi.fedoraproject.org"
bodhiBuild :: String -> IO Object
bodhiBuild :: String -> IO Object
bodhiBuild nvr :: String
nvr =
Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi [] (String -> IO Object) -> String -> IO Object
forall a b. (a -> b) -> a -> b
$ "builds" String -> String -> String
+/+ String
nvr
bodhiBuilds :: Query -> IO [Object]
bodhiBuilds :: Query -> IO [Object]
bodhiBuilds params :: Query
params =
Text -> Object -> [Object]
forall a. FromJSON a => Text -> Object -> a
lookupKey' "builds" (Object -> [Object]) -> IO Object -> IO [Object]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi Query
params "builds/"
bodhiComment :: String -> IO Object
cid :: String
cid =
Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi [] (String -> IO Object) -> String -> IO Object
forall a b. (a -> b) -> a -> b
$ "comments" String -> String -> String
+/+ String
cid
bodhiComments :: Query -> IO [Object]
params :: Query
params =
Text -> Object -> [Object]
forall a. FromJSON a => Text -> Object -> a
lookupKey' "comments" (Object -> [Object]) -> IO Object -> IO [Object]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi Query
params "comments/"
bodhiCSRF :: IO (Maybe Text)
bodhiCSRF :: IO (Maybe Text)
bodhiCSRF =
Text -> Object -> Maybe Text
forall a. FromJSON a => Text -> Object -> Maybe a
lookupKey "csrf_token" (Object -> Maybe Text) -> IO Object -> IO (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi [] "csrf"
bodhiOverride :: String -> IO (Maybe Object)
bodhiOverride :: String -> IO (Maybe Object)
bodhiOverride nvr :: String
nvr =
Text -> Object -> Maybe Object
forall a. FromJSON a => Text -> Object -> Maybe a
lookupKey "override" (Object -> Maybe Object) -> IO Object -> IO (Maybe Object)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi [] ("overrides" String -> String -> String
+/+ String
nvr)
bodhiOverrideDates :: String -> IO (Maybe (LocalTime,LocalTime))
bodhiOverrideDates :: String -> IO (Maybe (LocalTime, LocalTime))
bodhiOverrideDates nvr :: String
nvr = do
Maybe Object
mobj <- String -> IO (Maybe Object)
bodhiOverride String
nvr
case Maybe Object
mobj of
Nothing -> do
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ "Override for " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
nvr String -> String -> String
forall a. [a] -> [a] -> [a]
++ " not found"
Maybe (LocalTime, LocalTime) -> IO (Maybe (LocalTime, LocalTime))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (LocalTime, LocalTime)
forall a. Maybe a
Nothing
Just obj :: Object
obj -> Maybe (LocalTime, LocalTime) -> IO (Maybe (LocalTime, LocalTime))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (LocalTime, LocalTime) -> IO (Maybe (LocalTime, LocalTime)))
-> Maybe (LocalTime, LocalTime)
-> IO (Maybe (LocalTime, LocalTime))
forall a b. (a -> b) -> a -> b
$ Object -> Maybe (LocalTime, LocalTime)
readDates Object
obj
where
readDates :: Object -> Maybe (LocalTime,LocalTime)
readDates :: Object -> Maybe (LocalTime, LocalTime)
readDates =
(Object -> Parser (LocalTime, LocalTime))
-> Object -> Maybe (LocalTime, LocalTime)
forall a b. (a -> Parser b) -> a -> Maybe b
parseMaybe ((Object -> Parser (LocalTime, LocalTime))
-> Object -> Maybe (LocalTime, LocalTime))
-> (Object -> Parser (LocalTime, LocalTime))
-> Object
-> Maybe (LocalTime, LocalTime)
forall a b. (a -> b) -> a -> b
$ \obj :: Object
obj -> do
LocalTime
expire <- Object
obj Object -> Text -> Parser LocalTime
forall a. FromJSON a => Object -> Text -> Parser a
.: "expiration_date"
LocalTime
submit <- Object
obj Object -> Text -> Parser LocalTime
forall a. FromJSON a => Object -> Text -> Parser a
.: "submission_date"
(LocalTime, LocalTime) -> Parser (LocalTime, LocalTime)
forall (m :: * -> *) a. Monad m => a -> m a
return (LocalTime
expire,LocalTime
submit)
bodhiOverrides :: Query -> IO [Object]
bodhiOverrides :: Query -> IO [Object]
bodhiOverrides params :: Query
params =
Text -> Object -> [Object]
forall a. FromJSON a => Text -> Object -> a
lookupKey' "overrides" (Object -> [Object]) -> IO Object -> IO [Object]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi Query
params "overrides/"
bodhiPackages :: Query -> IO [Object]
bodhiPackages :: Query -> IO [Object]
bodhiPackages params :: Query
params =
Text -> Object -> [Object]
forall a. FromJSON a => Text -> Object -> a
lookupKey' "packages" (Object -> [Object]) -> IO Object -> IO [Object]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi Query
params "packages/"
bodhiRelease :: String -> IO Object
bodhiRelease :: String -> IO Object
bodhiRelease rel :: String
rel =
Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi [] (String -> IO Object) -> String -> IO Object
forall a b. (a -> b) -> a -> b
$ "releases" String -> String -> String
+/+ String
rel
bodhiReleases :: Query -> IO [Object]
bodhiReleases :: Query -> IO [Object]
bodhiReleases params :: Query
params =
Text -> Object -> [Object]
forall a. FromJSON a => Text -> Object -> a
lookupKey' "releases" (Object -> [Object]) -> IO Object -> IO [Object]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi Query
params "releases/"
bodhiUpdate :: String -> IO (Maybe Object)
bodhiUpdate :: String -> IO (Maybe Object)
bodhiUpdate update :: String
update =
Text -> Object -> Maybe Object
forall a. FromJSON a => Text -> Object -> Maybe a
lookupKey "update" (Object -> Maybe Object) -> IO Object -> IO (Maybe Object)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi [] ("updates" String -> String -> String
+/+ String
update)
bodhiUpdates :: Query -> IO [Object]
bodhiUpdates :: Query -> IO [Object]
bodhiUpdates params :: Query
params =
Text -> Object -> [Object]
forall a. FromJSON a => Text -> Object -> a
lookupKey' "updates" (Object -> [Object]) -> IO Object -> IO [Object]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi Query
params "updates/"
bodhiUser :: String -> IO Object
bodhiUser :: String -> IO Object
bodhiUser user :: String
user =
Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi [] (String -> IO Object) -> String -> IO Object
forall a b. (a -> b) -> a -> b
$ "users" String -> String -> String
+/+ String
user
bodhiUsers :: Query -> IO [Object]
bodhiUsers :: Query -> IO [Object]
bodhiUsers params :: Query
params =
Text -> Object -> [Object]
forall a. FromJSON a => Text -> Object -> a
lookupKey' "users" (Object -> [Object]) -> IO Object -> IO [Object]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query -> String -> IO Object
forall a. FromJSON a => Query -> String -> IO a
queryBodhi Query
params "users/"
queryBodhi :: FromJSON a => Query -> String -> IO a
queryBodhi :: Query -> String -> IO a
queryBodhi params :: Query
params path :: String
path =
let url :: String
url = "https://" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
server String -> String -> String
+/+ String
path
in String -> Query -> IO a
forall (m :: * -> *) a.
(MonadIO m, FromJSON a) =>
String -> Query -> m a
webAPIQuery String
url Query
params