import { DefaultRESTRequestOptions , RESTRequestOptions , RESTResponseDataType } from "../../../interfaces/RESTInterfaces" ; import RESTController from "../RESTController" ; import prepare from "./prepare" ; import RESTResponse from "../response" ; import { utilMergeDeep } from "../../../util/utilFunctions" ; class RESTRequest { public controller : RESTController ; /**
     * The options that will be used for sending the request
     */ public requestOptions : RESTRequestOptions ; /**
     * The amount of times this request has been executed
     */ public attempts : number ; constructor ( controller , options ) { this . controller = controller ; this . requestOptions = options ; this . attempts = 0 ; } setOptions ( options ) { this . requestOptions = utilMergeDeep ( JSON . parse ( JSON . stringify ( DefaultRESTRequestOptions ) ) , options || { } ) as RESTRequestOptions ; return this . requestOptions ; } async send ( options ? ) { await prepare ( this , options || this . requestOptions ) ; await Promise . all ( this . controller . requestHandlers . map ( handler => handler ( this ) ) ) ; const responseData = await this . controller . requester ( this . requestOptions ) ; this . attempts ++ ; const response = new RESTResponse ( this . controller , this , responseData ) ; return response . process ( ) ; } } export default RESTRequest ;