Skip to content

Commit

Permalink
Improve method curl to support oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
puritys committed Jul 5, 2016
1 parent 3c49f21 commit 8065dde
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ exports.exit = function(code) {/*{{{*/
exports.empty = function (v) {//{{{
if (!v) {
return true;
} else if (casting.is_object(v) && Object.keys(v).length === 0) {
return true;
} else if (casting.is_array(v) && v.length === 0) {
return true;
}

return false;

}//}}}
Expand Down
16 changes: 10 additions & 6 deletions src/js/curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ function reformatCurlData(curl) {//{{{
pos = url.indexOf("?");
if (pos != -1) {
urlParam = url.substring(pos + 1);
param = core.parse_str(urlParam);
formatCurl.url = url.substring(0, pos);

if (casting.is_string(curl.param)) {
param2 = core.parse_str(curl.param);
} else if (casting.is_object(curl.param)) {
param2 = curl.param;
if (typeof(curl.param) === "undefined" || core.empty(curl.param)) {
formatCurl.param = urlParam;
} else {
param = core.parse_str(urlParam);
if (casting.is_string(curl.param)) {
param2 = core.parse_str(curl.param);
} else if (casting.is_object(curl.param)) {
param2 = curl.param;
}
formatCurl.param = phplikeArray.array_merge(param, param2);
}

formatCurl.param = phplikeArray.array_merge(param, param2);
}

return formatCurl;
Expand Down
10 changes: 10 additions & 0 deletions tests/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ describe('Test function: empty', function() {//{{{
assert.equal(false, is);
});

it('empty object is empty', function() {
var str = {};
var is = php.empty(str);
assert.equal(true, is);
});
it('empty array is empty', function() {
var str = [];
var is = php.empty(str);
assert.equal(true, is);
});


});//}}}
Expand Down
12 changes: 12 additions & 0 deletions tests/curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ describe('Test method: reformatCurlData', function() {//{{{

});

it('Keep parameter "%26" for oauth', function() {
var c = phplikeMod.curl_init();
var url = "http://www.google.com.tw/?a=b&a1=cc%26";
c.url = url;
var res = phplikeMod.reformatCurlData(c);
assert.equal("http://www.google.com.tw/", res['url']);
assert.equal("a=b&a1=cc%26", res['param']);



});

});//}}}

describe('Test method: responseHeaderToHash', function() {
Expand Down

0 comments on commit 8065dde

Please sign in to comment.