mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
add encoding and camel to snake case conversion to FetchApiUtils
This commit is contained in:
parent
adb4c72253
commit
9c58fa321c
@ -10,15 +10,11 @@ class ArtworkListActions {
|
|||||||
|
|
||||||
fetchArtworkList() {
|
fetchArtworkList() {
|
||||||
ArtworkFetcher.fetch()
|
ArtworkFetcher.fetch()
|
||||||
/*.then((res) => {
|
|
||||||
return res.json();
|
|
||||||
})*/
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.actions.updateArtworkList(res.pieces);
|
this.actions.updateArtworkList(res.pieces);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
console.error('OMG cannot retrieve the artworks');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -10,8 +10,11 @@ class AscribeApp extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>ascribe all the things!</h1>
|
<header>ascribe</header>
|
||||||
|
<navigation>
|
||||||
<Link to="artworks">artworks</Link>
|
<Link to="artworks">artworks</Link>
|
||||||
|
</navigation>
|
||||||
|
|
||||||
<RouteHandler />
|
<RouteHandler />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -7,14 +7,14 @@ var ArtworkListFetcher = {
|
|||||||
fetch(page=1, pageSize=10) {
|
fetch(page=1, pageSize=10) {
|
||||||
let params = FetchApiUtils.argsToQueryParams({
|
let params = FetchApiUtils.argsToQueryParams({
|
||||||
page,
|
page,
|
||||||
'page_size': pageSize // this is kind of a bummer...
|
pageSize
|
||||||
});
|
});
|
||||||
|
|
||||||
return fetch(AppConstants.baseUrl + 'pieces/' + params, {
|
return fetch(AppConstants.baseUrl + 'pieces/' + params, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Basic ZGltaUBtYWlsaW5hdG9yLmNvbTowMDAwMDAwMDAw'
|
'Authorization': 'Basic ZGltaUBtYWlsaW5hdG9yLmNvbTowMDAwMDAwMDAw'
|
||||||
}
|
}
|
||||||
}).then((res) => { return res.json(); });
|
}).then((res) => res.json());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,6 +9,11 @@ let FetchApiUtils = {
|
|||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* and converts it to a query-parameter, which you can append to your URL.
|
* and converts it to a query-parameter, which you can append to your URL.
|
||||||
|
* The return looks like this:
|
||||||
|
*
|
||||||
|
* ?page=1&page_size=10
|
||||||
|
*
|
||||||
|
* CamelCase gets converted to snake_case!
|
||||||
*
|
*
|
||||||
* @param {[type]}
|
* @param {[type]}
|
||||||
* @return {[type]}
|
* @return {[type]}
|
||||||
@ -25,7 +30,9 @@ let FetchApiUtils = {
|
|||||||
s += '&';
|
s += '&';
|
||||||
}
|
}
|
||||||
|
|
||||||
return s + key + '=' + obj[key];
|
let snakeCaseKey = key.replace(/[A-Z]/, (match) => '_' + match.toLowerCase());
|
||||||
|
|
||||||
|
return s + snakeCaseKey + '=' + encodeURIComponent(obj[key]);
|
||||||
})
|
})
|
||||||
.join('');
|
.join('');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user