API reference

VRequest Class

Class for performing web requests using UnityWebRequest

Constructors

VRequest ( onDownloadProgress , onFirstResponse )
A constructor that takes in download progress delegate & first response delegate
Signature
Meta.WitAi.Requests.VRequest.VRequest(RequestProgressDelegate onDownloadProgress=null, RequestFirstResponseDelegate onFirstResponse=null)
Parameters
onDownloadProgress: RequestProgressDelegate  The callback for progress related to downloading
onFirstResponse: RequestFirstResponseDelegate  The callback for the first response of data from a request

Protected Fields

payload : string
The data for PUT and POST requests. This will usually be set by child classes that have unencoded payloads.
Signature
string Meta.WitAi.Requests.VRequest.payload
uri : Uri
The URI of the current/last request.
Signature
Uri Meta.WitAi.Requests.VRequest.uri

Static Fields

MaxConcurrentRequests : int
Will only start new requests if there are less than this number If <= 0, then all requests will run immediately
Signature
int Meta.WitAi.Requests.VRequest.MaxConcurrentRequests

Properties

DownloadProgress : float
[Get]
Current progress for download
Signature
float Meta.WitAi.Requests.VRequest.DownloadProgress
HasFirstResponse : bool
[Get]
If first response has been received
Signature
bool Meta.WitAi.Requests.VRequest.HasFirstResponse
IsComplete : bool
[Get]
Whether or not the completion delegate has been called
Signature
bool Meta.WitAi.Requests.VRequest.IsComplete
IsPerforming : bool
[Get]
If request is currently being performed
Signature
bool Meta.WitAi.Requests.VRequest.IsPerforming
IsStreamReady : bool
[Get]
If the download handler incorporates IVRequestStreamable & IsStreamReady
Signature
bool Meta.WitAi.Requests.VRequest.IsStreamReady
ResponseCode : int
[Get][Set]
Response Code if applicable
Signature
int Meta.WitAi.Requests.VRequest.ResponseCode
ResponseError : string
[Get]
Response error
Signature
string Meta.WitAi.Requests.VRequest.ResponseError
Timeout : int
[Get][Set]
Timeout in seconds
Signature
int Meta.WitAi.Requests.VRequest.Timeout
UploadProgress : float
[Get]
Current progress for get requests
Signature
float Meta.WitAi.Requests.VRequest.UploadProgress

Protected Methods

Begin ()
Signature
virtual void Meta.WitAi.Requests.VRequest.Begin()
Returns
void
GetHeaders ()
Signature
virtual Dictionary<string, string> Meta.WitAi.Requests.VRequest.GetHeaders()
Returns
Dictionary< string, string >
IsRequestComplete ()
Signature
virtual bool Meta.WitAi.Requests.VRequest.IsRequestComplete()
Returns
bool
Setup ( unityRequest )
Signature
virtual void Meta.WitAi.Requests.VRequest.Setup(UnityWebRequest unityRequest)
Parameters
unityRequest: UnityWebRequest
Returns
void
Unload ()
Signature
virtual void Meta.WitAi.Requests.VRequest.Unload()
Returns
void
Update ()
Signature
virtual void Meta.WitAi.Requests.VRequest.Update()
Returns
void

Methods

Cancel ()
Signature
virtual void Meta.WitAi.Requests.VRequest.Cancel()
Returns
void
CleanUrl ( url )
Adds 'file://' to url if no prefix is found
Signature
virtual string Meta.WitAi.Requests.VRequest.CleanUrl(string url)
Parameters
url: string
Returns
string
GetAudioDecoder ( audioType , includeJson , onJsonDecoded )
Instantiate an audio decoder based on the audio type to allow for complex streaming scenarios
Signature
virtual IAudioDecoder Meta.WitAi.Requests.VRequest.GetAudioDecoder(AudioType audioType, bool includeJson=false, AudioJsonDecodeDelegate onJsonDecoded=null)
Parameters
audioType: AudioType Audio decoder type allowed
includeJson: bool  Whether or not json will be returned within the stream
onJsonDecoded: AudioJsonDecodeDelegate  The json decode callback which will be called multiple times
Request ( unityRequest , onComplete )
Initialize with a request and an on completion callback
Signature
virtual bool Meta.WitAi.Requests.VRequest.Request(UnityWebRequest unityRequest, RequestCompleteDelegate< UnityWebRequest > onComplete)
Parameters
unityRequest: UnityWebRequest  The unity request to be performed
onComplete: RequestCompleteDelegate< UnityWebRequest >  The callback on completion, returns the request & error string
Returns
bool  False if the request cannot be performed
RequestAsync< TData > ( unityRequest , onDecode )
Initialize with a request and an on completion callback
Signature
virtual async Task<RequestCompleteResponse<TData> > Meta.WitAi.Requests.VRequest.RequestAsync< TData >(UnityWebRequest unityRequest, Func< UnityWebRequest, TData > onDecode)
Parameters
unityRequest: UnityWebRequest  The unity request to be performed
onDecode: Func< UnityWebRequest, TData >  A function to be performed to async decode all request data
Returns
async Task< RequestCompleteResponse< TData > >  Any errors encountered during the request
RequestAudioStream ( uri , audioType , includesJson , onSamplesDecoded , onJsonDecoded , onComplete )
Request audio clip with uri, audio type, sample decoded delegate & completion delegate
Signature
bool Meta.WitAi.Requests.VRequest.RequestAudioStream(Uri uri, AudioType audioType, bool includesJson, AudioSampleDecodeDelegate onSamplesDecoded, AudioJsonDecodeDelegate onJsonDecoded, RequestCompleteDelegate< bool > onComplete)
Parameters
uri: Uri  The url to be called
audioType: AudioType  The audio type requested (Wav, MP3, etc.)
includesJson: bool  Whether or not json will be embedded within the audio stream.
onSamplesDecoded: AudioSampleDecodeDelegate  Called one or more times as audio samples are decoded.
onJsonDecoded: AudioJsonDecodeDelegate  Called one or more times as json data is decoded.
onComplete: RequestCompleteDelegate< bool >  Called when the audio request has completed
Returns
bool
RequestAudioStream ( unityRequest , audioType , includesJson , onSamplesDecoded , onJsonDecoded , onComplete )
Request audio clip with web request, audio type, whether audio includes json data, callback delegates & completion delegate
Signature
bool Meta.WitAi.Requests.VRequest.RequestAudioStream(UnityWebRequest unityRequest, AudioType audioType, bool includesJson, AudioSampleDecodeDelegate onSamplesDecoded, AudioJsonDecodeDelegate onJsonDecoded, RequestCompleteDelegate< bool > onComplete)
Parameters
unityRequest: UnityWebRequest  The unity request to add a download handler to
audioType: AudioType  The audio type requested (Wav, MP3, etc.)
includesJson: bool  Whether or not json will be embedded within the audio stream.
onSamplesDecoded: AudioSampleDecodeDelegate  Called one or more times as audio samples are decoded.
onJsonDecoded: AudioJsonDecodeDelegate  Called one or more times as json data is decoded.
onComplete: RequestCompleteDelegate< bool >  Called when the audio request has completed
Returns
bool
RequestCompleteDelegate< TResult > ( result , error )
Signature
delegate void Meta.WitAi.Requests.VRequest.RequestCompleteDelegate< TResult >(TResult result, string error)
Parameters
result: TResult
error: string
Returns
delegate void
RequestFile ( uri , onComplete )
Performs a simple http header request
Signature
bool Meta.WitAi.Requests.VRequest.RequestFile(Uri uri, RequestCompleteDelegate< byte[]> onComplete)
Parameters
uri: Uri  Uri to get a file
onComplete: RequestCompleteDelegate< byte[]>  Called once file data has been loaded
Returns
bool  False if cannot begin request
RequestFileAsync ( uri )
Performs a simple http header request
Signature
async Task<RequestCompleteResponse<byte[]> > Meta.WitAi.Requests.VRequest.RequestFileAsync(Uri uri)
Parameters
uri: Uri  Uri to get a file
Returns
async Task< RequestCompleteResponse< byte[]> >  False if cannot begin request
RequestFileDownload ( downloadPath , unityRequest , onComplete )
Download a file using a unityrequest
Signature
bool Meta.WitAi.Requests.VRequest.RequestFileDownload(string downloadPath, UnityWebRequest unityRequest, RequestCompleteDelegate< bool > onComplete)
Parameters
downloadPath: string
unityRequest: UnityWebRequest  The unity request to add a download handler to
onComplete: RequestCompleteDelegate< bool >  Called once download has completed
Returns
bool
RequestFileDownloadAsync ( downloadPath , unityRequest )
Download a file using a unityrequest
Signature
async Task<string> Meta.WitAi.Requests.VRequest.RequestFileDownloadAsync(string downloadPath, UnityWebRequest unityRequest)
Parameters
downloadPath: string
unityRequest: UnityWebRequest  The unity request to add a download handler to
Returns
async Task< string >
RequestFileExists ( checkPath , onComplete )
Uses async method to check if file exists & return via the oncomplete method
Signature
bool Meta.WitAi.Requests.VRequest.RequestFileExists(string checkPath, RequestCompleteDelegate< bool > onComplete)
Parameters
checkPath: string  The local file path to be checked
onComplete: RequestCompleteDelegate< bool >
Returns
bool
RequestFileExistsAsync ( checkPath )
Checks if a file exists at a specified location using async calls
Signature
async Task<RequestCompleteResponse<bool> > Meta.WitAi.Requests.VRequest.RequestFileExistsAsync(string checkPath)
Parameters
checkPath: string  The local file path to be checked
Returns
async Task< RequestCompleteResponse< bool > >  An error if found
RequestFileHeaders ( uri , onComplete )
Performs a header request on a uri
Signature
bool Meta.WitAi.Requests.VRequest.RequestFileHeaders(Uri uri, RequestCompleteDelegate< Dictionary< string, string >> onComplete)
Parameters
uri: Uri  The uri to perform the request on
onComplete: RequestCompleteDelegate< Dictionary< string, string >>  A completion callback that includes the headers
Returns
bool
RequestFileHeadersAsync ( uri )
Performs a header request on a uri asynchronously
Signature
async Task<RequestCompleteResponse<Dictionary<string, string> > > Meta.WitAi.Requests.VRequest.RequestFileHeadersAsync(Uri uri)
Parameters
uri: Uri  The uri to perform the request on
Returns
async Task< RequestCompleteResponse< Dictionary< string, string > > >  Returns the header
RequestFirstResponseDelegate ()
Signature
delegate void Meta.WitAi.Requests.VRequest.RequestFirstResponseDelegate()
Returns
delegate void
RequestJson< TData > ( unityRequest , onComplete , onPartial )
Performs a request for text & decodes it into json
Signature
bool Meta.WitAi.Requests.VRequest.RequestJson< TData >(UnityWebRequest unityRequest, RequestCompleteDelegate< TData > onComplete, RequestCompleteDelegate< TData > onPartial=null)
Parameters
unityRequest: UnityWebRequest  The unity request performing the post or get
onComplete: RequestCompleteDelegate< TData >  The delegate upon completion
onPartial: RequestCompleteDelegate< TData >
Returns
bool  False if the request cannot be performed
RequestJsonAsync< TData > ( unityRequest , onPartial )
Performs a request for text and decodes it into json asynchronously
Signature
async Task<RequestCompleteResponse<TData> > Meta.WitAi.Requests.VRequest.RequestJsonAsync< TData >(UnityWebRequest unityRequest, RequestCompleteDelegate< TData > onPartial=null)
Parameters
unityRequest: UnityWebRequest  The unity request performing the post or get
onPartial: RequestCompleteDelegate< TData >
Returns
async Task< RequestCompleteResponse< TData > > RequestCompleteResponse with parsed data & error if applicable
RequestJsonGet< TData > ( uri , onComplete , onPartial )
Perform a json get request with a specified uri
Signature
bool Meta.WitAi.Requests.VRequest.RequestJsonGet< TData >(Uri uri, RequestCompleteDelegate< TData > onComplete, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
onComplete: RequestCompleteDelegate< TData >  The delegate upon completion
onPartial: RequestCompleteDelegate< TData >
Returns
bool  False if the request cannot be performed
RequestJsonGetAsync< TData > ( uri , onPartial )
Perform a json get request with a specified uri asynchronously
Signature
async Task<RequestCompleteResponse<TData> > Meta.WitAi.Requests.VRequest.RequestJsonGetAsync< TData >(Uri uri, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
onPartial: RequestCompleteDelegate< TData >
Returns
async Task< RequestCompleteResponse< TData > > RequestCompleteResponse with parsed data & error if applicable
RequestJsonPost< TData > ( uri , postData , onComplete , onPartial )
Performs a json request by posting byte data
Signature
bool Meta.WitAi.Requests.VRequest.RequestJsonPost< TData >(Uri uri, byte[] postData, RequestCompleteDelegate< TData > onComplete, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
postData: byte []  The data to be uploaded
onComplete: RequestCompleteDelegate< TData >  The delegate upon completion
onPartial: RequestCompleteDelegate< TData >
Returns
bool  False if the request cannot be performed
RequestJsonPost< TData > ( uri , postText , onComplete , onPartial )
Performs a json request by posting a string
Signature
bool Meta.WitAi.Requests.VRequest.RequestJsonPost< TData >(Uri uri, string postText, RequestCompleteDelegate< TData > onComplete, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
postText: string  The string to be uploaded
onComplete: RequestCompleteDelegate< TData >  The delegate upon completion
onPartial: RequestCompleteDelegate< TData >
Returns
bool  False if the request cannot be performed
RequestJsonPostAsync< TData > ( uri , postData , onPartial )
Performs a json request by posting byte data asynchronously
Signature
async Task<RequestCompleteResponse<TData> > Meta.WitAi.Requests.VRequest.RequestJsonPostAsync< TData >(Uri uri, byte[] postData, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
postData: byte []  The data to be uploaded
onPartial: RequestCompleteDelegate< TData >
Returns
async Task< RequestCompleteResponse< TData > > RequestCompleteResponse with parsed data & error if applicable
RequestJsonPostAsync< TData > ( uri , postText , onPartial )
Performs a json request by posting a string asynchronously
Signature
async Task<RequestCompleteResponse<TData> > Meta.WitAi.Requests.VRequest.RequestJsonPostAsync< TData >(Uri uri, string postText, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
postText: string  The string to be uploaded
onPartial: RequestCompleteDelegate< TData >
Returns
async Task< RequestCompleteResponse< TData > > RequestCompleteResponse with parsed data & error if applicable
RequestJsonPut< TData > ( uri , putData , onComplete , onPartial )
Performs a json put request with byte data
Signature
bool Meta.WitAi.Requests.VRequest.RequestJsonPut< TData >(Uri uri, byte[] putData, RequestCompleteDelegate< TData > onComplete, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
putData: byte []  The data to be uploaded
onComplete: RequestCompleteDelegate< TData >  The delegate upon completion
onPartial: RequestCompleteDelegate< TData >
Returns
bool  False if the request cannot be performed
RequestJsonPut< TData > ( uri , putText , onComplete , onPartial )
Performs a json put request with text
Signature
bool Meta.WitAi.Requests.VRequest.RequestJsonPut< TData >(Uri uri, string putText, RequestCompleteDelegate< TData > onComplete, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
putText: string  The text to be uploaded
onComplete: RequestCompleteDelegate< TData >  The delegate upon completion
onPartial: RequestCompleteDelegate< TData >
Returns
bool  False if the request cannot be performed
RequestJsonPutAsync< TData > ( uri , putData , onPartial )
Performs a json put request with byte data asynchronously
Signature
async Task<RequestCompleteResponse<TData> > Meta.WitAi.Requests.VRequest.RequestJsonPutAsync< TData >(Uri uri, byte[] putData, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
putData: byte []  The data to be uploaded
onPartial: RequestCompleteDelegate< TData >
Returns
async Task< RequestCompleteResponse< TData > > RequestCompleteResponse with parsed data & error if applicable
RequestJsonPutAsync< TData > ( uri , putText , onPartial )
Performs a json put request with text asynchronously
Signature
async Task<RequestCompleteResponse<TData> > Meta.WitAi.Requests.VRequest.RequestJsonPutAsync< TData >(Uri uri, string putText, RequestCompleteDelegate< TData > onPartial=null)
Parameters
uri: Uri  The uri to be requested
putText: string  The text to be uploaded
onPartial: RequestCompleteDelegate< TData >
Returns
async Task< RequestCompleteResponse< TData > > RequestCompleteResponse with parsed data & error if applicable
RequestProgressDelegate ( progress )
Signature
delegate void Meta.WitAi.Requests.VRequest.RequestProgressDelegate(float progress)
Parameters
progress: float
Returns
delegate void
RequestText ( unityRequest , onComplete , onPartial )
Performs a text request & handles the resultant text
Signature
bool Meta.WitAi.Requests.VRequest.RequestText(UnityWebRequest unityRequest, RequestCompleteDelegate< string > onComplete, TextStreamHandler.TextStreamResponseDelegate onPartial=null)
Parameters
unityRequest: UnityWebRequest  The unity request performing the post or get
onComplete: RequestCompleteDelegate< string >  The delegate upon completion
Returns
bool
RequestTextAsync ( unityRequest , onPartial )
Performs a text request async & returns the text along with any errors
Signature
async Task<RequestCompleteResponse<string> > Meta.WitAi.Requests.VRequest.RequestTextAsync(UnityWebRequest unityRequest, TextStreamHandler.TextStreamResponseDelegate onPartial=null)
Parameters
unityRequest: UnityWebRequest  The unity request performing the post or get
Returns
async Task< RequestCompleteResponse< string > >

Static Methods

CanDecodeAudio ( audioType )
Whether or not a specific audio type can be decoded
Signature
static bool Meta.WitAi.Requests.VRequest.CanDecodeAudio(AudioType audioType)
Parameters
audioType: AudioType
Returns
bool
CanStreamAudio ( audioType )
Whether or not audio can be streamed for a specific audio type
Signature
static bool Meta.WitAi.Requests.VRequest.CanStreamAudio(AudioType audioType)
Parameters
audioType: AudioType
Returns
bool
GetAudioDecoderType ( audioType )
Returns the IAudioDecoder type that works best with the specified AudioType for the current platform.
Signature
static Type Meta.WitAi.Requests.VRequest.GetAudioDecoderType(AudioType audioType)
Parameters
audioType: AudioType
Returns
Type
GetAudioExtension ( audioType )
Get audio extension from audio type
Signature
static string Meta.WitAi.Requests.VRequest.GetAudioExtension(AudioType audioType)
Parameters
audioType: AudioType  The specified audio type
Returns
string Audio extension without period.
GetAudioExtension ( audioType , textStream )
Get audio extension from audio type
Signature
static string Meta.WitAi.Requests.VRequest.GetAudioExtension(AudioType audioType, bool textStream)
Parameters
audioType: AudioType  The specified audio type
textStream: bool  Whether data includes text
Returns
string Audio extension without period.
GetSpecificRequestError ( request )
Signature
static string Meta.WitAi.Requests.VRequest.GetSpecificRequestError(UnityWebRequest request)
Parameters
request: UnityWebRequest
Returns
string

Inner Struct

RequestCompleteResponse Struct

A request result wrapper which can return a result and error string.

Constructors

RequestCompleteResponse ( value , error )
Simple constructor with value and error
Signature
Meta.WitAi.Requests.VRequest.RequestCompleteResponse< TValue >.RequestCompleteResponse(TValue value, string error)
Parameters
value: TValue  The value of the response
error: string  Any returned error from the request
RequestCompleteResponse ( value )
Signature
Meta.WitAi.Requests.VRequest.RequestCompleteResponse< TValue >.RequestCompleteResponse(TValue value)
Parameters
value: TValue
RequestCompleteResponse ( error )
Signature
Meta.WitAi.Requests.VRequest.RequestCompleteResponse< TValue >.RequestCompleteResponse(string error)
Parameters
error: string

Fields

Error : string
The error string, if errors occurred. Will be NullOrEmpty otherwise.
Signature
string Meta.WitAi.Requests.VRequest.RequestCompleteResponse< TValue >.Error
Value : TValue
The type of the result data
Signature
TValue Meta.WitAi.Requests.VRequest.RequestCompleteResponse< TValue >.Value