Prechádzať zdrojové kódy

Add JsonEncode instances for Output

jherve 1 rok pred
rodič
commit
9e12695889

+ 3 - 1
spago.dhall

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

+ 4 - 0
src/Content.purs

@@ -3,6 +3,7 @@ module ExampleWebExt.Content where
 import Prelude
 
 import Browser.DOM (getBrowserDom)
+import Data.Argonaut.Encode (toJsonString)
 import Effect (Effect)
 import Effect.Class.Console (logShow)
 import Effect.Console (log)
@@ -15,3 +16,6 @@ main = do
   dom <- getBrowserDom
   getContext 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 Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Either (Either, note)
 import Data.Generic.Rep (class Generic)
 import Data.Lens (findOf)
 import Data.Maybe (Maybe(..), isJust)
 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.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.Strings.Types (UIString(..))
 
 data JobOffer = JobOffer {
   title :: String,
@@ -27,6 +29,8 @@ derive instance Eq JobOffer
 derive instance Generic JobOffer _
 instance Show JobOffer where
   show = genericShow
+instance EncodeJson JobOffer where
+  encodeJson a = genericEncodeJson a
 
 fromUI ∷ JobsUnifiedTopCardElement UIElement → Either String JobOffer
 fromUI card = ado

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

@@ -2,6 +2,8 @@ module LinkedIn.Output.Types where
 
 import Prelude
 
+import Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Generic.Rep (class Generic)
 import Data.List.Types (NonEmptyList)
 import Data.Show.Generic (genericShow)
@@ -19,3 +21,5 @@ data Output =
 derive instance Generic Output _
 instance Show Output where
   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 Data.Argonaut.Encode (class EncodeJson)
+import Data.Argonaut.Encode.Generic (genericEncodeJson)
 import Data.Either (Either, note)
 import Data.Generic.Rep (class Generic)
 import Data.List as L
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
-import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderNormal)
 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.Strings.Types (UIString(..))
 
 data Project = Project {
   name :: String,
@@ -21,6 +23,8 @@ data Project = Project {
 derive instance Generic Project _
 instance Show Project where
   show = genericShow
+instance EncodeJson Project where
+  encodeJson a = genericEncodeJson a
 
 fromUI ∷ ArtDecoCardElement UIElement → Either String Project
 fromUI card = ado

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

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

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

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

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

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