Skip to content

Commit

Permalink
Merge pull request #111 from Automattic/fix/parting-query-parameter
Browse files Browse the repository at this point in the history
Fix/parting query parameter
  • Loading branch information
retrofox authored and jsnajdr committed Jan 27, 2020
1 parent 0dc14ad commit 8e1e57d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 23 deletions.
10 changes: 5 additions & 5 deletions packages/wpcom.js/dist/wpcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Batch.prototype.run = function (query, fn) {
}

// add urls to query object
query['urls[]'] = this.urls;
query['urls'] = this.urls;

return this.wpcom.req.get('/batch', query, fn);
};
Expand Down Expand Up @@ -1838,9 +1838,6 @@ module.exports = function (params, query, body, fn) {
// query could be `null`
query = query || {};

// pass `query` and/or `body` to request params
params.query = query;

// Handle special query parameters
// - `apiVersion`
if (query.apiVersion) {
Expand All @@ -1859,7 +1856,10 @@ module.exports = function (params, query, body, fn) {
}

// Stringify query object before to send
query = qs.stringify(query);
query = qs.stringify(query, { arrayFormat: 'brackets' });

// pass `query` and/or `body` to request params
params.query = query;

if (body) {
params.body = body;
Expand Down
28 changes: 28 additions & 0 deletions packages/wpcom.js/examples/browser-cors/batch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>wpcom.js browser example with CORS</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script src="/dist/wpcom.js"></script>
<script>
var wpcom = WPCOM();

wpcom
.batch()
.add('/sites/en.blog.wordpress.com')
.add('/sites/en.blog.wordpress.com/posts')
.add('/read/tags')
.add('/read/lists')
.add('/read/teams')
.run(function(err, me){
if (err) throw err;

console.log(err);
console.log(me);
});
</script>
</body>
</html>

7 changes: 2 additions & 5 deletions packages/wpcom.js/examples/browser-cors/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script src="/wpcom.js"></script>
<script src="/dist/wpcom.js"></script>
<script>
var wpcom = WPCOM();

wpcom
.site('retrofocs.wordpress.com')
.get({
apiVersion: '1.2',
proxyOrigin: 'http://calypso-sync:3002'
} , function(err, me){
.get(function(err, me){
if (err) throw err;

console.log(me);
Expand Down
13 changes: 5 additions & 8 deletions packages/wpcom.js/examples/browser-proxy/batch.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@
});


var url_site = '/sites/en.blog.wordpress.com';
var url_posts = '/sites/en.blog.wordpress.com/posts';
var url_me = '/me';

// get information about the currently logged in user (via cookie)
wpcom
.batch()
.add(url_site)
.add(url_posts)
.add(url_me)
.add('/sites/en.blog.wordpress.com')
.add('/sites/en.blog.wordpress.com/posts')
.add('/read/tags')
.add('/read/lists')
.add('/read/teams')
.run(function(err, me){
if (err) throw err;

Expand Down
2 changes: 1 addition & 1 deletion packages/wpcom.js/lib/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Batch.prototype.run = function (query, fn) {
}

// add urls to query object
query['urls[]'] = this.urls;
query['urls'] = this.urls;

return this.wpcom.req.get('/batch', query, fn);
};
Expand Down
8 changes: 4 additions & 4 deletions packages/wpcom.js/lib/util/send-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ module.exports = function (params, query, body, fn) {
// query could be `null`
query = query || {};

// pass `query` and/or `body` to request params
params.query = query;

// Handle special query parameters
// - `apiVersion`
if (query.apiVersion) {
Expand All @@ -62,7 +59,10 @@ module.exports = function (params, query, body, fn) {
}

// Stringify query object before to send
query = qs.stringify(query);
query = qs.stringify(query, { arrayFormat: 'brackets' });

// pass `query` and/or `body` to request params
params.query = query;

if (body) {
params.body = body;
Expand Down

0 comments on commit 8e1e57d

Please sign in to comment.