appcelerator/acs-node-sdk — pull request #20 by zhangshsy (2014-09-19 08:41:08+00:00)
Title: fix CLOUDSRV-4044 sel field doesn't seem to work for query

# Ticket
https://jira.appcelerator.org/browse/CLOUDSRV-4044

# Description
Root cause:
A bug in node-acs-sdk util.js

input:
var query = {
"where": {
"module_name": "test"
},
"limit": 25,
"order": {
"module_name": 1,
"module_version": 1
},
"sel": {
"all": [
"module_name",
"module_version"
]
}
};

in utils.js, sendRequest method will call querystring.stringify(query) to convert the query options to a query string, but if query options contain hash items, querystring.stringify won't convert them to string format, so in acs server side, we will get the following request:

Started GET "/v1/files/query.json?key=0pOweeD1FZgosZjOvajHGWAuStVVc8rI" for 192.168.50.1 at 2014-09-17 13:19:47 +0000
Processing by FilesController#query as JSON
Parameters: {"where"=>"{\"module_name\":1}", "limit"=>"25", "skip"=>"0", "order"=>"", "sel"=>"", "suppress_response_codes"=>"true", "key"=>"0pOweeD1FZgosZjOvajHGWAuStVVc8rI", "version"=>"v1"}

and will get the error:
Invalid JSON in sel parameter: A JSON text must at least contain two octets!

solution:
before pass parameters to api server, sdk will iterate the parameters, if the value of a parameter is a hash, then stringify it.

# How to test
run mocha test at https://github.com/appcelerator/acs-tests/pull/165.

prerequest:
1. download this pull request
2. setup local acs-node sdk by npm:
npm install ./acs-node-sdk/