[add] fetch call to database

This commit is contained in:
Daniel
2017-09-02 23:28:57 -04:00
parent 9c0e77ab42
commit df8e32f1cb
4 changed files with 64 additions and 18 deletions

View File

@@ -1,18 +1,28 @@
import React from 'react';
import PropTypes from 'prop-types';
import URLS from '../URLS';
import 'whatwg-fetch';
const propTypes = {
children: PropTypes.element,
};
function Creatures({children}) {
return (
<div>
{children||
<div>test</div>
}
</div>
);
fetch(URLS.Creature_Overworld)
.then(function(response) {
return response.json();
}).then(function(json) {
console.log('parsed json', json.feed.entry);
}).catch(function(ex) {
console.log('parsing failed', ex);
})
return (
<div>
{children||
<div>test</div>
}
</div>
);
}
Creatures.propTypes = propTypes;

33
src/components/URLS.js Normal file
View File

@@ -0,0 +1,33 @@
import React from 'react';
class URLS {
static base_url = "https://spreadsheets.google.com/feeds/list/";
static data_format = "/od6/public/values?alt=json";
// + "/od6/public/basic?alt=json"; // Alternate data format
constructor() {}
static path(spreadsheetID) {
return URLS.base_url + spreadsheetID + URLS.data_format;
}
get Creature_Overworld() {
return URLS.path("1Z4_MmlV7uE34nLzrcxslqQKRwL4OBXNA15s7G8eteXU");
}
// Singleton
static instance = null;
static createInstance() {
var object = new URLS();
return object;
}
static getInstance() {
if (!URLS.instance) {
URLS.instance = URLS.createInstance();
}
return URLS.instance;
}
}
export default URLS.getInstance();