module API.GundeckInternal where

import Testlib.Prelude

postPush ::
  ( HasCallStack,
    MakesValue user,
    MakesValue a
  ) =>
  user ->
  [a] ->
  App Response
postPush :: forall user a.
(HasCallStack, MakesValue user, MakesValue a) =>
user -> [a] -> App Response
postPush user
user [a]
payloads = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
user Service
Gundeck Versioned
Unversioned String
"/i/push/v2"
  [Value]
body <- (a -> App Value) -> [a] -> App [Value]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse a -> App Value
forall a. (MakesValue a, HasCallStack) => a -> App Value
make [a]
payloads
  String -> Request -> App Response
submit String
"POST" (Request -> App Response) -> Request -> App Response
forall a b. (a -> b) -> a -> b
$ Request
req Request -> (Request -> Request) -> Request
forall a b. a -> (a -> b) -> b
& [Value] -> Request -> Request
forall a. ToJSON a => a -> Request -> Request
addJSON [Value]
body

getPresence ::
  (HasCallStack, MakesValue user) =>
  user ->
  App Response
getPresence :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
getPresence user
u = do
  String
uid <- user
u user -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id" App Value -> (App Value -> App String) -> App String
forall a b. a -> (a -> b) -> b
& App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString
  Request
req <-
    user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
u Service
Gundeck Versioned
Unversioned
      (String -> App Request) -> String -> App Request
forall a b. (a -> b) -> a -> b
$ String
"/i/presences/"
      String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
uid
  String -> Request -> App Response
submit String
"GET" Request
req

unregisterUser ::
  (HasCallStack, MakesValue user) =>
  user ->
  App Response
unregisterUser :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
unregisterUser user
u = do
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
u Service
Gundeck Versioned
Unversioned String
"/i/user/"
  String -> Request -> App Response
submit String
"DELETE" Request
req

getPushTokens ::
  (HasCallStack, MakesValue user) =>
  user ->
  App Response
getPushTokens :: forall user.
(HasCallStack, MakesValue user) =>
user -> App Response
getPushTokens user
u = do
  String
uid <- user
u user -> String -> App Value
forall a. (HasCallStack, MakesValue a) => a -> String -> App Value
%. String
"id" App Value -> (App Value -> App String) -> App String
forall a b. a -> (a -> b) -> b
& App Value -> App String
forall a. (HasCallStack, MakesValue a) => a -> App String
asString
  Request
req <- user -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest user
u Service
Gundeck Versioned
Unversioned (String
"/i/push-tokens/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
uid)
  String -> Request -> App Response
submit String
"GET" Request
req