aur 4.0.2 → 5.0.0
raw patch · 5 files changed
+80/−197 lines, 5 filesdep +http-clientdep +http-client-tlsdep +servantdep −aeson-prettydep −filepathdep −lensdep ~aesondep ~mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: http-client, http-client-tls, servant, servant-client, transformers
Dependencies removed: aeson-pretty, filepath, lens, lens-aeson, vector, wreq
Dependency ranges changed: aeson, mtl
API changes (from Hackage documentation)
- Linux.Arch.Aur.Pkgbuild: pkgbuild :: MonadIO m => String -> m (Maybe Text)
- Linux.Arch.Aur.Pkgbuild: pkgbuild' :: MonadIO m => Text -> m (Maybe Text)
- Linux.Arch.Aur.Pkgbuild: pkgbuildUrl :: String -> String
- Linux.Arch.Aur.Rpc: info' :: MonadIO m => Text -> String -> Text -> m (Maybe AurInfo)
- Linux.Arch.Aur.Rpc: infoJ :: MonadIO m => Text -> m (Maybe Value)
- Linux.Arch.Aur.Rpc: infoJ' :: MonadIO m => Text -> String -> Text -> m (Maybe Value)
- Linux.Arch.Aur.Rpc: msearch :: MonadIO m => Text -> m [AurInfo]
- Linux.Arch.Aur.Rpc: msearch' :: MonadIO m => Text -> String -> Text -> m [AurInfo]
- Linux.Arch.Aur.Rpc: msearchJ :: MonadIO m => Text -> m (Maybe Value)
- Linux.Arch.Aur.Rpc: msearchJ' :: MonadIO m => Text -> String -> Text -> m (Maybe Value)
- Linux.Arch.Aur.Rpc: multiinfo :: MonadIO m => [Text] -> m [AurInfo]
- Linux.Arch.Aur.Rpc: multiinfo' :: MonadIO m => [Text] -> String -> Text -> m [AurInfo]
- Linux.Arch.Aur.Rpc: multiinfoJ :: MonadIO m => [Text] -> m (Maybe Value)
- Linux.Arch.Aur.Rpc: multiinfoJ' :: MonadIO m => [Text] -> String -> Text -> m (Maybe Value)
- Linux.Arch.Aur.Rpc: pretty :: Value -> Text
- Linux.Arch.Aur.Rpc: search' :: MonadIO m => Text -> String -> Text -> m [AurInfo]
- Linux.Arch.Aur.Rpc: searchJ :: MonadIO m => Text -> m (Maybe Value)
- Linux.Arch.Aur.Rpc: searchJ' :: MonadIO m => Text -> String -> Text -> m (Maybe Value)
+ Linux.Arch.Aur.Types: RPCResp :: Int -> Text -> Int -> [AurInfo] -> RPCResp
+ Linux.Arch.Aur.Types: [_resultCount] :: RPCResp -> Int
+ Linux.Arch.Aur.Types: [_results] :: RPCResp -> [AurInfo]
+ Linux.Arch.Aur.Types: [_type] :: RPCResp -> Text
+ Linux.Arch.Aur.Types: [_version] :: RPCResp -> Int
+ Linux.Arch.Aur.Types: [keywordsOf] :: AurInfo -> [Text]
+ Linux.Arch.Aur.Types: data RPCResp
+ Linux.Arch.Aur.Types: instance Data.Aeson.Types.Class.FromJSON Linux.Arch.Aur.Types.RPCResp
+ Linux.Arch.Aur.Types: instance GHC.Show.Show Linux.Arch.Aur.Types.RPCResp
- Linux.Arch.Aur.Rpc: info :: MonadIO m => Text -> m (Maybe AurInfo)
+ Linux.Arch.Aur.Rpc: info :: MonadIO m => [Text] -> m [AurInfo]
- Linux.Arch.Aur.Types: AurInfo :: Int -> Text -> Int -> Text -> Text -> Text -> [Text] -> Text -> Int -> Float -> Maybe Int -> Maybe Text -> Int -> Int -> Text -> [Text] -> [Text] -> [Text] -> [Text] -> [Text] -> AurInfo
+ Linux.Arch.Aur.Types: AurInfo :: Int -> Text -> Int -> Text -> Text -> Text -> Text -> Int -> Float -> Maybe Int -> Maybe Text -> Int -> Int -> Text -> [Text] -> [Text] -> [Text] -> [Text] -> [Text] -> [Text] -> [Text] -> AurInfo
Files
- Linux/Arch/Aur.hs +1/−3
- Linux/Arch/Aur/Pkgbuild.hs +0/−46
- Linux/Arch/Aur/Rpc.hs +41/−120
- Linux/Arch/Aur/Types.hs +24/−6
- aur.cabal +14/−22
Linux/Arch/Aur.hs view
@@ -1,8 +1,6 @@ module Linux.Arch.Aur- ( module Linux.Arch.Aur.Pkgbuild- , module Linux.Arch.Aur.Rpc+ ( module Linux.Arch.Aur.Rpc , module Linux.Arch.Aur.Types ) where -import Linux.Arch.Aur.Pkgbuild import Linux.Arch.Aur.Rpc import Linux.Arch.Aur.Types
− Linux/Arch/Aur/Pkgbuild.hs
@@ -1,46 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE ViewPatterns #-}---- |--- Module : Linux.Arch.Aur.Pkgbuild--- Copyright : (c) Colin Woodbury, 2014,2015--- License : GPL3--- Maintainer: Colin Woodbury <colingw@gmail.com>--module Linux.Arch.Aur.Pkgbuild- ( pkgbuild- , pkgbuild'- , pkgbuildUrl ) where--import Control.Exception (SomeException, catch)-import Control.Lens ((^?))-import Control.Monad ((>=>))-import Control.Monad.Trans (MonadIO, liftIO)-import Data.Text hiding (take)-import qualified Data.Text.Lazy as TL-import Data.Text.Lazy.Encoding-import Network.Wreq-import System.FilePath ((</>))-------type E = SomeException--baseUrl :: String-baseUrl = "https://aur4.archlinux.org/"---- | The location of a given package's PKGBUILD on the AUR servers.-pkgbuildUrl :: String -> String-pkgbuildUrl p = baseUrl </> "cgit/aur.git/plain/PKGBUILD?h=" ++ p---- | The PKGBUILD of a given package, retrieved from the AUR servers.-pkgbuild :: MonadIO m => String -> m (Maybe Text)-pkgbuild p = e $ (rb >=> txt) <$> get (pkgbuildUrl p)- where rb = (^? responseBody)- txt = Just . TL.toStrict . decodeUtf8- e f = liftIO $ f `catch` (\(_ :: E) -> return Nothing)---- | Callable with Text as well, if that's easier.-pkgbuild' :: MonadIO m => Text -> m (Maybe Text)-pkgbuild' (unpack -> p) = pkgbuild p
Linux/Arch/Aur/Rpc.hs view
@@ -1,139 +1,60 @@-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE DataKinds #-} -- | -- Module : Linux.Arch.Aur.Rpc--- Copyright : (c) Colin Woodbury, 2014, 2015+-- Copyright : (c) Colin Woodbury, 2014, 2015, 2016 -- License : GPL3 -- Maintainer: Colin Woodbury <colingw@gmail.com>+--+-- See https://aur.archlinux.org/rpc for details. module Linux.Arch.Aur.Rpc- ( -- * AUR4 Queries- info- , multiinfo- , search- , msearch- -- * AUR4 Queries as JSON- , infoJ- , multiinfoJ- , searchJ- , msearchJ- -- * Explicit API version/endpoint- , info'- , multiinfo'- , search'- , msearch'- -- * Explicit API version/endpoint as JSON- , infoJ'- , multiinfoJ'- , searchJ'- , msearchJ'- -- * Pretty JSON- , pretty ) where--import Linux.Arch.Aur.Types+ ( info, search ) where -import Control.Lens-import Control.Monad.Trans (MonadIO, liftIO)-import Data.Aeson (Value(..), FromJSON, Result(..), fromJSON)-import Data.Aeson.Encode.Pretty-import Data.Aeson.Lens (AsValue, key, nth)-import Data.Maybe (catMaybes)-import Data.Text-import qualified Data.Text.Lazy as TL-import Data.Text.Lazy.Encoding-import qualified Data.Vector as V-import Network.Wreq+import Control.Monad.Trans (MonadIO, liftIO)+import Control.Monad.Trans.Except+import Data.Proxy+import Data.Text (Text, unpack)+import Linux.Arch.Aur.Types+import Network.HTTP.Client (Manager, newManager)+import Network.HTTP.Client.TLS+import Servant.API+import Servant.Client+import System.IO.Unsafe --- -aurUrl :: String-aurUrl = "https://aur.archlinux.org/rpc.php?"---- | Returns all information about one package.-info :: MonadIO m => Text -> m (Maybe AurInfo)-info p = (>>= extract) <$> infoJ p---- | Like `info`, but can handle requests for multiple packages at once.--- More efficient than using `info` multiple times.-multiinfo :: MonadIO m => [Text] -> m [AurInfo]-multiinfo ps = mapArray <$> multiinfoJ ps---- | Yields any matches to the input as `AurInfo`, but--- doesn't include dependency information.-search :: MonadIO m => Text -> m [AurInfo]-search s = mapArray <$> searchJ s---- | Search the AUR by Maintainer name.-msearch :: MonadIO m => Text -> m [AurInfo]-msearch m = mapArray <$> msearchJ m---- | `info` call as Haskellised JSON.-infoJ :: MonadIO m => Text -> m (Maybe Value)-infoJ p = (>>= (^? nth 0)) <$> multiinfoJ [p]---- | `multiinfo` call as Haskellised JSON.-multiinfoJ :: MonadIO m => [Text] -> m (Maybe Value)-multiinfoJ ps = multiinfoJ' ps aurUrl "4"---- | `search` call as Haskellised JSON.-searchJ :: MonadIO m => Text -> m (Maybe Value)-searchJ s = searchJ' s aurUrl "4"---- | `msearch` call as Haskellised JSON.-msearchJ :: MonadIO m => Text -> m (Maybe Value)-msearchJ m = msearchJ' m aurUrl "4"---- | `info` with explicit RPC endpoint and API version.-info' :: MonadIO m => Text -> String -> Text -> m (Maybe AurInfo)-info' p url ver = (>>= extract) <$> infoJ' p url ver---- | `multiinfo` with explicit RPC endpoint and API version.-multiinfo' :: MonadIO m => [Text] -> String -> Text -> m [AurInfo]-multiinfo' ps url ver = mapArray <$> multiinfoJ' ps url ver--search' :: MonadIO m => Text -> String -> Text -> m [AurInfo]-search' s url ver = mapArray <$> searchJ' s url ver--msearch' :: MonadIO m => Text -> String -> Text -> m [AurInfo]-msearch' m url ver = mapArray <$> msearchJ' m url ver--infoJ' :: MonadIO m => Text -> String -> Text -> m (Maybe Value)-infoJ' p url ver = (>>= (^? nth 0)) <$> multiinfoJ' [p] url ver+type Info = "rpc" :> QueryParam "v" String+ :> QueryParam "type" String+ :> QueryParams "arg[]" String+ :> Get '[JSON] RPCResp -multiinfoJ' :: MonadIO m => [Text] -> String -> Text -> m (Maybe Value)-multiinfoJ' ps url ver = rpc "multiinfo" ps "arg[]" url ver+type Search = "rpc" :> QueryParam "v" String+ :> QueryParam "type" String+ :> QueryParam "arg" String+ :> Get '[JSON] RPCResp -searchJ' :: MonadIO m => Text -> String -> Text -> m (Maybe Value)-searchJ' s url ver = rpc "search" [s] "arg" url ver+type API = Info :<|> Search -msearchJ' :: MonadIO m => Text -> String -> Text -> m (Maybe Value)-msearchJ' m url ver = rpc "msearch" [m] "arg" url ver+api :: Proxy API+api = Proxy --- | Call the RPC.--- Doesn't fail elegantly when there is a connection failure.-rpc :: MonadIO m => Text -> [Text] -> Text -> String -> Text -> m (Maybe Value)-rpc method args argLabel url ver = liftIO (rpcResults <$> getWith opts url)- where opts = defaults & param "type" .~ [method]- & param argLabel .~ args- & param "v" .~ [ver]+-- Bad, but necessary, apparently.+__manager :: Manager+__manager = unsafePerformIO $ newManager tlsManagerSettings -rpcResults :: AsValue r => Response r -> Maybe Value-rpcResults r = r ^? responseBody . key "results"+-- | Make a call to the AUR RPC. Assumes version 5 of the API.+rpcI :<|> rpcS = client api (BaseUrl Http aurUrl 80 "") __manager+ where aurUrl = "aur.archlinux.org" --- | Conversion of JSON to nicely formatted Text.-pretty :: Value -> Text-pretty = TL.toStrict . decodeUtf8 . encodePretty+-- | Perform an @info@ call on one or more package names.+info :: MonadIO m => [Text] -> m [AurInfo]+info = unwrap . rpcI (Just "5") (Just "info") . map unpack ------------------------ UTILITY FUNCTIONS----------------------extract :: FromJSON a => Value -> Maybe a-extract = f . fromJSON- where f (Success x) = Just x- f _ = Nothing+-- | Perform a @search@ call on a package name or description text.+search :: MonadIO m => Text -> m [AurInfo]+search = unwrap . rpcS (Just "5") (Just "search") . Just . unpack --- There must be a better way to do this.--- Use lenses, child.-mapArray :: FromJSON a => Maybe Value -> [a]-mapArray (Just (Array v)) = catMaybes . V.toList . V.map extract $ v-mapArray _ = []+unwrap :: MonadIO m => ExceptT ServantError IO RPCResp -> m [AurInfo]+unwrap = liftIO . fmap (either (const []) _results) . runExceptT
Linux/Arch/Aur/Types.hs view
@@ -2,12 +2,14 @@ -- | -- Module : Linux.Arch.Aur.Types--- Copyright : (c) Colin Woodbury, 2014, 2015+-- Copyright : (c) Colin Woodbury, 2014, 2015, 2016 -- License : GPL3 -- Maintainer: Colin Woodbury <colingw@gmail.com> module Linux.Arch.Aur.Types- ( AurInfo(..) ) where+ ( RPCResp(..)+ , AurInfo(..)+ ) where import Control.Applicative ((<|>)) import Control.Monad (mzero)@@ -16,13 +18,26 @@ --- +data RPCResp = RPCResp { _version :: Int+ , _type :: Text+ , _resultCount :: Int+ , _results :: [AurInfo] } deriving (Show)++instance FromJSON RPCResp where+ parseJSON (Object v) = RPCResp <$>+ v .: "version" <*>+ v .: "type" <*>+ v .: "resultcount" <*>+ v .: "results"++ parseJSON _ = mzero+ data AurInfo = AurInfo { aurIdOf :: Int , aurNameOf :: Text , pkgBaseIdOf :: Int , pkgBaseOf :: Text , aurVersionOf :: Text , aurDescriptionOf :: Text- , licenseOf :: [Text] , urlOf :: Text , aurVotesOf :: Int , popularityOf :: Float@@ -35,7 +50,9 @@ , makeDepsOf :: [Text] , optDepsOf :: [Text] , conflictsOf :: [Text]- , providesOf :: [Text] } deriving (Eq,Show)+ , providesOf :: [Text]+ , licenseOf :: [Text]+ , keywordsOf :: [Text] } deriving (Eq,Show) instance FromJSON AurInfo where parseJSON (Object v) = AurInfo <$>@@ -45,7 +62,6 @@ v .: "PackageBase" <*> v .: "Version" <*> v .: "Description" <*>- v .:? "License" .!= [] <*> v .: "URL" <*> v .: "NumVotes" <*> v .: "Popularity" <*>@@ -58,6 +74,8 @@ v .:? "MakeDepends" .!= [] <*> v .:? "OptDepends" .!= [] <*> v .:? "Conflicts" .!= [] <*>- v .:? "Provides" .!= []+ v .:? "Provides" .!= [] <*>+ v .:? "License" .!= [] <*>+ v .:? "Keywords" .!= [] parseJSON _ = mzero
aur.cabal view
@@ -1,6 +1,6 @@ name: aur -version: 4.0.2+version: 5.0.0 synopsis: Access metadata from the Arch Linux User Repository. @@ -26,16 +26,11 @@ . * info: Get metadata for one package. .- * multiinfo: Get metadata for many packages at once.- . * search: Get limited metadata for packages that match a given regex. .- * msearch: Get metadata for all packages maintained- by a given user.- .- By default this library supports version 3 of the RPC,- and hence version 3.2+ of the AUR.+ By default this library supports version 5 of the RPC,+ and hence version 4.2+ of the AUR. source-repository head type: git@@ -43,21 +38,18 @@ library exposed-modules: Linux.Arch.Aur,- Linux.Arch.Aur.Pkgbuild, Linux.Arch.Aur.Rpc, Linux.Arch.Aur.Types - other-extensions: OverloadedStrings, ScopedTypeVariables- - build-depends: base >=4.8 && <4.9,- aeson >=0.7 && <1,- aeson-pretty >=0.7 && <1,- filepath,- lens >=4.2 && <5,- lens-aeson,- mtl >=2.1 && <3,- text >=1.1 && <1.3,- vector >=0.10,- wreq >=0.4- + build-depends:+ base >=4.8 && <4.9+ , aeson >= 0.9.0.1+ , http-client >= 0.4.27+ , http-client-tls >= 0.2.2+ , mtl >= 2.2.1+ , servant >= 0.5 && < 0.6+ , servant-client >= 0.5 && < 0.6+ , text >=1.1 && <1.3+ , transformers >= 0.4.2.0+ default-language: Haskell2010