From 7d48dd705ea34da8ea782740e837292e5f085a44 Mon Sep 17 00:00:00 2001 From: Kegan Myers Date: Fri, 28 Feb 2014 11:31:49 -0600 Subject: [PATCH] Document JsonRequest --- lib/Typertext/Json/JsonRequest.ts | 41 ++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/Typertext/Json/JsonRequest.ts b/lib/Typertext/Json/JsonRequest.ts index df7de22..6221ecf 100644 --- a/lib/Typertext/Json/JsonRequest.ts +++ b/lib/Typertext/Json/JsonRequest.ts @@ -1,3 +1,7 @@ +/** + * @namespace Typertext + * @module Json + */ module Typertext.Json { import HttpRequest = Typertext.Http.HttpRequest; import HttpResponse = Typertext.Http.HttpResponse; @@ -10,20 +14,55 @@ module Typertext.Json { private jsonType:string; private request:HttpRequest; + /** + * A class to simplify passing both the status and data of a completed proxy request + * + * @interface GenericRequest + * @uses Typertext.Http.HttpRequest; + * @uses Typertext.Http.HttpResponse; + * @uses Typertext.Http.HttpResponseStatus; + * @uses Typertext.Http.HttpUrl; + * @uses Typertext.Http.HttpPostData; + * @uses Typertext.Http.HttpMethod; + * + * @author Kegan Myers + * @version 0.3.0 + */ constructor(jsonContentType:string = "application/json") { this.request = new HttpRequest(); this.jsonType = jsonContentType; } + /** + * A convenience method for simply calling a GET + * + * @param {HttpUrl} request + * @param {JsonResponseHandler} callback + */ public Get(request:HttpUrl, callback:JsonResponseHandler):void { this.RawRequest(HttpMethod.GET, request, {}, callback); } + /** + * A convenience method for simply calling a POST + * + * @param {HttpUrl} request + * @param {HttpPostData} postData + * @param {JsonResponseHandler} callback + */ public Post(request:HttpUrl, postData:HttpPostData, callback:JsonResponseHandler):void { this.RawRequest(HttpMethod.GET, request, postData, callback); } - public RawRequest(method:Typertext.Http.HttpMethod, request:HttpUrl, postData:Typertext.Http.HttpPostData = {}, callback:JsonResponseHandler = (c)=> { + /** + * A layer to automatically decode a response into a JSON object + * + * @param {HttpMethod} method + * @param {HttpUrl} request + * @param {HttpPostData} postData + * @param {JsonResponseHandler} callback + */ + public RawRequest(method:HttpMethod, request:HttpUrl, postData:Typertext.Http.HttpPostData = {}, callback:JsonResponseHandler = (c)=> { }) { this.request.RawRequest(method, request, postData, (response:HttpResponse)=> { //Make sure that we got the Json content type we are expecting