diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/Main.hs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..75a4396 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,46 @@ +module Main + ( main + ) where + +import Data.Aeson.TH (defaultOptions, deriveJSON) +import Data.HashMap.Strict (HashMap) +import qualified Data.HashMap.Strict as HashMap +import Data.Text (Text) +import qualified Data.Text.IO as Text.IO +import Data.Vector (Vector) +import qualified Data.Vector as Vector +import Network.HTTP.Req + ( runReq + , defaultHttpConfig + , req + , GET(..) + , https + , jsonResponse + , NoReqBody(..) + , (/:) + , responseBody + ) +import Data.Maybe (fromMaybe) + +newtype PackagistPackage = PackagistPackage + { version :: Text + } deriving (Eq, Show) + +$(deriveJSON defaultOptions ''PackagistPackage) + +newtype PackagistResponse = PackagistResponse + { packages :: HashMap Text (Vector PackagistPackage) + } deriving (Eq, Show) + +$(deriveJSON defaultOptions ''PackagistResponse) + +main :: IO () +main = do + packagistResponse <- runReq defaultHttpConfig $ + let uri = https "repo.packagist.org" /: "p2" /: "composer" /: "composer.json" + in req GET uri NoReqBody jsonResponse mempty + let packagistPackages = packages $ responseBody packagistResponse + + Text.IO.putStrLn $ fromMaybe "" + $ HashMap.lookup "composer/composer" packagistPackages + >>= fmap (version . fst) . Vector.uncons |
