{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module JSDOM.Generated.Response
(error, error_, redirect, redirect_, arrayBuffer, arrayBuffer_,
blob, blob_, formData, formData_, json, json_, text, text_, clone,
clone_, getType, getUrl, getRedirected, getStatus, getOk,
getStatusText, getHeaders, getBody, getBodyUnsafe,
getBodyUnchecked, getBodyUsed, Response(..), gTypeResponse)
where
import Prelude ((.), (==), (>>=), return, IO, Int, Float, Double, Bool(..), Maybe, maybe, fromIntegral, round, realToFrac, fmap, Show, Read, Eq, Ord, Maybe(..))
import qualified Prelude (error)
import Data.Typeable (Typeable)
import Data.Traversable (mapM)
import Language.Javascript.JSaddle (JSM(..), JSVal(..), JSString, strictEqual, toJSVal, valToStr, valToNumber, valToBool, js, jss, jsf, jsg, function, asyncFunction, new, array, jsUndefined, (!), (!!))
import Data.Int (Int64)
import Data.Word (Word, Word64)
import JSDOM.Types
import Control.Applicative ((<$>))
import Control.Monad (void)
import Control.Lens.Operators ((^.))
import JSDOM.EventTargetClosures (EventName, unsafeEventName, unsafeEventNameAsync)
import JSDOM.Enums
error :: (MonadDOM m) => m Response
error
= liftDOM
(((jsg "Response") ^. jsf "error" ()) >>= fromJSValUnchecked)
error_ :: (MonadDOM m) => m ()
error_ = liftDOM (void ((jsg "Response") ^. jsf "error" ()))
redirect ::
(MonadDOM m, ToJSString url) => url -> Maybe Word -> m Response
redirect url status
= liftDOM
(((jsg "Response") ^. jsf "redirect" [toJSVal url, toJSVal status])
>>= fromJSValUnchecked)
redirect_ ::
(MonadDOM m, ToJSString url) => url -> Maybe Word -> m ()
redirect_ url status
= liftDOM
(void
((jsg "Response") ^. jsf "redirect" [toJSVal url, toJSVal status]))
arrayBuffer :: (MonadDOM m) => Response -> m ArrayBuffer
arrayBuffer self
= liftDOM
(((self ^. jsf "arrayBuffer" ()) >>= readPromise) >>=
fromJSValUnchecked)
arrayBuffer_ :: (MonadDOM m) => Response -> m ()
arrayBuffer_ self = liftDOM (void (self ^. jsf "arrayBuffer" ()))
blob :: (MonadDOM m) => Response -> m Blob
blob self
= liftDOM
(((self ^. jsf "blob" ()) >>= readPromise) >>= fromJSValUnchecked)
blob_ :: (MonadDOM m) => Response -> m ()
blob_ self = liftDOM (void (self ^. jsf "blob" ()))
formData :: (MonadDOM m) => Response -> m Blob
formData self
= liftDOM
(((self ^. jsf "formData" ()) >>= readPromise) >>=
fromJSValUnchecked)
formData_ :: (MonadDOM m) => Response -> m ()
formData_ self = liftDOM (void (self ^. jsf "formData" ()))
json :: (MonadDOM m) => Response -> m JSVal
json self
= liftDOM (((self ^. jsf "json" ()) >>= readPromise) >>= toJSVal)
json_ :: (MonadDOM m) => Response -> m ()
json_ self = liftDOM (void (self ^. jsf "json" ()))
text :: (MonadDOM m, FromJSString result) => Response -> m result
text self
= liftDOM
(((self ^. jsf "text" ()) >>= readPromise) >>= fromJSValUnchecked)
text_ :: (MonadDOM m) => Response -> m ()
text_ self = liftDOM (void (self ^. jsf "text" ()))
clone :: (MonadDOM m) => Response -> m Response
clone self
= liftDOM ((self ^. jsf "clone" ()) >>= fromJSValUnchecked)
clone_ :: (MonadDOM m) => Response -> m ()
clone_ self = liftDOM (void (self ^. jsf "clone" ()))
getType :: (MonadDOM m) => Response -> m ResponseType
getType self = liftDOM ((self ^. js "type") >>= fromJSValUnchecked)
getUrl :: (MonadDOM m, FromJSString result) => Response -> m result
getUrl self = liftDOM ((self ^. js "url") >>= fromJSValUnchecked)
getRedirected :: (MonadDOM m) => Response -> m Bool
getRedirected self
= liftDOM ((self ^. js "redirected") >>= valToBool)
getStatus :: (MonadDOM m) => Response -> m Word
getStatus self
= liftDOM (round <$> ((self ^. js "status") >>= valToNumber))
getOk :: (MonadDOM m) => Response -> m Bool
getOk self = liftDOM ((self ^. js "ok") >>= valToBool)
getStatusText ::
(MonadDOM m, FromJSString result) => Response -> m result
getStatusText self
= liftDOM ((self ^. js "statusText") >>= fromJSValUnchecked)
getHeaders :: (MonadDOM m) => Response -> m Headers
getHeaders self
= liftDOM ((self ^. js "headers") >>= fromJSValUnchecked)
getBody :: (MonadDOM m) => Response -> m (Maybe ReadableStream)
getBody self = liftDOM ((self ^. js "body") >>= fromJSVal)
getBodyUnsafe ::
(MonadDOM m, HasCallStack) => Response -> m ReadableStream
getBodyUnsafe self
= liftDOM
(((self ^. js "body") >>= fromJSVal) >>=
maybe (Prelude.error "Nothing to return") return)
getBodyUnchecked :: (MonadDOM m) => Response -> m ReadableStream
getBodyUnchecked self
= liftDOM ((self ^. js "body") >>= fromJSValUnchecked)
getBodyUsed :: (MonadDOM m) => Response -> m Bool
getBodyUsed self = liftDOM ((self ^. js "bodyUsed") >>= valToBool)