Add additional HTTP Methods, add references

This commit is contained in:
Kegan Myers 2014-04-28 10:07:15 -05:00
parent 3ec1bcaf9a
commit 0d765f6456
10 changed files with 111 additions and 15 deletions

View file

@ -1,6 +1,6 @@
{
"name": "Typertext",
"version": "0.7.2",
"version": "0.8.0",
"homepage": "https://github.com/terribleplan/Typertext",
"authors": [
"Kegan Myers <kegan@keganmyers.com>"

15
build/typertext.d.ts vendored
View file

@ -16,8 +16,10 @@ declare module Typertext.Transport {
}
declare module Typertext {
interface GenericRequest<T extends GenericResponseHandler<GenericResponse<any>>> {
Delete(request: Http.HttpUrl, callback: T): void;
Get(request: Http.HttpUrl, callback: T): void;
Post(request: Http.HttpUrl, postData: Http.HttpPostData, callback: T): void;
Put(request: Http.HttpUrl, putData: Http.HttpPostData, callback: T): void;
RawRequest(method: Http.HttpMethod, request: Http.HttpUrl, postData?: Http.HttpPostData, callback?: T, transport?: Transport.TransportConstructor): void;
}
}
@ -46,8 +48,13 @@ declare module Typertext.Http {
}
declare module Typertext.Http {
enum HttpMethod {
GET = 0,
POST = 1,
DELETE = 0,
GET = 1,
HEAD = 2,
OPTIONS = 3,
POST = 4,
PUT = 5,
TRACE = 6,
}
}
declare module Typertext.Http {
@ -69,8 +76,10 @@ declare module Typertext.Http {
declare module Typertext.Http {
class HttpRequest implements GenericRequest<HttpResponseHandler> {
constructor();
public Delete(request: HttpUrl, callback: HttpResponseHandler): void;
public Get(request: HttpUrl, callback: HttpResponseHandler): void;
public Post(request: HttpUrl, postData: HttpPostData, callback: HttpResponseHandler): void;
public Put(request: HttpUrl, putData: HttpPostData, callback: HttpResponseHandler): void;
public RawRequest(method: HttpMethod, request: HttpUrl, postData?: HttpPostData, callback?: HttpResponseHandler, transport?: Transport.TransportConstructor): void;
}
}
@ -130,8 +139,10 @@ declare module Typertext.Json {
private jsonType;
private request;
constructor(jsonContentType?: string);
public Delete(request: Http.HttpUrl, callback: JsonResponseHandler): void;
public Get(request: Http.HttpUrl, callback: JsonResponseHandler): void;
public Post(request: Http.HttpUrl, postData: Http.HttpPostData, callback: JsonResponseHandler): void;
public Put(request: Http.HttpUrl, putData: Http.HttpPostData, callback: JsonResponseHandler): void;
public RawRequest(method: Http.HttpMethod, request: Http.HttpUrl, postData?: Http.HttpPostData, callback?: JsonResponseHandler, transport?: Transport.TransportConstructor): void;
}
}

View file

@ -87,8 +87,13 @@ var Typertext;
(function (Typertext) {
(function (Http) {
(function (HttpMethod) {
HttpMethod[HttpMethod["GET"] = 0] = "GET";
HttpMethod[HttpMethod["POST"] = 1] = "POST";
HttpMethod[HttpMethod["DELETE"] = 0] = "DELETE";
HttpMethod[HttpMethod["GET"] = 1] = "GET";
HttpMethod[HttpMethod["HEAD"] = 2] = "HEAD";
HttpMethod[HttpMethod["OPTIONS"] = 3] = "OPTIONS";
HttpMethod[HttpMethod["POST"] = 4] = "POST";
HttpMethod[HttpMethod["PUT"] = 5] = "PUT";
HttpMethod[HttpMethod["TRACE"] = 6] = "TRACE";
})(Http.HttpMethod || (Http.HttpMethod = {}));
var HttpMethod = Http.HttpMethod;
})(Typertext.Http || (Typertext.Http = {}));
@ -113,12 +118,20 @@ var Typertext;
var HttpRequest = (function () {
function HttpRequest() {
}
HttpRequest.prototype.Delete = function (request, callback) {
this.RawRequest(5 /* PUT */, request, {}, callback);
};
HttpRequest.prototype.Get = function (request, callback) {
this.RawRequest(0 /* GET */, request, {}, callback);
this.RawRequest(1 /* GET */, request, {}, callback);
};
HttpRequest.prototype.Post = function (request, postData, callback) {
this.RawRequest(1 /* POST */, request, postData, callback);
this.RawRequest(4 /* POST */, request, postData, callback);
};
HttpRequest.prototype.Put = function (request, putData, callback) {
this.RawRequest(5 /* PUT */, request, putData, callback);
};
HttpRequest.prototype.RawRequest = function (method, request, postData, callback, transport) {
@ -320,12 +333,20 @@ var Typertext;
this.request = new HttpRequest();
this.jsonType = jsonContentType;
}
JsonRequest.prototype.Delete = function (request, callback) {
this.RawRequest(0 /* DELETE */, request, {}, callback);
};
JsonRequest.prototype.Get = function (request, callback) {
this.RawRequest(0 /* GET */, request, {}, callback);
this.RawRequest(1 /* GET */, request, {}, callback);
};
JsonRequest.prototype.Post = function (request, postData, callback) {
this.RawRequest(1 /* POST */, request, postData, callback);
this.RawRequest(4 /* POST */, request, postData, callback);
};
JsonRequest.prototype.Put = function (request, putData, callback) {
this.RawRequest(5 /* PUT */, request, putData, callback);
};
JsonRequest.prototype.RawRequest = function (method, request, postData, callback, transport) {
@ -472,7 +493,7 @@ var Typertext;
this.xdr.open(HttpMethod[this.method], this.request.ToString());
if (this.method == 0 /* GET */) {
if (this.method == 1 /* GET */) {
this.xdr.send();
return;
}
@ -540,7 +561,7 @@ var Typertext;
XHR.prototype.Send = function () {
this.xhr.open(HttpMethod[this.method], this.request.ToString(), true);
if (this.method == 0 /* GET */) {
if (this.method == 1 /* GET */) {
this.xhr.send();
return;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,3 +1,8 @@
/// <reference path="GenericResponse.ts" />
/// <reference path="GenericResponseHandler.ts" />
/// <reference path="Http/HttpMethod.ts" />
/// <reference path="Http/HttpPostData.ts" />
/// <reference path="Http/HttpUrl.ts" />
/// <reference path="Transport/TransportConstructor.ts" />
/**
@ -24,6 +29,14 @@ module Typertext {
*/
export interface GenericRequest<T extends GenericResponseHandler<GenericResponse<any>>> {
/**
* A convenience method which will simply use the RawRequest method with a DELETE
*
* @param {HttpUrl} request
* @param {GenericResponseHandler} callback
*/
Delete(request:HttpUrl, callback:T):void;
/**
* A convenience method which will simply use the RawRequest method with a GET
*
@ -41,6 +54,15 @@ module Typertext {
*/
Post(request:HttpUrl, postData:HttpPostData, callback:T):void;
/**
* A convenience method which will simply use the RawRequest method with a GET
*
* @param {HttpUrl} request
* @param {HttpPostData} putData
* @param {GenericResponseHandler} callback
*/
Put(request:HttpUrl, putData:HttpPostData, callback:T):void;
/**
* A method which calls the server and passes returned data to an optionally specified callback
*

View file

@ -26,6 +26,16 @@ module Typertext.Http {
constructor() {
}
/**
* A convenience method for simply calling a DELETE
*
* @param {HttpUrl} request
* @param {HttpResponseHandler} callback
*/
public Delete(request:HttpUrl, callback:HttpResponseHandler):void {
this.RawRequest(HttpMethod.PUT, request, {}, callback);
}
/**
* A convenience method for simply calling a GET
*
@ -47,6 +57,17 @@ module Typertext.Http {
this.RawRequest(HttpMethod.POST, request, postData, callback);
}
/**
* A convenience method for simply calling a PUT
*
* @param {HttpUrl} request
* @param {HttpPostData} putData
* @param {HttpResponseHandler} callback
*/
public Put(request:HttpUrl, putData:HttpPostData, callback:HttpResponseHandler):void {
this.RawRequest(HttpMethod.PUT, request, putData, callback);
}
/**
* This is a method that calls against a specified HTTP server and does basic handling of responses, with no
* data manipulation

View file

@ -35,6 +35,16 @@ module Typertext.Json {
this.jsonType = jsonContentType;
}
/**
* A convenience method for simply calling a DELETE
*
* @param {HttpUrl} request
* @param {JsonResponseHandler} callback
*/
public Delete(request:HttpUrl, callback:JsonResponseHandler):void {
this.RawRequest(HttpMethod.DELETE, request, {}, callback);
}
/**
* A convenience method for simply calling a GET
*
@ -56,6 +66,17 @@ module Typertext.Json {
this.RawRequest(HttpMethod.POST, request, postData, callback);
}
/**
* A convenience method for simply calling a POST
*
* @param {HttpUrl} request
* @param {HttpPutData} postData
* @param {JsonResponseHandler} callback
*/
public Put(request:HttpUrl, putData:HttpPostData, callback:JsonResponseHandler):void {
this.RawRequest(HttpMethod.PUT, request, putData, callback);
}
/**
* A layer to automatically decode a response into a JSON object
*

View file

@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/terribleplan/Typertext.git"
},
"version": "0.7.2",
"version": "0.8.0",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-cli": "~0.1.13",