Skip to content

Commit 0eb0c3d

Browse files
authored
Merge pull request #10 from Irandoust/bugfix/fix-trello-response-error
Bugfix/fix trello response error
2 parents dfd17fb + fbff474 commit 0eb0c3d

File tree

4 files changed

+57
-42
lines changed

4 files changed

+57
-42
lines changed

bundle/react-trello-client.bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,12 @@ var TrelloClient = function TrelloClient(props) {
165165
};
166166

167167
var ajax = function ajax(restOptions) {
168-
return fetch(restOptions.url, {
169-
method: restOptions.type,
170-
headers: {
171-
'Content-Type': 'application/json'
172-
},
173-
body: restOptions.type === 'GET' ? null : JSON.stringify(restOptions.data)
174-
}).then(function (response) {
175-
return response;
168+
return fetch(restOptions.url, restOptions.options).then(function (response) {
169+
return response.json();
170+
}).then(function (data) {
171+
return restOptions.success(data);
176172
}).catch(function (error) {
177-
return error;
173+
return restOptions.error(error);
178174
});
179175
};
180176

@@ -251,24 +247,38 @@ var TrelloClient = function TrelloClient(props) {
251247
error = _parseRestArgs2[3];
252248

253249
var restOpts = {
254-
url: '' + baseURL + path,
255-
type: method,
256-
data: {},
257-
dataType: 'json',
250+
url: '' + baseURL + path + '?',
251+
options: {
252+
method: method,
253+
mode: 'cors',
254+
referrerPolicy: 'no-referrer',
255+
headers: {
256+
'Accept': 'application/json',
257+
'Content-Type': 'application/json'
258+
}
259+
},
258260
success: success,
259261
error: error
260-
261262
// Only include the key if it's been set to something truthy
262-
};if (_key) {
263-
restOpts.data.key = _key;
263+
264+
265+
// Only include body if method is not GET
266+
};if (method != 'GET') {
267+
restOpts.options.body = {};
268+
}
269+
270+
// Only include the key if it's been set to something truthy
271+
if (_key) {
272+
restOpts.url = restOpts.url + '&key=' + _key;
264273
}
274+
265275
// Only include the token if it's been set to something truthy
266276
if (_token) {
267-
restOpts.data.token = _token;
277+
restOpts.url = restOpts.url + '&token=' + _token;
268278
}
269279

270280
if (params != null) {
271-
extend(restOpts.data, params);
281+
extend(restOpts.options.body, params);
272282
}
273283

274284
return ajax(restOpts);
@@ -543,7 +553,6 @@ var TrelloClient = function TrelloClient(props) {
543553
}
544554

545555
window.Trello = Trello;
546-
547556
var localStorage = window.localStorage;
548557

549558

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-trello-client",
3-
"version": "1.1.4",
3+
"version": "1.1.6",
44
"description": "\"This is a simple and lightweight React plugin to have a clean Trello client without using jQuery or any other additional libraries.\"",
55
"main": "dist/index.js",
66
"scripts": {

src/index.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,11 @@ const TrelloClient = (props) => {
100100

101101
}
102102

103-
const ajax = function (restOptions) {
104-
return fetch(restOptions.url, {
105-
method: restOptions.type,
106-
headers: {
107-
'Content-Type': 'application/json',
108-
},
109-
body: restOptions.type === 'GET' ? null : JSON.stringify(restOptions.data)
110-
})
111-
.then(response => response)
112-
.catch(error => error)
103+
const ajax = (restOptions) => {
104+
return fetch(restOptions.url, restOptions.options)
105+
.then(response => response.json())
106+
.then(data => restOptions.success(data))
107+
.catch(error => restOptions.error(error))
113108
}
114109

115110
const authorizeURL = function (args) {
@@ -169,27 +164,39 @@ const TrelloClient = (props) => {
169164
// error - Function to call when the request fails
170165
rest(method, ...args) {
171166
const [path, params, success, error] = parseRestArgs(args);
172-
173-
const restOpts = {
174-
url: `${baseURL}${path}`,
175-
type: method,
176-
data: {},
177-
dataType: 'json',
167+
var restOpts = {
168+
url: '' + baseURL + path + '?',
169+
options: {
170+
method,
171+
mode: 'cors',
172+
referrerPolicy: 'no-referrer',
173+
headers: {
174+
'Accept': 'application/json',
175+
'Content-Type': 'application/json',
176+
},
177+
},
178178
success,
179-
error,
179+
error
180+
// Only include the key if it's been set to something truthy
181+
}
182+
183+
// Only include body if method is not GET
184+
if (method != 'GET') {
185+
restOpts.options.body = {}
180186
}
181187

182188
// Only include the key if it's been set to something truthy
183189
if (key) {
184-
restOpts.data.key = key;
190+
restOpts.url = `${restOpts.url}&key=${key}`
185191
}
192+
186193
// Only include the token if it's been set to something truthy
187194
if (token) {
188-
restOpts.data.token = token;
195+
restOpts.url = `${restOpts.url}&token=${token}`
189196
}
190197

191198
if (params != null) {
192-
extend(restOpts.data, params);
199+
extend(restOpts.options.body, params);
193200
}
194201

195202
return ajax(restOpts);
@@ -465,7 +472,6 @@ const TrelloClient = (props) => {
465472
}
466473

467474
window.Trello = Trello;
468-
469475
const { localStorage } = window;
470476

471477
if (localStorage != null) {

0 commit comments

Comments
 (0)