This repository has been archived on 2019-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
Typertext/lib/Typertext/GenericResponse.ts

88 lines
2.4 KiB
TypeScript
Raw Normal View History

/**
* @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;
/**
* 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;
}
/**
* Accessor method
*
* @returns {T}
*/
2014-02-26 19:12:37 +00:00
public GetContent():T {
return this.content;
}
/**
* Accessor method
*
* @returns {string}
* @constructor
*/
2014-02-26 19:12:37 +00:00
public GetContentType():string {
return this.GetHeaders()["Content-Type"];
}
/**
* Accessor method
*
* @returns {HttpHeaderData}
* @constructor
*/
2014-02-26 19:12:37 +00:00
public GetHeaders():HttpHeaderData {
return this.headers;
}
/**
* Accessor method
*
* @returns {number}
* @constructor
*/
2014-02-26 19:12:37 +00:00
public GetHttpStatus():number {
return this.httpStatus;
}
/**
* Accessor method
*
* @returns {HttpResponseStatus}
* @constructor
*/
2014-02-26 19:12:37 +00:00
public GetStatus():HttpResponseStatus {
return this.status;
}
}
}