api-builder 0.4.0.0 → 0.5.0.0
raw patch · 4 files changed
+15/−23 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Network.API.Builder.Query: toQuery :: ToQuery a => a -> Maybe Text
+ Network.API.Builder.Query: toQuery :: ToQuery a => Text -> a -> [(Text, Text)]
- Network.API.Builder.Routes: (=.) :: ToQuery a => Text -> a -> (Text, Maybe Text)
+ Network.API.Builder.Routes: (=.) :: ToQuery a => Text -> a -> [(Text, Text)]
- Network.API.Builder.Routes: type URLParam = (Text, Maybe Text)
+ Network.API.Builder.Routes: type URLParam = [(Text, Text)]
Files
- api-builder.cabal +1/−1
- src/Network/API/Builder/Error.hs +0/−2
- src/Network/API/Builder/Query.hs +10/−11
- src/Network/API/Builder/Routes.hs +4/−9
api-builder.cabal view
@@ -1,5 +1,5 @@ name: api-builder-version: 0.4.0.0+version: 0.5.0.0 synopsis: Library for easily building REST API wrappers in Haskell license: BSD3 author: Fraser Murray
src/Network/API/Builder/Error.hs view
@@ -17,8 +17,6 @@ deriving Show instance Eq a => Eq (APIError a) where- (HTTPError _) == _ = False- _ == (HTTPError _) = False (APIError a) == (APIError b) = a == b InvalidURLError == InvalidURLError = True (ParseError a) == (ParseError b) = a == b
src/Network/API/Builder/Query.hs view
@@ -1,29 +1,28 @@ module Network.API.Builder.Query where -import Data.Maybe import Data.Text (Text) import qualified Data.Text as Text class ToQuery a where- toQuery :: a -> Maybe Text+ toQuery :: Text -> a -> [(Text, Text)] instance ToQuery Integer where- toQuery = Just . Text.pack . show+ toQuery k v = [(k, Text.pack $ show v)] instance ToQuery Bool where- toQuery True = Just "true"- toQuery False = Just "false"+ toQuery k True = [(k, "true")]+ toQuery k False = [(k, "false")] instance ToQuery Int where- toQuery = Just . Text.pack . show+ toQuery k v = [(k, Text.pack $ show v)] instance ToQuery Text where- toQuery = Just+ toQuery k v = [(k, v)] instance ToQuery a => ToQuery (Maybe a) where- toQuery (Just a) = toQuery a- toQuery Nothing = Nothing+ toQuery k (Just a) = toQuery k a+ toQuery _ Nothing = [] instance ToQuery a => ToQuery [a] where- toQuery [] = Nothing- toQuery xs = Just $ Text.intercalate "," $ mapMaybe toQuery xs+ toQuery _ [] = []+ toQuery k xs = [(k, Text.intercalate "," $ map snd $ concatMap (toQuery k) xs)]
src/Network/API/Builder/Routes.hs view
@@ -6,7 +6,6 @@ , routeURL ) where import Control.Arrow ((***))-import Data.Maybe (mapMaybe) import Data.Monoid ((<>)) import Data.Text (Text) import qualified Data.Text as T@@ -20,7 +19,7 @@ -- | Alias to @(Text, Maybe Text)@ used to store each query that gets -- tacked onto the request.-type URLParam = (Text, Maybe Text)+type URLParam = [(Text, Text)] -- | Convenience function for building @URLParam@s. Right-hand argument must -- have a @ToQuery@ instance so it can be converted to the appropriate@@ -29,8 +28,8 @@ -- -- >>> "api_type" =. ("json" :: Text) -- ("api_type", Just "json")-(=.) :: ToQuery a => Text -> a -> (Text, Maybe Text)-k =. v = (k, toQuery v)+(=.) :: ToQuery a => Text -> a -> [(Text, Text)]+k =. v = toQuery k v -- | Main type for routes in the API. Used to represent the URL minus the actual -- endpoint URL as well as the query string and the HTTP method used to communicate@@ -54,8 +53,4 @@ pathParamsSep xs = if T.isInfixOf "." (last xs) then "?" else "/?" buildParams :: [URLParam] -> Text-buildParams = T.pack . HTTP.urlEncodeVars . map (T.unpack *** T.unpack) . mapMaybe collectParams--collectParams :: URLParam -> Maybe (Text, Text)-collectParams (a, Just x) = Just (a,x)-collectParams (_, Nothing) = Nothing+buildParams = T.pack . HTTP.urlEncodeVars . concatMap (map (T.unpack *** T.unpack))