[aeson] fix incomplete pattern matches in ISTEX.Client parsing

parent 5f1f42e3
...@@ -44,7 +44,7 @@ common defaults ...@@ -44,7 +44,7 @@ common defaults
, servant >= 0.20 && < 0.21 , servant >= 0.20 && < 0.21
, servant-client >= 0.20 && < 0.21 , servant-client >= 0.20 && < 0.21
, text >= 2.0.2 && < 2.2 , text >= 2.0.2 && < 2.2
ghc-options: -Wall -Wunused-imports -Wunused-binds -Wmissing-signatures -Werror ghc-options: -Wall -Wincomplete-uni-patterns -Wmissing-signatures -Wunused-imports -Wunused-binds -Werror
library library
import: import:
......
...@@ -3,16 +3,14 @@ ...@@ -3,16 +3,14 @@
module ISTEX.Client where module ISTEX.Client where
import Control.Applicative ((<|>)) import Control.Applicative ((<|>))
import Control.Lens qualified as L
import Data.Aeson import Data.Aeson
import Data.Proxy (Proxy(..))
import Data.Text qualified as T
import GHC.Generics import GHC.Generics
import Text.Read (readEither)
import Servant.API import Servant.API
import Servant.Client import Servant.Client
import Data.Proxy (Proxy(..)) import Text.Read (readEither)
import qualified Data.Text as T
import qualified Control.Lens as L
data Author = Author data Author = Author
{ _author_name :: T.Text { _author_name :: T.Text
...@@ -21,8 +19,10 @@ data Author = Author ...@@ -21,8 +19,10 @@ data Author = Author
L.makeLenses ''Author L.makeLenses ''Author
instance FromJSON Author where instance FromJSON Author where
parseJSON (Object o) = parseJSON = withObject "Author" $ \o -> do
Author <$> (o .: "name") <*> (o .: "affiliations" <|> pure []) _author_name <- o .: "name"
_author_affiliations <- o .: "affiliations" <|> pure []
pure $ Author { .. }
data Source = Source data Source = Source
{ _source_title :: Maybe T.Text { _source_title :: Maybe T.Text
...@@ -41,7 +41,7 @@ parsePubDate (Just pubDate) = ...@@ -41,7 +41,7 @@ parsePubDate (Just pubDate) =
ePubDate = readEither (T.unpack pubDate) :: Either String Int ePubDate = readEither (T.unpack pubDate) :: Either String Int
instance FromJSON Source where instance FromJSON Source where
parseJSON (Object o) = do parseJSON = withObject "Source" $ \o -> do
_source_title <- o .:? "title" _source_title <- o .:? "title"
-- _source_authors <- o .:? "author" -- _source_authors <- o .:? "author"
mPubDate <- o .:? "publicationDate" mPubDate <- o .:? "publicationDate"
...@@ -60,7 +60,7 @@ data Document = Document ...@@ -60,7 +60,7 @@ data Document = Document
L.makeLenses ''Document L.makeLenses ''Document
instance FromJSON Document where instance FromJSON Document where
parseJSON (Object o) = do parseJSON = withObject "Document" $ \o -> do
_document_id <- o .: "id" <|> o .: "_id" _document_id <- o .: "id" <|> o .: "_id"
_document_title <- o .:? "title" _document_title <- o .:? "title"
_document_authors <- o .: "author" <|> pure [] _document_authors <- o .: "author" <|> pure []
...@@ -76,8 +76,10 @@ data Documents = Documents ...@@ -76,8 +76,10 @@ data Documents = Documents
} deriving (Show, Generic) } deriving (Show, Generic)
L.makeLenses ''Documents L.makeLenses ''Documents
instance FromJSON Documents where instance FromJSON Documents where
parseJSON (Object o) = parseJSON = withObject "Documents" $ \o -> do
Documents <$> (o .: "total") <*> (o .: "hits") _documents_total <- o .: "total"
_documents_hits <- o .: "hits"
pure $ Documents { .. }
instance Semigroup Documents where instance Semigroup Documents where
(<>) (Documents { _documents_total (<>) (Documents { _documents_total
, _documents_hits = d1 }) , _documents_hits = d1 })
...@@ -96,7 +98,7 @@ data ScrollResponse = ScrollResponse ...@@ -96,7 +98,7 @@ data ScrollResponse = ScrollResponse
L.makeLenses ''ScrollResponse L.makeLenses ''ScrollResponse
instance FromJSON ScrollResponse where instance FromJSON ScrollResponse where
parseJSON (Object o) = do parseJSON = withObject "ScrollResponse" $ \o -> do
_documents_total <- o .: "total" _documents_total <- o .: "total"
_documents_hits <- o .: "hits" _documents_hits <- o .: "hits"
_scroll_noMoreScrollResults <- o .:? "noMoreScrollResults" _scroll_noMoreScrollResults <- o .:? "noMoreScrollResults"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment