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