Commit c673924b authored by Grégoire Locqueville's avatar Grégoire Locqueville

[FIX]: Align with OpenAlex API breakage

Fixes haskell-gargantext#379 issue: gargantext/haskell-gargantext#379
* `raw_affiliation_string` could be empty: added `Maybe` to the type
* Added the "diamond" (`OADiamond` constructor) option to the OA status (`OAStatus` type)
parent ceb8f2ce
...@@ -58,7 +58,7 @@ type ISSNL = Text ...@@ -58,7 +58,7 @@ type ISSNL = Text
type Language = Text -- TODO: https://doc.wikimedia.org/mediawiki-core/master/php/Names_8php_source.html type Language = Text -- TODO: https://doc.wikimedia.org/mediawiki-core/master/php/Names_8php_source.html
type Level = Int type Level = Int
-- |https://docs.openalex.org/api-entities/works/work-object#oa_status -- |https://docs.openalex.org/api-entities/works/work-object#oa_status
data OAStatus = OAGold | OAGreen | OAHybrid | OABronze | OAClosed data OAStatus = OAGold | OAGreen | OAHybrid | OABronze | OAClosed | OADiamond
deriving (Generic, Show) deriving (Generic, Show)
instance FromJSON OAStatus where instance FromJSON OAStatus where
parseJSON (String "gold") = pure OAGold parseJSON (String "gold") = pure OAGold
...@@ -66,7 +66,9 @@ instance FromJSON OAStatus where ...@@ -66,7 +66,9 @@ instance FromJSON OAStatus where
parseJSON (String "hybrid") = pure OAHybrid parseJSON (String "hybrid") = pure OAHybrid
parseJSON (String "bronze") = pure OABronze parseJSON (String "bronze") = pure OABronze
parseJSON (String "closed") = pure OAClosed parseJSON (String "closed") = pure OAClosed
parseJSON _ = fail "Don't know how to parse this oa status" parseJSON (String "diamond") = pure OADiamond
parseJSON (String str) = fail $ "Don't know how to parse this oa status: " <> Protolude.show str
parseJSON _ = fail "OAStatus should be a string"
type OpenAlexID = Text type OpenAlexID = Text
type URL = Text type URL = Text
type Year = Int type Year = Int
...@@ -366,7 +368,7 @@ data Authorship = Authorship ...@@ -366,7 +368,7 @@ data Authorship = Authorship
, author_position :: Text , author_position :: Text
, institutions :: [DehydratedInstitution] , institutions :: [DehydratedInstitution]
, is_corresponding :: Maybe Bool , is_corresponding :: Maybe Bool
, raw_affiliation_string :: Text , raw_affiliation_string :: Maybe Text
} deriving (Generic, Show, FromJSON) } deriving (Generic, Show, FromJSON)
authorshipAuthorName :: Authorship -> Maybe Text authorshipAuthorName :: Authorship -> Maybe Text
authorshipAuthorName (Authorship { author = DehydratedAuthor { display_name } }) = display_name authorshipAuthorName (Authorship { author = DehydratedAuthor { display_name } }) = display_name
......
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