{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module JSDOM.Generated.XMLHttpRequest
(newXMLHttpRequest, openSimple, open, setRequestHeader, send,
abort, getResponseHeader, getResponseHeader_,
getResponseHeaderUnsafe, getResponseHeaderUnchecked,
getAllResponseHeaders, getAllResponseHeaders_, overrideMimeType,
pattern UNSENT, pattern OPENED, pattern HEADERS_RECEIVED,
pattern LOADING, pattern DONE, readyStateChange, getReadyState,
setTimeout, getTimeout, setWithCredentials, getWithCredentials,
getUpload, getResponseURL, getStatus, getStatusText,
setResponseType, getResponseType, getResponse, getResponseText,
getResponseTextUnsafe, getResponseTextUnchecked, getResponseXML,
getResponseXMLUnsafe, getResponseXMLUnchecked, XMLHttpRequest(..),
gTypeXMLHttpRequest)
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
newXMLHttpRequest :: (MonadDOM m) => m XMLHttpRequest
newXMLHttpRequest
= liftDOM (XMLHttpRequest <$> new (jsg "XMLHttpRequest") ())
openSimple ::
(MonadDOM m, ToJSString method, ToJSString url) =>
XMLHttpRequest -> method -> url -> m ()
openSimple self method url
= liftDOM (void (self ^. jsf "open" [toJSVal method, toJSVal url]))
open ::
(MonadDOM m, ToJSString method, ToJSString url, ToJSString user,
ToJSString password) =>
XMLHttpRequest ->
method -> url -> Bool -> Maybe user -> Maybe password -> m ()
open self method url async user password
= liftDOM
(void
(self ^. jsf "open"
[toJSVal method, toJSVal url, toJSVal async, toJSVal user,
toJSVal password]))
setRequestHeader ::
(MonadDOM m, ToJSString header, ToJSString value) =>
XMLHttpRequest -> header -> value -> m ()
setRequestHeader self header value
= liftDOM
(void
(self ^. jsf "setRequestHeader" [toJSVal header, toJSVal value]))
send ::
(MonadDOM m, IsXMLHttpRequestBody body) =>
XMLHttpRequest -> Maybe body -> m ()
send self body = liftDOM (void (self ^. jsf "send" [toJSVal body]))
abort :: (MonadDOM m) => XMLHttpRequest -> m ()
abort self = liftDOM (void (self ^. jsf "abort" ()))
getResponseHeader ::
(MonadDOM m, ToJSString name, FromJSString result) =>
XMLHttpRequest -> name -> m (Maybe result)
getResponseHeader self name
= liftDOM
((self ^. jsf "getResponseHeader" [toJSVal name]) >>=
fromMaybeJSString)
getResponseHeader_ ::
(MonadDOM m, ToJSString name) => XMLHttpRequest -> name -> m ()
getResponseHeader_ self name
= liftDOM (void (self ^. jsf "getResponseHeader" [toJSVal name]))
getResponseHeaderUnsafe ::
(MonadDOM m, ToJSString name, HasCallStack, FromJSString result) =>
XMLHttpRequest -> name -> m result
getResponseHeaderUnsafe self name
= liftDOM
(((self ^. jsf "getResponseHeader" [toJSVal name]) >>=
fromMaybeJSString)
>>= maybe (Prelude.error "Nothing to return") return)
getResponseHeaderUnchecked ::
(MonadDOM m, ToJSString name, FromJSString result) =>
XMLHttpRequest -> name -> m result
getResponseHeaderUnchecked self name
= liftDOM
((self ^. jsf "getResponseHeader" [toJSVal name]) >>=
fromJSValUnchecked)
getAllResponseHeaders ::
(MonadDOM m, FromJSString result) => XMLHttpRequest -> m result
getAllResponseHeaders self
= liftDOM
((self ^. jsf "getAllResponseHeaders" ()) >>= fromJSValUnchecked)
getAllResponseHeaders_ :: (MonadDOM m) => XMLHttpRequest -> m ()
getAllResponseHeaders_ self
= liftDOM (void (self ^. jsf "getAllResponseHeaders" ()))
overrideMimeType ::
(MonadDOM m, ToJSString mime) => XMLHttpRequest -> mime -> m ()
overrideMimeType self mime
= liftDOM (void (self ^. jsf "overrideMimeType" [toJSVal mime]))
pattern UNSENT = 0
pattern OPENED = 1
pattern HEADERS_RECEIVED = 2
pattern LOADING = 3
pattern DONE = 4
readyStateChange :: EventName XMLHttpRequest Event
readyStateChange
= unsafeEventNameAsync (toJSString "readystatechange")
getReadyState :: (MonadDOM m) => XMLHttpRequest -> m Word
getReadyState self
= liftDOM (round <$> ((self ^. js "readyState") >>= valToNumber))
setTimeout :: (MonadDOM m) => XMLHttpRequest -> Word -> m ()
setTimeout self val = liftDOM (self ^. jss "timeout" (toJSVal val))
getTimeout :: (MonadDOM m) => XMLHttpRequest -> m Word
getTimeout self
= liftDOM (round <$> ((self ^. js "timeout") >>= valToNumber))
setWithCredentials ::
(MonadDOM m) => XMLHttpRequest -> Bool -> m ()
setWithCredentials self val
= liftDOM (self ^. jss "withCredentials" (toJSVal val))
getWithCredentials :: (MonadDOM m) => XMLHttpRequest -> m Bool
getWithCredentials self
= liftDOM ((self ^. js "withCredentials") >>= valToBool)
getUpload ::
(MonadDOM m) => XMLHttpRequest -> m XMLHttpRequestUpload
getUpload self
= liftDOM ((self ^. js "upload") >>= fromJSValUnchecked)
getResponseURL ::
(MonadDOM m, FromJSString result) => XMLHttpRequest -> m result
getResponseURL self
= liftDOM ((self ^. js "responseURL") >>= fromJSValUnchecked)
getStatus :: (MonadDOM m) => XMLHttpRequest -> m Word
getStatus self
= liftDOM (round <$> ((self ^. js "status") >>= valToNumber))
getStatusText ::
(MonadDOM m, FromJSString result) => XMLHttpRequest -> m result
getStatusText self
= liftDOM ((self ^. js "statusText") >>= fromJSValUnchecked)
setResponseType ::
(MonadDOM m) =>
XMLHttpRequest -> XMLHttpRequestResponseType -> m ()
setResponseType self val
= liftDOM (self ^. jss "responseType" (toJSVal val))
getResponseType ::
(MonadDOM m) => XMLHttpRequest -> m XMLHttpRequestResponseType
getResponseType self
= liftDOM ((self ^. js "responseType") >>= fromJSValUnchecked)
getResponse :: (MonadDOM m) => XMLHttpRequest -> m JSVal
getResponse self = liftDOM ((self ^. js "response") >>= toJSVal)
getResponseText ::
(MonadDOM m, FromJSString result) =>
XMLHttpRequest -> m (Maybe result)
getResponseText self
= liftDOM ((self ^. js "responseText") >>= fromMaybeJSString)
getResponseTextUnsafe ::
(MonadDOM m, HasCallStack, FromJSString result) =>
XMLHttpRequest -> m result
getResponseTextUnsafe self
= liftDOM
(((self ^. js "responseText") >>= fromMaybeJSString) >>=
maybe (Prelude.error "Nothing to return") return)
getResponseTextUnchecked ::
(MonadDOM m, FromJSString result) => XMLHttpRequest -> m result
getResponseTextUnchecked self
= liftDOM ((self ^. js "responseText") >>= fromJSValUnchecked)
getResponseXML ::
(MonadDOM m) => XMLHttpRequest -> m (Maybe Document)
getResponseXML self
= liftDOM ((self ^. js "responseXML") >>= fromJSVal)
getResponseXMLUnsafe ::
(MonadDOM m, HasCallStack) => XMLHttpRequest -> m Document
getResponseXMLUnsafe self
= liftDOM
(((self ^. js "responseXML") >>= fromJSVal) >>=
maybe (Prelude.error "Nothing to return") return)
getResponseXMLUnchecked ::
(MonadDOM m) => XMLHttpRequest -> m Document
getResponseXMLUnchecked self
= liftDOM ((self ^. js "responseXML") >>= fromJSValUnchecked)