Quellcode durchsuchen

Add JsonEncode instances for Output

jherve vor 1 Jahr
Ursprung
Commit
9e12695889

+ 3 - 1
spago.dhall

@@ -4,7 +4,9 @@ You can edit this file as you like.
 -}
 -}
 { name = "web-extension"
 { name = "web-extension"
 , dependencies =
 , dependencies =
-  [ "arrays"
+  [ "argonaut-codecs"
+  , "argonaut-generic"
+  , "arrays"
   , "assert"
   , "assert"
   , "console"
   , "console"
   , "control"
   , "control"

+ 4 - 0
src/Content.purs

@@ -3,6 +3,7 @@ module ExampleWebExt.Content where
 import Prelude
 import Prelude
 
 
 import Browser.DOM (getBrowserDom)
 import Browser.DOM (getBrowserDom)
+import Data.Argonaut.Encode (toJsonString)
 import Effect (Effect)
 import Effect (Effect)
 import Effect.Class.Console (logShow)
 import Effect.Class.Console (logShow)
 import Effect.Console (log)
 import Effect.Console (log)
@@ -15,3 +16,6 @@ main = do
   dom <- getBrowserDom
   dom <- getBrowserDom
   getContext dom >>= logShow
   getContext dom >>= logShow
   extractFromDocument dom >>= logShow
   extractFromDocument dom >>= logShow
+
+  extracted <- extractFromDocument dom
+  log $ toJsonString extracted

+ 6 - 2
src/LinkedIn/Jobs/JobOffer.purs

@@ -2,15 +2,17 @@ module LinkedIn.Jobs.JobOffer where
 
 
 import Prelude
 import Prelude
 
 
+import Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Either (Either, note)
 import Data.Either (Either, note)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
 import Data.Lens (findOf)
 import Data.Lens (findOf)
 import Data.Maybe (Maybe(..), isJust)
 import Data.Maybe (Maybe(..), isJust)
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
-import LinkedIn.UI.Components.JobsUnifiedTopCard (JobsUnifiedTopCardElement, TopCardInsight(..), TopCardInsightContent(..), _top_to_action_buttons, _top_to_insights, toHeader, toPrimaryDescriptionLink, toPrimaryDescriptionText)
 import LinkedIn.UI.Basic.Types (JobFlexibility)
 import LinkedIn.UI.Basic.Types (JobFlexibility)
-import LinkedIn.UI.Strings.Types (UIString(..))
+import LinkedIn.UI.Components.JobsUnifiedTopCard (JobsUnifiedTopCardElement, TopCardInsight(..), TopCardInsightContent(..), _top_to_action_buttons, _top_to_insights, toHeader, toPrimaryDescriptionLink, toPrimaryDescriptionText)
 import LinkedIn.UI.Elements.Types (UIElement(..))
 import LinkedIn.UI.Elements.Types (UIElement(..))
+import LinkedIn.UI.Strings.Types (UIString(..))
 
 
 data JobOffer = JobOffer {
 data JobOffer = JobOffer {
   title :: String,
   title :: String,
@@ -27,6 +29,8 @@ derive instance Eq JobOffer
 derive instance Generic JobOffer _
 derive instance Generic JobOffer _
 instance Show JobOffer where
 instance Show JobOffer where
   show = genericShow
   show = genericShow
+instance EncodeJson JobOffer where
+  encodeJson a = genericEncodeJson a
 
 
 fromUI ∷ JobsUnifiedTopCardElement UIElement → Either String JobOffer
 fromUI ∷ JobsUnifiedTopCardElement UIElement → Either String JobOffer
 fromUI card = ado
 fromUI card = ado

+ 4 - 0
src/LinkedIn/Output/Types.purs

@@ -2,6 +2,8 @@ module LinkedIn.Output.Types where
 
 
 import Prelude
 import Prelude
 
 
+import Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
 import Data.List.Types (NonEmptyList)
 import Data.List.Types (NonEmptyList)
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
@@ -19,3 +21,5 @@ data Output =
 derive instance Generic Output _
 derive instance Generic Output _
 instance Show Output where
 instance Show Output where
   show = genericShow
   show = genericShow
+instance EncodeJson Output where
+  encodeJson a = genericEncodeJson a

+ 6 - 2
src/LinkedIn/Profile/Project.purs

@@ -2,15 +2,17 @@ module LinkedIn.Profile.Project where
 
 
 import Prelude
 import Prelude
 
 
+import Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Either (Either, note)
 import Data.Either (Either, note)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
 import Data.List as L
 import Data.List as L
 import Data.Maybe (Maybe(..))
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
-import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderNormal)
 import LinkedIn.UI.Basic.Types (TimeSpan)
 import LinkedIn.UI.Basic.Types (TimeSpan)
-import LinkedIn.UI.Strings.Types (UIString(..))
+import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderNormal)
 import LinkedIn.UI.Elements.Types (UIElement(..))
 import LinkedIn.UI.Elements.Types (UIElement(..))
+import LinkedIn.UI.Strings.Types (UIString(..))
 
 
 data Project = Project {
 data Project = Project {
   name :: String,
   name :: String,
@@ -21,6 +23,8 @@ data Project = Project {
 derive instance Generic Project _
 derive instance Generic Project _
 instance Show Project where
 instance Show Project where
   show = genericShow
   show = genericShow
+instance EncodeJson Project where
+  encodeJson a = genericEncodeJson a
 
 
 fromUI ∷ ArtDecoCardElement UIElement → Either String Project
 fromUI ∷ ArtDecoCardElement UIElement → Either String Project
 fromUI card = ado
 fromUI card = ado

+ 5 - 1
src/LinkedIn/Profile/Skill.purs

@@ -2,13 +2,15 @@ module LinkedIn.Profile.Skill where
 
 
 import Prelude
 import Prelude
 
 
+import Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Either (Either, note)
 import Data.Either (Either, note)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
 import Data.Maybe (Maybe(..))
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
 import LinkedIn.UI.Components.ArtDecoTab (ArtDecoTabElement, toHeaderBold)
 import LinkedIn.UI.Components.ArtDecoTab (ArtDecoTabElement, toHeaderBold)
-import LinkedIn.UI.Strings.Types (UIString(..))
 import LinkedIn.UI.Elements.Types (UIElement(..))
 import LinkedIn.UI.Elements.Types (UIElement(..))
+import LinkedIn.UI.Strings.Types (UIString(..))
 
 
 data Skill = Skill {
 data Skill = Skill {
   name :: String
   name :: String
@@ -17,6 +19,8 @@ data Skill = Skill {
 derive instance Generic Skill _
 derive instance Generic Skill _
 instance Show Skill where
 instance Show Skill where
   show = genericShow
   show = genericShow
+instance EncodeJson Skill where
+  encodeJson a = genericEncodeJson a
 
 
 fromUI ∷ ArtDecoTabElement UIElement → Either String Skill
 fromUI ∷ ArtDecoTabElement UIElement → Either String Skill
 fromUI tab = ado
 fromUI tab = ado

+ 6 - 2
src/LinkedIn/Profile/WorkExperience.purs

@@ -2,16 +2,18 @@ module LinkedIn.Profile.WorkExperience where
 
 
 import Prelude
 import Prelude
 
 
+import Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Either (Either, note)
 import Data.Either (Either, note)
 import Data.Foldable (findMap)
 import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
 import Data.List as L
 import Data.List as L
 import Data.Maybe (Maybe(..))
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
-import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderLight, toHeaderNormal)
 import LinkedIn.UI.Basic.Types (Duration, TimeSpan)
 import LinkedIn.UI.Basic.Types (Duration, TimeSpan)
-import LinkedIn.UI.Strings.Types (UIString(..))
+import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderLight, toHeaderNormal)
 import LinkedIn.UI.Elements.Types (UIElement(..))
 import LinkedIn.UI.Elements.Types (UIElement(..))
+import LinkedIn.UI.Strings.Types (UIString(..))
 
 
 data WorkExperience = WorkExperience {
 data WorkExperience = WorkExperience {
   position :: String,
   position :: String,
@@ -26,6 +28,8 @@ derive instance Generic WorkExperience _
 derive instance Eq WorkExperience
 derive instance Eq WorkExperience
 instance Show WorkExperience where
 instance Show WorkExperience where
   show = genericShow
   show = genericShow
+instance EncodeJson WorkExperience where
+  encodeJson a = genericEncodeJson a
 
 
 fromUI ∷ ArtDecoCardElement UIElement → Either String WorkExperience
 fromUI ∷ ArtDecoCardElement UIElement → Either String WorkExperience
 fromUI card = ado
 fromUI card = ado

+ 11 - 0
src/LinkedIn/UI/Basic/Types.purs

@@ -2,6 +2,9 @@ module LinkedIn.UI.Basic.Types where
 
 
 import Prelude
 import Prelude
 
 
+import Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Encoders (encodeString)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Date (Month, Year)
 import Data.Date (Month, Year)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
 import Data.Int64 (Int64)
 import Data.Int64 (Int64)
@@ -20,6 +23,8 @@ derive instance Eq MonthYear
 derive instance Generic MonthYear _
 derive instance Generic MonthYear _
 instance Show MonthYear where
 instance Show MonthYear where
   show = genericShow
   show = genericShow
+instance EncodeJson MonthYear where
+  encodeJson a = encodeString "monthyear" -- TODO
 
 
 data TimeSpan =
 data TimeSpan =
   TimeSpanBounded MonthYear MonthYear
   TimeSpanBounded MonthYear MonthYear
@@ -29,6 +34,8 @@ derive instance Eq TimeSpan
 derive instance Generic TimeSpan _
 derive instance Generic TimeSpan _
 instance Show TimeSpan where
 instance Show TimeSpan where
   show = genericShow
   show = genericShow
+instance EncodeJson TimeSpan where
+  encodeJson a = genericEncodeJson a
 
 
 data MonthYearOrToday = MY MonthYear | Today
 data MonthYearOrToday = MY MonthYear | Today
 
 
@@ -41,6 +48,8 @@ derive instance Eq Duration
 derive instance Generic Duration _
 derive instance Generic Duration _
 instance Show Duration where
 instance Show Duration where
   show = genericShow
   show = genericShow
+instance EncodeJson Duration where
+  encodeJson a = encodeString "duration" -- TODO
 
 
 data JobFlexibility = JobFlexHybrid | JobFlexOnSite | JobFlexFullRemote
 data JobFlexibility = JobFlexHybrid | JobFlexOnSite | JobFlexFullRemote
 
 
@@ -48,3 +57,5 @@ derive instance Eq JobFlexibility
 derive instance Generic JobFlexibility _
 derive instance Generic JobFlexibility _
 instance Show JobFlexibility where
 instance Show JobFlexibility where
   show = genericShow
   show = genericShow
+instance EncodeJson JobFlexibility where
+  encodeJson a = genericEncodeJson a