Skip to content

Commit

Permalink
Fixed Issue YahooArchive#429: Added params to body for PUT requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ridgway committed Aug 29, 2012
1 parent 0808a9d commit 5a2e0a8
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 159 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -9,5 +9,5 @@ node_modules
arrowreport arrowreport
artifacts artifacts
flatfile flatfile
test_descriptor-report.json *_descriptor-report.json
test_descriptor-report.xml *_descriptor-report.xml
4 changes: 2 additions & 2 deletions .npmignore
Expand Up @@ -10,5 +10,5 @@ artifacts
examples examples
flatfile flatfile
Makefile Makefile
test_descriptor-report.json *_descriptor-report.json
test_descriptor-report.xml *_descriptor-report.xml
37 changes: 28 additions & 9 deletions lib/app/autoload/rest.common.js
Expand Up @@ -53,9 +53,29 @@ YUI.add('mojito-rest-lib', function(Y, NAME) {
Y.namespace('mojito.lib').REST = { Y.namespace('mojito.lib').REST = {


/** /**
* Calls IO. Provides mockability
* @param url
* @param config the IO configuration
* @param callback
* @private * @private
*/ */
_doRequest: function(method, url, params, config, callback) { _doRequest: function (url, config) {
Y.io(url, config);
},

/**
* Creates the configuration to be passed to the IO request
*
* @param {String} method HTTP method
* @param {String} url HTTP location
* @param {Object} params Params that are passed in the request
* @param {Object} config Additional configuration
* @param {Object} config.headers Headers to be sent with the request
* @param {Number} config.timeout Timeout for the IO request
* @param {Function} callback The handler for the response
* @private
*/
_makeRequest: function(method, url, params, config, callback) {
// TODO: [Issue 72] Figure out why 'params' values are attaching // TODO: [Issue 72] Figure out why 'params' values are attaching
// themselves to headers! // themselves to headers!
var ioConfig = { var ioConfig = {
Expand All @@ -72,7 +92,7 @@ YUI.add('mojito-rest-lib', function(Y, NAME) {
} else { } else {
url += '&' + params; url += '&' + params;
} }
} else if ('POST' === method) { } else if ('POST' === method || 'PUT' === method) {
ioConfig.data = params; ioConfig.data = params;
} }
} }
Expand All @@ -89,8 +109,7 @@ YUI.add('mojito-rest-lib', function(Y, NAME) {
callback(resp); callback(resp);
}; };
} }

this._doRequest(url, ioConfig);
Y.io(url, ioConfig);
}, },




Expand All @@ -104,7 +123,7 @@ YUI.add('mojito-rest-lib', function(Y, NAME) {
*/ */
GET: function() { GET: function() {
var args = ['GET'].concat(Array.prototype.slice.call(arguments)); var args = ['GET'].concat(Array.prototype.slice.call(arguments));
this._doRequest.apply(this, args); this._makeRequest.apply(this, args);
}, },




Expand All @@ -118,7 +137,7 @@ YUI.add('mojito-rest-lib', function(Y, NAME) {
*/ */
POST: function() { POST: function() {
var args = ['POST'].concat(Array.prototype.slice.call(arguments)); var args = ['POST'].concat(Array.prototype.slice.call(arguments));
this._doRequest.apply(this, args); this._makeRequest.apply(this, args);
}, },




Expand All @@ -132,7 +151,7 @@ YUI.add('mojito-rest-lib', function(Y, NAME) {
*/ */
PUT: function() { PUT: function() {
var args = ['PUT'].concat(Array.prototype.slice.call(arguments)); var args = ['PUT'].concat(Array.prototype.slice.call(arguments));
this._doRequest.apply(this, args); this._makeRequest.apply(this, args);
}, },




Expand All @@ -146,7 +165,7 @@ YUI.add('mojito-rest-lib', function(Y, NAME) {
*/ */
DELETE: function() { DELETE: function() {
var args = ['DELETE'].concat(Array.prototype.slice.call(arguments)); var args = ['DELETE'].concat(Array.prototype.slice.call(arguments));
this._doRequest.apply(this, args); this._makeRequest.apply(this, args);
}, },




Expand All @@ -160,7 +179,7 @@ YUI.add('mojito-rest-lib', function(Y, NAME) {
*/ */
HEAD: function() { HEAD: function() {
var args = ['HEAD'].concat(Array.prototype.slice.call(arguments)); var args = ['HEAD'].concat(Array.prototype.slice.call(arguments));
this._doRequest.apply(this, args); this._makeRequest.apply(this, args);
} }
}; };


Expand Down
Expand Up @@ -314,12 +314,11 @@ YUI.add('RESTLib', function(Y) {
}, },


printPUTParams: function(actionContext){ printPUTParams: function(actionContext){
var project = actionContext.params.getFromUrl("project"); var project = actionContext.params.getFromBody("project");
var sprint = actionContext.params.getFromUrl("sprint"); var sprint = actionContext.params.getFromBody("sprint");
var method = actionContext.http.getRequest().method; var method = actionContext.http.getRequest().method;


//var output = "<p id=\"output\">(METHOD: " + method + ") This is sprint " + sprint + " for the project " + project + "</p>"; var output = "<p id=\"output\">(METHOD: " + method + ") This is sprint " + sprint + " for the project " + project + "</p>";
var output = "<p id=\"output\">(METHOD: " + method + ")</p>";
actionContext.http.setHeader('content-type', 'text/html'); actionContext.http.setHeader('content-type', 'text/html');
actionContext.done(output); actionContext.done(output);
}, },
Expand Down
2 changes: 1 addition & 1 deletion tests/func/serveronly/testrestlib-PUTWithParamsClient.js
Expand Up @@ -15,7 +15,7 @@ YUI({
var that = this; var that = this;
Y.one('#p_putParam').simulate('click'); Y.one('#p_putParam').simulate('click');
that.wait(function(){ that.wait(function(){
Y.Assert.areEqual('(METHOD: PUT)', Y.one('#output').get('innerHTML')); Y.Assert.areEqual('(METHOD: PUT) This is sprint 4 for the project Mojito', Y.one('#output').get('innerHTML'));
}, 2000); }, 2000);
} }


Expand Down
2 changes: 1 addition & 1 deletion tests/func/serveronly/testrestlib-PUTWithParamsServer.js
Expand Up @@ -12,7 +12,7 @@ YUI({
suite.add(new Y.Test.Case({ suite.add(new Y.Test.Case({
"test PUTWithParamsServer": function(){ "test PUTWithParamsServer": function(){
Y.Assert.areEqual('200', Y.one('#status').get('innerHTML')); Y.Assert.areEqual('200', Y.one('#status').get('innerHTML'));
Y.Assert.areEqual('(METHOD: PUT)', Y.one('#output').get('innerHTML')); Y.Assert.areEqual('(METHOD: PUT) This is sprint 4 for the project Mojito', Y.one('#output').get('innerHTML'));
} }
})); }));


Expand Down
5 changes: 2 additions & 3 deletions tests/run.js
Expand Up @@ -158,12 +158,11 @@ function deploy (cmd, callback) {


function startArrowSelenium (callback) { function startArrowSelenium (callback) {
console.log("---Starting Arrow Selenium---"); console.log("---Starting Arrow Selenium---");
var p = runCommand(cwd+"/func/applications/frameworkapp/common", "arrow_selenium", ["--open=firefox"]); var p = runCommand(cwd+"/func/applications/frameworkapp/common", "arrow_selenium", ["--open=firefox"], function () {
setTimeout(function () {
pids.push(p.pid); pids.push(p.pid);
pidNames[p.pid] = 'arrow_selenium'; pidNames[p.pid] = 'arrow_selenium';
callback(null); callback(null);
}, 10000); });
} }


function runFuncTests (callback) { function runFuncTests (callback) {
Expand Down

0 comments on commit 5a2e0a8

Please sign in to comment.