2014-02-28 16:45:35 +00:00
|
|
|
/**
|
|
|
|
* @module Typertext
|
|
|
|
* @submodule Http
|
|
|
|
* @submodule Json
|
|
|
|
*/
|
2014-02-26 19:12:37 +00:00
|
|
|
module Typertext {
|
|
|
|
import HttpHeaderData = Typertext.Http.HttpHeaderData;
|
|
|
|
import HttpResponseStatus = Typertext.Http.HttpResponseStatus;
|
|
|
|
|
|
|
|
export class GenericResponse<T> {
|
|
|
|
private status:HttpResponseStatus;
|
|
|
|
private headers:HttpHeaderData;
|
|
|
|
private httpStatus:number;
|
|
|
|
private content:T;
|
|
|
|
|
2014-02-28 16:45:35 +00:00
|
|
|
/**
|
|
|
|
* A common way to specify a response that gets passed between classes and eventually returned to the user
|
|
|
|
*
|
|
|
|
* @class GenericResponse
|
|
|
|
* @uses Typertext.Http.HttpHeaderData
|
|
|
|
* @uses Typertext.Http.HttpResponseStatus
|
|
|
|
*
|
|
|
|
* @param {HttpResponseStatus} status
|
|
|
|
* @param {HttpHeaderData} responseHeaders
|
|
|
|
* @param {number} httpResponseCode
|
|
|
|
* @param {T} responseBody
|
|
|
|
* @constructor
|
|
|
|
*
|
|
|
|
* @author Kegan Myers <kegan@keganmyers.com>
|
|
|
|
* @version 0.3.0
|
|
|
|
*/
|
2014-02-26 19:12:37 +00:00
|
|
|
constructor(status:HttpResponseStatus, responseHeaders?:HttpHeaderData, httpResponseCode?:number, responseBody?:T) {
|
|
|
|
this.status = status;
|
|
|
|
this.headers = responseHeaders;
|
|
|
|
this.httpStatus = httpResponseCode;
|
|
|
|
this.content = responseBody;
|
|
|
|
}
|
|
|
|
|
2014-02-28 16:45:35 +00:00
|
|
|
/**
|
|
|
|
* Accessor method
|
|
|
|
*
|
|
|
|
* @returns {T}
|
|
|
|
*/
|
2014-02-26 19:12:37 +00:00
|
|
|
public GetContent():T {
|
|
|
|
return this.content;
|
|
|
|
}
|
|
|
|
|
2014-02-28 16:45:35 +00:00
|
|
|
/**
|
|
|
|
* Accessor method
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-26 19:12:37 +00:00
|
|
|
public GetContentType():string {
|
|
|
|
return this.GetHeaders()["Content-Type"];
|
|
|
|
}
|
|
|
|
|
2014-02-28 16:45:35 +00:00
|
|
|
/**
|
|
|
|
* Accessor method
|
|
|
|
*
|
|
|
|
* @returns {HttpHeaderData}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-26 19:12:37 +00:00
|
|
|
public GetHeaders():HttpHeaderData {
|
|
|
|
return this.headers;
|
|
|
|
}
|
|
|
|
|
2014-02-28 16:45:35 +00:00
|
|
|
/**
|
|
|
|
* Accessor method
|
|
|
|
*
|
|
|
|
* @returns {number}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-26 19:12:37 +00:00
|
|
|
public GetHttpStatus():number {
|
|
|
|
return this.httpStatus;
|
|
|
|
}
|
|
|
|
|
2014-02-28 16:45:35 +00:00
|
|
|
/**
|
|
|
|
* Accessor method
|
|
|
|
*
|
|
|
|
* @returns {HttpResponseStatus}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-26 19:12:37 +00:00
|
|
|
public GetStatus():HttpResponseStatus {
|
|
|
|
return this.status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|