module Effectful.Wreq.Session
  (
  -- * Session creation
  Session
  , newSession
  , newAPISession

  -- ** More control-oriented session creation
  , newSessionControl

  -- * Get information about session state
  , getSessionCookieJar

  -- * HTTP verbs
  , get
  , post
  , head_
  , options
  , put
  , delete
  , customMethod

  -- * Configurable verbs
  , getWith
  , postWith
  , headWith
  , optionsWith
  , putWith
  , deleteWith
  , customMethodWith
  , customPayloadMethodWith
  , customHistoriedMethodWith
  , customHistoriedPayloadMethodWith
  )
    where

import Data.ByteString.Lazy                 (ByteString)
import Effectful
import Effectful.Dispatch.Static
import Effectful.Wreq                       (Wreq)
import Network.HTTP.Client
import Network.Wreq.Session                 (Session)
import Network.Wreq.Session qualified as S
import           Network.Wreq.Types

-- | Lifted `S.newSession`
newSession :: Wreq :> es => Eff es Session
newSession :: forall (es :: [Effect]). (Wreq :> es) => Eff es Session
newSession = IO Session -> Eff es Session
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ IO Session
S.newSession

-- | Lifted `S.newAPISession`
newAPISession :: Wreq :> es => Eff es Session
newAPISession :: forall (es :: [Effect]). (Wreq :> es) => Eff es Session
newAPISession = IO Session -> Eff es Session
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ IO Session
S.newAPISession

-- | Lifted `S.newSessionControl`
newSessionControl :: Wreq :> es => Maybe CookieJar -> ManagerSettings -> Eff es Session
newSessionControl :: forall (es :: [Effect]).
(Wreq :> es) =>
Maybe CookieJar -> ManagerSettings -> Eff es Session
newSessionControl Maybe CookieJar
cj = IO Session -> Eff es Session
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Session -> Eff es Session)
-> (ManagerSettings -> IO Session)
-> ManagerSettings
-> Eff es Session
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe CookieJar -> ManagerSettings -> IO Session
S.newSessionControl Maybe CookieJar
cj

-- | Lifted `S.getSessionCookieJar`
getSessionCookieJar :: Wreq :> es => Session -> Eff es (Maybe CookieJar)
getSessionCookieJar :: forall (es :: [Effect]).
(Wreq :> es) =>
Session -> Eff es (Maybe CookieJar)
getSessionCookieJar = IO (Maybe CookieJar) -> Eff es (Maybe CookieJar)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Maybe CookieJar) -> Eff es (Maybe CookieJar))
-> (Session -> IO (Maybe CookieJar))
-> Session
-> Eff es (Maybe CookieJar)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session -> IO (Maybe CookieJar)
S.getSessionCookieJar

-- | Lifted `S.get`
get :: Wreq :> es => Session -> String -> Eff es (Response ByteString)
get :: forall (es :: [Effect]).
(Wreq :> es) =>
Session -> String -> Eff es (Response ByteString)
get Session
session = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (String -> IO (Response ByteString))
-> String
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session -> String -> IO (Response ByteString)
S.get Session
session

-- | Lifted `S.post`
post :: (Wreq :> es, Postable a) => Session -> String -> a -> Eff es (Response ByteString)
post :: forall (es :: [Effect]) a.
(Wreq :> es, Postable a) =>
Session -> String -> a -> Eff es (Response ByteString)
post Session
session String
url = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (a -> IO (Response ByteString))
-> a
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session -> String -> a -> IO (Response ByteString)
forall a.
Postable a =>
Session -> String -> a -> IO (Response ByteString)
S.post Session
session String
url

-- | Lifted `S.head_`
head_ :: Wreq :> es => Session -> String -> Eff es (Response ())
head_ :: forall (es :: [Effect]).
(Wreq :> es) =>
Session -> String -> Eff es (Response ())
head_ Session
session = IO (Response ()) -> Eff es (Response ())
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ()) -> Eff es (Response ()))
-> (String -> IO (Response ())) -> String -> Eff es (Response ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session -> String -> IO (Response ())
S.head_ Session
session

-- | Lifted `S.options`
options :: Wreq :> es => Session -> String -> Eff es (Response ())
options :: forall (es :: [Effect]).
(Wreq :> es) =>
Session -> String -> Eff es (Response ())
options Session
session = IO (Response ()) -> Eff es (Response ())
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ()) -> Eff es (Response ()))
-> (String -> IO (Response ())) -> String -> Eff es (Response ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session -> String -> IO (Response ())
S.options Session
session

-- | Lifted `S.put`
put :: (Wreq :> es, Putable a) => Session -> String -> a -> Eff es (Response ByteString)
put :: forall (es :: [Effect]) a.
(Wreq :> es, Putable a) =>
Session -> String -> a -> Eff es (Response ByteString)
put Session
session String
url = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (a -> IO (Response ByteString))
-> a
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session -> String -> a -> IO (Response ByteString)
forall a.
Putable a =>
Session -> String -> a -> IO (Response ByteString)
S.put Session
session String
url

-- | Lifted `S.delete`
delete :: Wreq :> es => Session -> String -> Eff es (Response ByteString)
delete :: forall (es :: [Effect]).
(Wreq :> es) =>
Session -> String -> Eff es (Response ByteString)
delete Session
session = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (String -> IO (Response ByteString))
-> String
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session -> String -> IO (Response ByteString)
S.delete Session
session

-- | Lifted `S.customMethod`
customMethod :: Wreq :> es => String -> Session -> String -> Eff es (Response ByteString)
customMethod :: forall (es :: [Effect]).
(Wreq :> es) =>
String -> Session -> String -> Eff es (Response ByteString)
customMethod String
method Session
session = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (String -> IO (Response ByteString))
-> String
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Session -> String -> IO (Response ByteString)
S.customMethod String
method Session
session

-- | Lifted `S.getWith`
getWith :: Wreq :> es => Options -> Session -> String -> Eff es (Response ByteString)
getWith :: forall (es :: [Effect]).
(Wreq :> es) =>
Options -> Session -> String -> Eff es (Response ByteString)
getWith Options
opts Session
session = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (String -> IO (Response ByteString))
-> String
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Options -> Session -> String -> IO (Response ByteString)
S.getWith Options
opts Session
session

-- | Lifted `S.postWith`
postWith :: (Wreq :> es, Postable a) => Options -> Session -> String -> a -> Eff es (Response ByteString)
postWith :: forall (es :: [Effect]) a.
(Wreq :> es, Postable a) =>
Options -> Session -> String -> a -> Eff es (Response ByteString)
postWith Options
opts Session
session String
url = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (a -> IO (Response ByteString))
-> a
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Options -> Session -> String -> a -> IO (Response ByteString)
forall a.
Postable a =>
Options -> Session -> String -> a -> IO (Response ByteString)
S.postWith Options
opts Session
session String
url

-- | Lifted `S.headWith`
headWith :: Wreq :> es => Options -> Session -> String -> Eff es (Response ())
headWith :: forall (es :: [Effect]).
(Wreq :> es) =>
Options -> Session -> String -> Eff es (Response ())
headWith Options
opts Session
session = IO (Response ()) -> Eff es (Response ())
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ()) -> Eff es (Response ()))
-> (String -> IO (Response ())) -> String -> Eff es (Response ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Options -> Session -> String -> IO (Response ())
S.headWith Options
opts Session
session

-- | Lifted `S.optionsWith`
optionsWith :: Wreq :> es => Options -> Session -> String -> Eff es (Response ())
optionsWith :: forall (es :: [Effect]).
(Wreq :> es) =>
Options -> Session -> String -> Eff es (Response ())
optionsWith Options
opts Session
session = IO (Response ()) -> Eff es (Response ())
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ()) -> Eff es (Response ()))
-> (String -> IO (Response ())) -> String -> Eff es (Response ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Options -> Session -> String -> IO (Response ())
S.optionsWith Options
opts Session
session

-- | Lifted `S.putWith`
putWith :: (Wreq :> es, Putable a) => Options -> Session -> String -> a -> Eff es (Response ByteString)
putWith :: forall (es :: [Effect]) a.
(Wreq :> es, Putable a) =>
Options -> Session -> String -> a -> Eff es (Response ByteString)
putWith Options
opts Session
session String
url = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (a -> IO (Response ByteString))
-> a
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Options -> Session -> String -> a -> IO (Response ByteString)
forall a.
Putable a =>
Options -> Session -> String -> a -> IO (Response ByteString)
S.putWith Options
opts Session
session String
url

-- | Lifted `S.deleteWith`
deleteWith :: Wreq :> es => Options -> Session -> String -> Eff es (Response ByteString)
deleteWith :: forall (es :: [Effect]).
(Wreq :> es) =>
Options -> Session -> String -> Eff es (Response ByteString)
deleteWith Options
opts Session
session = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (String -> IO (Response ByteString))
-> String
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Options -> Session -> String -> IO (Response ByteString)
S.deleteWith Options
opts Session
session

-- | Lifted `S.customMethodWith`
customMethodWith :: Wreq :> es => String -> Options -> Session -> String -> Eff es (Response ByteString)
customMethodWith :: forall (es :: [Effect]).
(Wreq :> es) =>
String
-> Options -> Session -> String -> Eff es (Response ByteString)
customMethodWith String
method Options
opts Session
session = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (String -> IO (Response ByteString))
-> String
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Options -> Session -> String -> IO (Response ByteString)
S.customMethodWith String
method Options
opts Session
session

-- | Lifted `S.customPayloadMethodWith`
customPayloadMethodWith :: (Wreq :> es, Postable a) => String -> Options -> Session -> String -> a -> Eff es (Response ByteString)
customPayloadMethodWith :: forall (es :: [Effect]) a.
(Wreq :> es, Postable a) =>
String
-> Options
-> Session
-> String
-> a
-> Eff es (Response ByteString)
customPayloadMethodWith String
method Options
opts Session
session String
url = IO (Response ByteString) -> Eff es (Response ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (Response ByteString) -> Eff es (Response ByteString))
-> (a -> IO (Response ByteString))
-> a
-> Eff es (Response ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> Options -> Session -> String -> a -> IO (Response ByteString)
forall a.
Postable a =>
String
-> Options -> Session -> String -> a -> IO (Response ByteString)
S.customPayloadMethodWith String
method Options
opts Session
session String
url

-- | Lifted `S.customHistoriedMethodWith`
customHistoriedMethodWith :: Wreq :> es => String -> Options -> Session -> String -> Eff es (HistoriedResponse ByteString)
customHistoriedMethodWith :: forall (es :: [Effect]).
(Wreq :> es) =>
String
-> Options
-> Session
-> String
-> Eff es (HistoriedResponse ByteString)
customHistoriedMethodWith String
method Options
opts Session
session = IO (HistoriedResponse ByteString)
-> Eff es (HistoriedResponse ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (HistoriedResponse ByteString)
 -> Eff es (HistoriedResponse ByteString))
-> (String -> IO (HistoriedResponse ByteString))
-> String
-> Eff es (HistoriedResponse ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> Options
-> Session
-> String
-> IO (HistoriedResponse ByteString)
S.customHistoriedMethodWith String
method Options
opts Session
session

-- | Lifted `S.customHistoriedPayloadMethodWith`
customHistoriedPayloadMethodWith :: (Wreq :> es, Postable a) => String -> Options -> Session -> String -> a -> Eff es (HistoriedResponse ByteString)
customHistoriedPayloadMethodWith :: forall (es :: [Effect]) a.
(Wreq :> es, Postable a) =>
String
-> Options
-> Session
-> String
-> a
-> Eff es (HistoriedResponse ByteString)
customHistoriedPayloadMethodWith String
method Options
opts Session
session String
url = IO (HistoriedResponse ByteString)
-> Eff es (HistoriedResponse ByteString)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (HistoriedResponse ByteString)
 -> Eff es (HistoriedResponse ByteString))
-> (a -> IO (HistoriedResponse ByteString))
-> a
-> Eff es (HistoriedResponse ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> Options
-> Session
-> String
-> a
-> IO (HistoriedResponse ByteString)
forall a.
Postable a =>
String
-> Options
-> Session
-> String
-> a
-> IO (HistoriedResponse ByteString)
S.customHistoriedPayloadMethodWith String
method Options
opts Session
session String
url