Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Bugfix for getToken (thanks to danboy)

  • Loading branch information...
commit 9967cd903d2eb3e8b2170c9cdc4c8a2f7b1b7c1d 1 parent d97aecf
@stelcheck stelcheck authored
Showing with 15 additions and 17 deletions.
  1. +1 −1  Makefile
  2. +1 −1  examples/tests.js
  3. +13 −15 index.js
View
2  Makefile
@@ -1,5 +1,5 @@
unit:
- find vows/ -name "*.js" -exec node {} \;
+ find tests/ -name "*.js" -exec node {} \;
lint:
find . -name "*.js" -not -regex "^\./node_modules\(.*\)" -exec ./node_modules/jslint/bin/jslint.js --sloppy --node --white --forin false {} \;
View
2  examples/tests.js
@@ -1,7 +1,7 @@
/*jslint
forin: true
*/
-var pivotal = require("pivotal"),
+var pivotal = require("../index.js"),
colors = require("colors"),
async = require("async"),
tests = null,
View
28 index.js
@@ -50,15 +50,7 @@ var pivotal = {
*/
pivotal.getToken = function (user, pass, cb) {
- this.apiCall("POST", ["tokens", "active"], null, querystring.stringify({"username": user, "password" : pass}), function (res) {
-
- if (res.token) {
- this.token = res.token.guid;
- return cb(this.token);
- }
-
- return cb(false);
- });
+ pivotal.apiCall("POST", ["tokens", "active"], null, querystring.stringify({"username": user, "password" : pass}), null, cb);
};
/**
@@ -557,7 +549,7 @@ pivotal.apiCall = function (method, pathSegments, query, data, file, cb) {
// Build Request URL
var path = "/services/v3/" + pathSegments.join("/"),
- xmlData = null,
+ postData = null,
options = null,
req = null,
boundaryKey = null;
@@ -583,9 +575,15 @@ pivotal.apiCall = function (method, pathSegments, query, data, file, cb) {
// format data if required
if (data) {
- xmlData = this.toXml(data);
- options.headers["Content-Length"] = xmlData.length;
- options.headers["Content-Type"] = "application/xml";
+ if(typeof(data) === "string"){
+ postData = data;
+ }
+ else {
+ postData = this.toXml(data);
+ options.headers["Content-Type"] = "application/xml";
+ }
+
+ options.headers["Content-Length"] = postData.length;
}
if (file) {
@@ -662,8 +660,8 @@ pivotal.apiCall = function (method, pathSegments, query, data, file, cb) {
});
// PUT / POST data
- if (xmlData) {
- return req.end(xmlData);
+ if (postData) {
+ return req.end(postData);
}
/*
Please sign in to comment.
Something went wrong with that request. Please try again.