Allow arrays to be used as arguments for POST/PUT requests

master 0.8.2
Kegan Myers 8 years ago
parent 85c5fe3d0d
commit 769c779d8c
  1. 2
      bower.json
  2. 10
      build/typertext.d.ts
  3. 17
      build/typertext.js
  4. 2
      build/typertext.js.map
  5. 2
      build/typertext.min.js
  6. 2
      build/typertext.min.js.map
  7. 5
      lib/Typertext/Http/HttpQueryString.ts
  8. 5
      lib/Typertext/Http/HttpRequest.ts
  9. 17
      lib/Typertext/Http/HttpUrl.ts
  10. 2
      package.json
  11. 9
      test/Typertext/Http/HttpUrl.test.js

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

@ -92,7 +92,11 @@ declare module Typertext.Http {
}
declare module Typertext.Http {
interface HttpQueryString {
[index: string]: string;
[index: string]: any;
}
}
declare module Typertext.Http {
interface HttpResponseHandler extends GenericResponseHandler<HttpResponse> {
}
}
declare module Typertext.Transport {
@ -121,10 +125,6 @@ declare module Typertext.Http {
constructor(status: HttpResponseStatus, responseHeaderGetter?: (input: string) => string, httpResponseCode?: number, responseBody?: string);
}
}
declare module Typertext.Http {
interface HttpResponseHandler extends GenericResponseHandler<HttpResponse> {
}
}
declare module Typertext.Http {
enum HttpResponseStatus {
success = 0,

@ -130,7 +130,22 @@ var Typertext;
var temp;
for (temp in data) {
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(data[temp]) + "&";
var cur = data[temp];
if (cur instanceof Array) {
for (var i = 0; i < cur.length; i++) {
if (typeof cur[i] !== "string") {
continue;
}
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(cur[i]) + "&";
}
continue;
}
if (typeof cur === "string") {
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(cur) + "&";
}
}
return rs.slice(0, -1);

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

@ -5,8 +5,11 @@
module Typertext.Http {
/**
* @interface HttpQueryString
*
* Although it appears that this can provide any type of value, implementations
* are allowed to disregard types they are unable to handle.
*/
export interface HttpQueryString {
[index:string]:string
[index:string]:any
}
}

@ -1,10 +1,9 @@
/// <reference path="HttpResponseHandler.ts" />
/// <reference path="../GenericRequest.ts" />
/// <reference path="../Transport/TransportConstructor.ts" />
/// <reference path="../Transport/GenericTransport.ts" />
/// <reference path="../Transport/TransportChooser.ts" />
//TODO add support for IE8-9 CORS via XDomain
//TODO better error handling, ala exceptions
/**
* @namespace Typertext
* @module Http

@ -79,7 +79,22 @@ module Typertext.Http {
var temp:string;
for (temp in data) {
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(data[temp]) + "&";
var cur = data[temp];
if (cur instanceof Array) {
for (var i = 0; i < cur.length; i++) {
if (typeof cur[i] !== "string") {
continue;
}
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(cur[i]) + "&";
}
continue;
}
if (typeof cur === "string") {
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(cur) + "&";
}
}
return rs.slice(0, -1);

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

@ -209,6 +209,15 @@ describe("Typertext.Http.HttpUrl", function () {
expect(actualOutput).toEqual(expectedOutput);
});
it("encodes a key with an array value", function () {
var input = {
"foo": ["bar", "fizz", "buzz"]
},
expectedOutput = "foo=bar&foo=fizz&foo=buzz",
actualOutput = Typertext.Http.HttpUrl.UrlEncodeObject(input);
expect(actualOutput).toEqual(expectedOutput);
});
});
describe("UrlDecodeObject", function () {