JobOffer.purs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. module LinkedIn.Jobs.JobOffer where
  2. import Prelude
  3. import Data.Either (Either, note)
  4. import Data.Foldable (findMap)
  5. import Data.Generic.Rep (class Generic)
  6. import Data.Maybe (Maybe(..))
  7. import Data.Show.Generic (genericShow)
  8. import LinkedIn.DetachedNode (DetachedNode)
  9. import LinkedIn.JobsUnifiedTopCard (JobsUnifiedTopCardElement, toHeader, toPrimaryDescriptionLink, toPrimaryDescriptionText)
  10. import LinkedIn.Profile.Utils (toUIElement)
  11. import LinkedIn.UIElements.Types (UIElement(..), UIString(..))
  12. data JobOffer = JobOffer {
  13. title :: String,
  14. companyName :: String,
  15. companyLink :: String,
  16. location :: Maybe String
  17. }
  18. derive instance Generic JobOffer _
  19. instance Show JobOffer where
  20. show = genericShow
  21. fromUI ∷ JobsUnifiedTopCardElement DetachedNode → Either String JobOffer
  22. fromUI card = ado
  23. title <- note "No title found" $ findMap extractTitle header
  24. companyName <- note "No company found" $ findMap extractCompany link
  25. companyLink <- note "No company link found" $ findMap extractCompanyLink link
  26. in
  27. JobOffer { title, companyName, companyLink, location: findMap extractLocation primaryDescText }
  28. where
  29. asUI = toUIElement <$> card
  30. header = toHeader asUI
  31. link = toPrimaryDescriptionLink asUI
  32. primaryDescText = toPrimaryDescriptionText asUI
  33. extractTitle :: UIElement -> Maybe String
  34. extractTitle = case _ of
  35. UIElement (UIStringPlain str) -> Just str
  36. _ -> Nothing
  37. extractCompany :: UIElement -> Maybe String
  38. extractCompany = case _ of
  39. UILink _ (UIStringPlain str) -> Just str
  40. _ -> Nothing
  41. extractCompanyLink :: UIElement -> Maybe String
  42. extractCompanyLink = case _ of
  43. UILink link _ -> Just link
  44. _ -> Nothing
  45. extractLocation :: UIElement -> Maybe String
  46. extractLocation = case _ of
  47. UIElement (UIStringDotSeparated _ (UIStringPlain str)) -> Just str
  48. _ -> Nothing