Skip to content

Commit

Permalink
Merge pull request #10 from Irandoust/bugfix/fix-trello-response-error
Browse files Browse the repository at this point in the history
Bugfix/fix trello response error
  • Loading branch information
Irandoust authored Jan 25, 2020
2 parents dfd17fb + fbff474 commit 0eb0c3d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion bundle/react-trello-client.bundle.min.js

Large diffs are not rendered by default.

47 changes: 28 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,12 @@ var TrelloClient = function TrelloClient(props) {
};

var ajax = function ajax(restOptions) {
return fetch(restOptions.url, {
method: restOptions.type,
headers: {
'Content-Type': 'application/json'
},
body: restOptions.type === 'GET' ? null : JSON.stringify(restOptions.data)
}).then(function (response) {
return response;
return fetch(restOptions.url, restOptions.options).then(function (response) {
return response.json();
}).then(function (data) {
return restOptions.success(data);
}).catch(function (error) {
return error;
return restOptions.error(error);
});
};

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

var restOpts = {
url: '' + baseURL + path,
type: method,
data: {},
dataType: 'json',
url: '' + baseURL + path + '?',
options: {
method: method,
mode: 'cors',
referrerPolicy: 'no-referrer',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
},
success: success,
error: error

// Only include the key if it's been set to something truthy
};if (_key) {
restOpts.data.key = _key;


// Only include body if method is not GET
};if (method != 'GET') {
restOpts.options.body = {};
}

// Only include the key if it's been set to something truthy
if (_key) {
restOpts.url = restOpts.url + '&key=' + _key;
}

// Only include the token if it's been set to something truthy
if (_token) {
restOpts.data.token = _token;
restOpts.url = restOpts.url + '&token=' + _token;
}

if (params != null) {
extend(restOpts.data, params);
extend(restOpts.options.body, params);
}

return ajax(restOpts);
Expand Down Expand Up @@ -543,7 +553,6 @@ var TrelloClient = function TrelloClient(props) {
}

window.Trello = Trello;

var localStorage = window.localStorage;


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-trello-client",
"version": "1.1.4",
"version": "1.1.6",
"description": "\"This is a simple and lightweight React plugin to have a clean Trello client without using jQuery or any other additional libraries.\"",
"main": "dist/index.js",
"scripts": {
Expand Down
48 changes: 27 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,11 @@ const TrelloClient = (props) => {

}

const ajax = function (restOptions) {
return fetch(restOptions.url, {
method: restOptions.type,
headers: {
'Content-Type': 'application/json',
},
body: restOptions.type === 'GET' ? null : JSON.stringify(restOptions.data)
})
.then(response => response)
.catch(error => error)
const ajax = (restOptions) => {
return fetch(restOptions.url, restOptions.options)
.then(response => response.json())
.then(data => restOptions.success(data))
.catch(error => restOptions.error(error))
}

const authorizeURL = function (args) {
Expand Down Expand Up @@ -169,27 +164,39 @@ const TrelloClient = (props) => {
// error - Function to call when the request fails
rest(method, ...args) {
const [path, params, success, error] = parseRestArgs(args);

const restOpts = {
url: `${baseURL}${path}`,
type: method,
data: {},
dataType: 'json',
var restOpts = {
url: '' + baseURL + path + '?',
options: {
method,
mode: 'cors',
referrerPolicy: 'no-referrer',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
},
success,
error,
error
// Only include the key if it's been set to something truthy
}

// Only include body if method is not GET
if (method != 'GET') {
restOpts.options.body = {}
}

// Only include the key if it's been set to something truthy
if (key) {
restOpts.data.key = key;
restOpts.url = `${restOpts.url}&key=${key}`
}

// Only include the token if it's been set to something truthy
if (token) {
restOpts.data.token = token;
restOpts.url = `${restOpts.url}&token=${token}`
}

if (params != null) {
extend(restOpts.data, params);
extend(restOpts.options.body, params);
}

return ajax(restOpts);
Expand Down Expand Up @@ -465,7 +472,6 @@ const TrelloClient = (props) => {
}

window.Trello = Trello;

const { localStorage } = window;

if (localStorage != null) {
Expand Down

0 comments on commit 0eb0c3d

Please sign in to comment.