aur 6.3.1 → 7.0.0
raw patch · 4 files changed
+60/−68 lines, 4 filesdep +bytestringdep +http-typesdep −servantdep −servant-clientPVP ok
version bump matches the API change (PVP)
Dependencies added: bytestring, http-types
Dependencies removed: servant, servant-client
API changes (from Hackage documentation)
- Linux.Arch.Aur: ConnectionError :: SomeException -> ClientError
- Linux.Arch.Aur: DecodeFailure :: Text -> Response -> ClientError
- Linux.Arch.Aur: FailureResponse :: RequestF () (BaseUrl, ByteString) -> Response -> ClientError
- Linux.Arch.Aur: InvalidContentTypeHeader :: Response -> ClientError
- Linux.Arch.Aur: UnsupportedContentType :: MediaType -> Response -> ClientError
- Linux.Arch.Aur: data ClientError
+ Linux.Arch.Aur: BadJSON :: AurError
+ Linux.Arch.Aur: NotFound :: ByteString -> AurError
+ Linux.Arch.Aur: OtherAurError :: ByteString -> AurError
+ Linux.Arch.Aur: data AurError
+ Linux.Arch.Aur: instance GHC.Classes.Eq Linux.Arch.Aur.AurError
+ Linux.Arch.Aur: instance GHC.Classes.Ord Linux.Arch.Aur.AurError
+ Linux.Arch.Aur: instance GHC.Show.Show Linux.Arch.Aur.AurError
- Linux.Arch.Aur: info :: Manager -> [Text] -> IO (Either ClientError [AurInfo])
+ Linux.Arch.Aur: info :: Manager -> [Text] -> IO (Either AurError [AurInfo])
- Linux.Arch.Aur: search :: Manager -> Text -> IO (Either ClientError [AurInfo])
+ Linux.Arch.Aur: search :: Manager -> Text -> IO (Either AurError [AurInfo])
Files
- CHANGELOG.md +16/−0
- aur.cabal +6/−6
- lib/Linux/Arch/Aur.hs +37/−61
- tests/Test.hs +1/−1
CHANGELOG.md view
@@ -1,5 +1,21 @@ # Changelog +## Unreleased++#### Added++- The `AurError` type to account for the API change described below.++#### Changed++- The `servant` dependency has been dropped in favour of vanilla `http-client`.+- `info` and `search` now return the custom `AurError` type instead of servant's+ `ClientError`.++#### Removed++- The reexport of `ClientError` from servant.+ ## 6.3.1 - Rewiden `servant` bounds.
aur.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: aur-version: 6.3.1+version: 7.0.0 synopsis: Access metadata from the Arch Linux User Repository. description: Access package information from Arch Linux's AUR via its RPC interface. The@@ -10,7 +10,7 @@ of the AUR. category: Linux-homepage: https://github.com/aurapm/aura+homepage: https://github.com/fosskers/aura author: Colin Woodbury maintainer: colin@fosskers.ca copyright: 2014 - 2020 Colin Woodbury@@ -36,10 +36,10 @@ hs-source-dirs: lib exposed-modules: Linux.Arch.Aur build-depends:- , aeson >=0.9 && <1.5- , servant >=0.16 && <0.18- , servant-client >=0.16 && <0.18- , text ^>=1.2+ , aeson >=0.9 && <1.5+ , bytestring+ , http-types ^>=0.12+ , text ^>=1.2 test-suite aur-test import: commons
lib/Linux/Arch/Aur.hs view
@@ -1,7 +1,7 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DerivingStrategies #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeOperators #-} -- | -- Module : Linux.Arch.Aur@@ -14,22 +14,18 @@ module Linux.Arch.Aur ( -- * Types AurInfo(..)+ , AurError(..) -- * Queries , info, search- -- * Re-exports- -- | These are __Servant__ types which you could want to manipulate without- -- directly depending on (and importing) servant.- , ClientError(..) ) where -import Control.Applicative ((<|>))-import Control.Monad (mzero)-import Data.Aeson-import Data.Proxy-import Data.Text (Text)-import Network.HTTP.Client (Manager)-import Servant.API-import Servant.Client+import Control.Applicative ((<|>))+import Data.Aeson+import Data.ByteString (ByteString)+import Data.Text (Text)+import qualified Data.Text as T+import Network.HTTP.Client+import Network.HTTP.Types.Status --- @@ -37,17 +33,16 @@ { _version :: Int , _type :: Text , _resultCount :: Int- , _results :: [AurInfo] } deriving (Show)+ , _results :: [AurInfo] }+ deriving (Show) instance FromJSON RPCResp where- parseJSON (Object v) = RPCResp+ parseJSON = withObject "RPCResp" $ \v -> RPCResp <$> v .: "version" <*> v .: "type" <*> v .: "resultcount" <*> v .: "results" - parseJSON _ = mzero- -- | All relevant information about an AUR package. data AurInfo = AurInfo { aurIdOf :: Int@@ -73,7 +68,7 @@ , keywordsOf :: [Text] } deriving (Eq,Show) instance FromJSON AurInfo where- parseJSON (Object v) = AurInfo+ parseJSON = withObject "AurInfo" $ \v -> AurInfo <$> v .: "ID" <*> v .: "Name" <*> v .: "PackageBaseID"@@ -96,8 +91,6 @@ <*> v .:? "License" .!= [] <*> v .:? "Keywords" .!= [] - parseJSON _ = mzero- instance ToJSON AurInfo where toJSON ai = object [ "ID" .= aurIdOf ai@@ -122,46 +115,29 @@ , "License" .= licenseOf ai , "Keywords" .= keywordsOf ai ] ------type Info = "rpc" :> QueryParam "v" Text- :> QueryParam "type" Text- :> QueryParams "arg[]" Text- :> Get '[JSON] RPCResp--type Search = "rpc" :> QueryParam "v" Text- :> QueryParam "type" Text- :> QueryParam "arg" Text- :> Get '[JSON] RPCResp--type API = Info :<|> Search--api :: Proxy API-api = Proxy--url :: BaseUrl-url = BaseUrl Https "aur.archlinux.org" 443 ""---- | Make a call to the AUR RPC. Assumes version 5 of the API.-rpcI :: Maybe Text -> Maybe Text -> [Text] -> ClientM RPCResp-rpcS :: Maybe Text -> Maybe Text -> Maybe Text -> ClientM RPCResp-rpcI :<|> rpcS = client api+data AurError = NotFound ByteString | BadJSON | OtherAurError ByteString+ deriving stock (Eq, Ord, Show) -- | Perform an @info@ call on one or more package names.--- Will fail with a `Nothing` if there was a connection/decoding error.-info :: Manager -> [Text] -> IO (Either ClientError [AurInfo])-info m ps = unwrap m $ rpcI (Just "5") (Just "info") ps+-- Will fail with a `Left` if there was a connection/decoding error.+info :: Manager -> [Text] -> IO (Either AurError [AurInfo])+info m ps = work m url+ where+ url = "https://aur.archlinux.org/rpc?v=5&type=info&" <> as+ as = T.unpack . T.intercalate "&" $ map ("arg%5B%5D=" <>) ps -- | Perform a @search@ call on a package name or description text.--- Will fail with a `Nothing` if there was a connection/decoding error.-search :: Manager -> Text -> IO (Either ClientError [AurInfo])-search m p = unwrap m $ rpcS (Just "5") (Just "search") (Just p)--unwrap :: Manager -> ClientM RPCResp -> IO (Either ClientError [AurInfo])-unwrap m r = fmap _results <$> runClientM r env+-- Will fail with a `Left` if there was a connection/decoding error.+search :: Manager -> Text -> IO (Either AurError [AurInfo])+search m p = work m url where-#if !MIN_VERSION_servant_client(0,17,0)- env = ClientEnv m url Nothing-#else- env = ClientEnv m url Nothing defaultMakeClientRequest-#endif+ url = "https://aur.archlinux.org/rpc?v=5&type=search&arg=" <> T.unpack p++work :: Manager -> String -> IO (Either AurError [AurInfo])+work m url = do+ req <- parseRequest url+ res <- httpLbs req m+ case responseStatus res of+ Status 200 _ -> pure . maybe (Left BadJSON) (Right . _results) . decode' $ responseBody res+ Status 404 e -> pure . Left $ NotFound e+ Status _ e -> pure . Left $ OtherAurError e
tests/Test.hs view
@@ -18,7 +18,7 @@ ] infoTest :: Manager -> Assertion-infoTest m = info m ["aura"] >>= \x -> (not . null <$> x) @?= Right True+infoTest m = info m ["aura", "aura-bin"] >>= \x -> (length <$> x) @?= Right 2 infoTest' :: Manager -> Assertion infoTest' m = info m ["aura1234567"] >>= \x -> (null <$> x) @?= Right True