Sweater Weather API consumes external API services and exposes endpoints for a weather application frontend.
This Rails Api is the final solo project during MOD 3 at Turing School of Software and Design
Features:
- Basic authentication for user registration and login.
- Issuing a required API key upon registration.
- Search current, 5 day, and next 8 hours weather forecasts for a location in one call.
- Find a relevant background image for a location
- Plan a road trip between two locations. Receive estimated travel time and a weather report for the destination based on ETA.
The external services consumed are:
- Search weather forecast by location
GET /api/v1/forecast?location=atlanta,ga
{
"data": {
"id": "null",
"type": "forecast",
"attributes": {
"current_weather": {
"datetime": "2022-06-14T21:10:36.000-04:00",
"sunrise": "2022-06-14T06:26:34.000-04:00",
"sunset": "2022-06-14T20:49:16.000-04:00",
"temperature": 85.06,
"feels_like": 93.63,
"humidity": 72,
"uvi": 0,
"visibility": 10000,
"conditions": "scattered clouds",
"icon": "03n"
},
"daily_weather": [
{
"date": "2022-06-14",
"sunrise": "2022-06-14T06:26:34.000-04:00",
"sunset": "2022-06-14T20:49:16.000-04:00",
"max_temp": 97.09,
"min_temp": 79.11,
"conditions": "light rain",
"icon": "10d"
},
{...} etc (5 days total)
],
"hourly_weather": [
{
"time": "21:00:00",
"temperature": 85.06,
"conditions": "light rain",
"icon": "10n"
},
{...} etc (8 hours total)
]
}
}
}
- Find a background image for a location
GET /api/v1/backgrounds?location=atlanta,ga
{
"data": {
"id": "null",
"type": "image",
"attributes": {
"image": {
"name": "Atlanta, Georgia, USA Skyline | Legal Executive Institute",
"image_url": "http://www.legalexecutiveinstitute.com/wp-content/uploads/2019/02/SEMA19-Image.jpeg",
"credit": {
"source": "http://www.legalexecutiveinstitute.com/events/the-15th-annual-southeastern-ma-private-equity-forum/atlanta-georgia-usa-skyline/",
"author": "Legal Executive Institute",
"logo": "https://www.bing.com/th?id=ODF.Vr1XrhRx0qOyTZHcVP930Q&pid=Api"
}
}
}
}
}
- Register User
POST api/v1/users
Content-Type: application/json
Accept: application/json
body: {
"email": "[email protected]",
"password": "password",
"password_confirmation": "password"
}
{
"data": {
"id": "1",
"type": "users",
"attributes": {
"email": "[email protected]",
"api_key": "SOME API KEY"
}
}
}
- Login User
POST api/v1/sessions
Content-Type: application/json
Accept: application/json
body: {
"email": "[email protected]",
"password": "password"
}
{
"data": {
"id": "1",
"type": "users",
"attributes": {
"email": "[email protected]",
"api_key": "SOME API KEY"
}
}
}
- Road Trip
POST /api/v1/road_trip
Content-Type: application/json
Accept: application/json
body: {
"origin": "Atlanta, GA",
"destination": "Cincinnati, OH",
"api_key": "SOME API KEY"
}
{
"data": {
"id": "null",
"type": "roadtrip",
"attributes": {
"start_city": "Atlanta, GA",
"end_city": "Cincinnati, OH",
"travel_time": "7 hours, 4 minutes",
"weather_at_eta": {
"temperature": 74.3,
"conditions": "clear sky"
}
}
}
}
OpenWeather One Call API follow instructions to get API key for v2.5.
MapQuest Geocoding API follow instructions to get API key.
MapQuest Directions API you only need the one key for MapQuest.
Microsoft Bing Image Search You need to set up a API key for Bing through Azure.
-
Clone this repository on your local machine.
-
Install required Gems utilizing Bundler:
- In terminal, use Bundler to install any missing Gems. If Bundler is not installed, first run the following command.
$ gem install bundler
- If Bundler is already installed or after it has been installed, run the following command.
$ bundle install
- Database Migration
- Before using the web application you will need to setup your databases locally by running the following command
$ rails db:{drop,create,migrate}
- Setup Figaro
$ bundle exec figaro install
-
That will create an
config/application.yml
file. -
Add your api keys to new this new file.
#config/application.yml
mapquest_key: <your mapquest key here>
open_weather_key: <your open weather key here>
bing_images_key: <your azure key here>
- Startup and Access
-
Start the server locally.
-
Start server
$ rails s
- Open Postman and import this collection to get started.