diff options
Diffstat (limited to 'lib/OwnTracks/Command.hs')
| -rw-r--r-- | lib/OwnTracks/Command.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/OwnTracks/Command.hs b/lib/OwnTracks/Command.hs index 257d3e3..532a593 100644 --- a/lib/OwnTracks/Command.hs +++ b/lib/OwnTracks/Command.hs @@ -42,6 +42,7 @@ data Command = -- ^ Imports and activates new configuration values (iOS,Android) | GetWaypoints -- ^ Triggers publish of a waypoints message (iOS,Android) + deriving (Eq, Show, Generic) instance ToJSON Command where toJSON c = object ( "_type" .= String "cmd" @@ -61,3 +62,18 @@ instance ToJSON Command where SetWaypoints ws -> [ "waypoints" .= ws ] SetConfiguration c -> [ "configuration" .= c ] _ -> [] + +instance FromJSON Command where + parseJSON (Object v) = do + action :: Text <- v .: "action" + case action of + "dump" -> pure Dump + "status" -> pure GetStatus + "reportSteps" -> ReportSteps <$> v .: "from" <*> v .: "to" + "reportLocation" -> pure ReportLocation + "clearWaypoints" -> pure ClearWaypoints + "setWaypoints" -> SetWaypoints <$> v .: "waypoints" + "setConfiguration" -> SetConfiguration <$> v .: "configuration" + "waypoints" -> pure GetWaypoints + _ -> fail "unknown action in _type=command" + parseJSON _ = fail "Command should be an object" |
