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

87 lines
2.3 KiB
TypeScript
Raw Normal View History

/**
* @module Typertext
* @submodule Http
* @submodule Json
*/
2014-02-26 19:12:37 +00:00
module Typertext {
import HttpResponseStatus = Typertext.Http.HttpResponseStatus;
export class GenericResponse<T> {
private status:HttpResponseStatus;
private headers:(input:string)=>string;
2014-02-26 19:12:37 +00:00
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 {Function} responseHeaderGetter
* @param {number} httpResponseCode
* @param {T} responseBody
* @constructor
*
* @author Kegan Myers <kegan@keganmyers.com>
* @version 0.3.0
*/
constructor(status:HttpResponseStatus, responseHeaderGetter?:(input:string)=>string, httpResponseCode?:number, responseBody?:T) {
2014-02-26 19:12:37 +00:00
this.status = status;
this.headers = responseHeaderGetter;
2014-02-26 19:12:37 +00:00
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.GetHeader("Content-Type");
2014-02-26 19:12:37 +00:00
}
/**
* Accessor method
*
* @returns {string}
* @constructor
*/
public GetHeader(name:string):string {
return this.headers(name);
2014-02-26 19:12:37 +00:00
}
/**
* 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;
}
}
}