{-# LANGUAGE OverloadedStrings #-}
module Tesla.Car.Command.Sharing (share) where
import Control.Monad.IO.Class (MonadIO (..))
import Data.Aeson
import Data.Text (Text)
import Data.Time.Clock.POSIX (getCurrentTime, utcTimeToPOSIXSeconds)
import Tesla.Car.Command
share :: MonadIO m => Text -> Car m CommandResponse
share :: forall (m :: * -> *). MonadIO m => Text -> Car m CommandResponse
share Text
to = do
Int
now <- forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
forall (m :: * -> *).
MonadIO m =>
String -> [Pair] -> Car m CommandResponse
runCmd String
"share" [
Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Text
"share_ext_content_raw" :: Text),
Key
"value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
object [ Key
"android.intent.extra.TEXT" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
to ],
Key
"locale" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Text
"en-US" :: Text),
Key
"timestamp_ms" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Int
now forall a. Num a => a -> a -> a
* (Int
1000::Int))
]