Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
added a /services/weather route
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekTandy committed Oct 23, 2016
1 parent 37e719d commit 188f063
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ router.use('/shelters', require('./shelters'))
router.get('/program-types', require('./programs/programTypes'))
router.use('/programs', require('./programs'))

router.use('/weather', require('./weather'))

router.use('/notifications', require('./sms'))

// make sure /services sends a 404
Expand Down
3 changes: 2 additions & 1 deletion services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
searchHost: 'search-ocelot-6tqsxtl7pweckdfvle6ty47yiu.us-east-1.es.amazonaws.com',
searchUserAccessKeyId: process.env.SEARCH_USER_ACCESS_KEY_ID,
searchUserSecretAccessKey: process.env.SEARCH_USER_SECRET_ACCESS_KEY,
googleMapsKey: 'AIzaSyBajQBc7MPg6vMpNoFYnA4zWSb6EqwXWjg'
googleMapsKey: 'AIzaSyBajQBc7MPg6vMpNoFYnA4zWSb6EqwXWjg',
darklyKey: 'eb66b65972855bd4018ad52880c3378d'
}
14 changes: 14 additions & 0 deletions services/weather/getForecast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const agent = require('../../src/agent')
const { darklyKey } = require('../config')

const apiUrl = 'https://api.darksky.net/forecast'
const locationForApi = '38.633665,-90.195588'

const getForecast = () =>
agent.get(`${apiUrl}/${darklyKey}/${locationForApi}`)
.then(({ body }) => {
console.log('get forecast', body)
return body
})

module.exports = getForecast
11 changes: 11 additions & 0 deletions services/weather/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express')
const router = express.Router()
const getForecast = require('./getForecast')

router.get('/', (req, res, next) =>
getForecast()
.then(forecast => res.json(forecast))
.catch(next)
)

module.exports = router

0 comments on commit 188f063

Please sign in to comment.