ソースを参照

Extract hasSimplifiedApplicationProcess information

jherve 1 年間 前
コミット
ac3a54220e

+ 16 - 4
src/LinkedIn/Jobs/JobOffer.purs

@@ -5,9 +5,9 @@ import Prelude
 import Data.Either (Either, note)
 import Data.Generic.Rep (class Generic)
 import Data.Lens (findOf)
-import Data.Maybe (Maybe(..))
+import Data.Maybe (Maybe(..), isJust)
 import Data.Show.Generic (genericShow)
-import LinkedIn.JobsUnifiedTopCard (JobsUnifiedTopCardElement, TopCardInsight(..), TopCardInsightContent(..), _top_to_insights, toHeader, toPrimaryDescriptionLink, toPrimaryDescriptionText)
+import LinkedIn.JobsUnifiedTopCard (JobsUnifiedTopCardElement, TopCardInsight(..), TopCardInsightContent(..), _top_to_action_buttons, _top_to_insights, toHeader, toPrimaryDescriptionLink, toPrimaryDescriptionText)
 import LinkedIn.UIElements.Types (UIElement(..), UIString(..))
 
 data JobOffer = JobOffer {
@@ -17,7 +17,8 @@ data JobOffer = JobOffer {
   location :: Maybe String,
   remote :: Maybe String,
   companyDomain :: Maybe String,
-  companySize :: Maybe String
+  companySize :: Maybe String,
+  hasSimplifiedApplicationProcess :: Boolean
 }
 
 derive instance Generic JobOffer _
@@ -37,7 +38,8 @@ fromUI card = ado
       location: extractLocation primaryDescText,
       remote: extractJobRemote =<< jobInsight,
       companyDomain: extractCompanyDomain =<< companyInsight,
-      companySize: extractCompanySize =<< companyInsight
+      companySize: extractCompanySize =<< companyInsight,
+      hasSimplifiedApplicationProcess: isJust $ extractSimplifiedApplicationProcess =<< applyButton
     }
   where
     header = toHeader card
@@ -45,6 +47,11 @@ fromUI card = ado
     primaryDescText = toPrimaryDescriptionText card
     jobInsight = getInsight "job" card
     companyInsight = getInsight "company" card
+    applyButton = findOf _top_to_action_buttons isApply card
+      where
+        isApply = case _ of
+          UIButton {mainClass: Just main} -> main == "jobs-apply-button"
+          _ -> false
 
 getInsight ∷ String → JobsUnifiedTopCardElement UIElement → Maybe (TopCardInsight UIElement)
 getInsight i card = findOf _top_to_insights (isIcon i) card
@@ -87,3 +94,8 @@ extractJobRemote :: TopCardInsight UIElement -> Maybe String
 extractJobRemote = case _ of
   TopCardInsight {content: TopCardInsightContentSecondary {primary: (UIElement (UIStringPlain str))}} -> Just str
   _ -> Nothing
+
+extractSimplifiedApplicationProcess ∷ UIElement → Maybe Boolean
+extractSimplifiedApplicationProcess = case _ of
+  UIButton {role: Nothing} -> Just true
+  _ -> Nothing

+ 6 - 0
src/LinkedIn/JobsUnifiedTopCard.purs

@@ -276,6 +276,12 @@ _top_to_insights = _top_card
 _insight_to_content = prop (Proxy :: Proxy "content")
   <<< traversed
 
+_top_to_action_buttons = _top_card
+  <<< prop (Proxy :: Proxy "actions")
+  <<< traversed
+  <<< traversed
+  <<< _action_button
+
 _top_card ∷ forall a. Lens' (JobsUnifiedTopCardElement a) { actions ∷ Maybe (NonEmptyList (TopCardAction a)) , header ∷ a , insights ∷ Maybe (NonEmptyList (TopCardInsight a)) , primaryDescription ∷ TopCardPrimaryDescription a }
 _top_card = lens' \(JobsUnifiedTopCardElement c) -> Tuple c \c' -> JobsUnifiedTopCardElement c'
 

+ 3 - 2
src/LinkedIn/Profile/Utils.purs

@@ -4,6 +4,7 @@ import Prelude
 
 import Control.Alt ((<|>))
 import Data.Either (Either(..))
+import Data.List as L
 import Data.Maybe (Maybe(..))
 import Data.Traversable (class Traversable, traverse)
 import Effect (Effect)
@@ -34,8 +35,8 @@ toUIElement (DetachedSvgElement _) = Left (ParseError "SVG element could not be
 
 toUIElement (DetachedLiIcon i) = Right (UIIcon i)
 
-toUIElement (DetachedButton {content, role}) =  map toButton $ runParser content uiStringP
-  where toButton ui = UIButton role ui
+toUIElement (DetachedButton {content, role, classes}) =  map toButton $ runParser content uiStringP
+  where toButton ui = UIButton {role, label: ui, mainClass: L.head classes}
 
 toUIElement (DetachedA {content, href}) = map toLink $ runParser content uiStringP
   where toLink ui = UILink href ui

+ 1 - 1
src/LinkedIn/UIElements/Types.purs

@@ -50,7 +50,7 @@ instance Show UIString where
 data UIElement =
   UIElement UIString
   | UILink String UIString
-  | UIButton (Maybe String) UIString
+  | UIButton {role :: Maybe String, label :: UIString, mainClass :: Maybe String}
   | UIIcon String
 
 derive instance Generic UIElement _