Skip to content

Commit

Permalink
plugged api
Browse files Browse the repository at this point in the history
  • Loading branch information
bdhsu committed Jan 12, 2019
1 parent 8c85787 commit b2c5262
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"normalize": "^0.3.1",
"normalize.css": "^8.0.1",
"react": "^16.7.0",
Expand Down
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import logo from './logo.svg';
import 'normalize.css';
import './App.css';
import api from './utils/api';
import PropTypes from 'prop-types';

class LocationInput extends Component {
Expand Down Expand Up @@ -73,12 +74,13 @@ class App extends Component {
}
handleSubmit(location) {
console.log('location: ' + location);

api.fetchCurrentWeather(location);
// this.setState(_ => {
//
// });
}


render() {
return (
<div className="App">
Expand Down
15 changes: 15 additions & 0 deletions src/utils/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var axios = require('axios');

var apikey = "8fad34166684286360dc6d77073bd5e5";
var params = "&APPID=" + apikey;

module.exports = {
fetchCurrentWeather: function(location) {
var link = window.encodeURI("http://api.openweathermap.org/data/2.5/weather?q=" + location + params);
return axios.get(link)
.then(function(results) {
console.log('results: ' + results);
console.log(JSON.stringify(results));
});
}
}

0 comments on commit b2c5262

Please sign in to comment.