SweaterWhether exposes several endpoints related to weather forecasting and road trip length. This app is built to support a hypothetical front-end team who have provided API contracts and specs.
- Thanks to Pexels Image Search API for background image endpoint
- Thanks to OpenWeather OneCall API for weather forecast endpoints
To get the web application running, please fork and clone down the repo.
git clone <your@github.account:SweaterWhether.git>
To run this application you will need Ruby 2.5.3 and Rails 5.2.5
- Install the gem packages
bundle install
- Generate your local
application.ymlfile to store the api keys and confirm it was added to your.gitignorebundle exec figaro install
RSpec testing suite is utilized for testing this application.
- Run the RSpec suite to ensure everything is passing as expected
bundle exec rspec
- Required query params:
location
GET /api/v1/forecast?location={loc}
{
"data": {
"id": null,
"type": "forecast",
"attributes": {
"current_weather": {
"datetime": "2021-04-27T17:13:24.000-06:00",
"sunrise": "2021-04-27T06:14:08.000-06:00",
"sunset": "2021-04-27T20:10:38.000-06:00",
"temperature": 48.74,
"feels_like": 46.99,
"humidity": 61,
"uvi": 1.91,
"visibility": 10000,
"conditions": "overcast clouds",
"icon": "04d"
},
"daily_weather": [
{
"date": "2021-04-27",
"sunrise": "2021-04-27T06:14:08.000-06:00",
"sunset": "2021-04-27T20:10:38.000-06:00",
"max_temp": 48.78,
"min_temp": 36.79,
"conditions": "rain and snow",
"icon": "13d"
},
{
"date": "2021-04-28",
"sunrise": "2021-04-28T06:12:42.000-06:00",
"sunset": "2021-04-28T20:11:48.000-06:00",
"max_temp": 60.91,
"min_temp": 37.89,
"conditions": "overcast clouds",
"icon": "04d"
},
{
"date": "2021-04-29",
"sunrise": "2021-04-29T06:11:18.000-06:00",
"sunset": "2021-04-29T20:12:57.000-06:00",
"max_temp": 68.52,
"min_temp": 44.15,
"conditions": "few clouds",
"icon": "02d"
},
{
"date": "2021-04-30",
"sunrise": "2021-04-30T06:09:55.000-06:00",
"sunset": "2021-04-30T20:14:06.000-06:00",
"max_temp": 75.51,
"min_temp": 51.96,
"conditions": "overcast clouds",
"icon": "04d"
},
{
"date": "2021-05-01",
"sunrise": "2021-05-01T06:08:33.000-06:00",
"sunset": "2021-05-01T20:15:15.000-06:00",
"max_temp": 69.93,
"min_temp": 55.02,
"conditions": "overcast clouds",
"icon": "04d"
}
],
"hourly_weather": [
{
"time": "17:00:00",
"temperature": 48.74,
"conditions": "overcast clouds",
"icon": "04d"
},
{
"time": "18:00:00",
"temperature": 48.78,
"conditions": "overcast clouds",
"icon": "04d"
},
{
"time": "19:00:00",
"temperature": 48.52,
"conditions": "broken clouds",
"icon": "04d"
},
{
"time": "20:00:00",
"temperature": 46.76,
"conditions": "overcast clouds",
"icon": "04d"
},
{
"time": "21:00:00",
"temperature": 44.1,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "22:00:00",
"temperature": 42.78,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "23:00:00",
"temperature": 41.65,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "00:00:00",
"temperature": 40.91,
"conditions": "scattered clouds",
"icon": "03n"
}
]
}
}
}- Required query params:
location
GET /api/v1/backgrounds?location={loc}
{
"data": {
"id": null,
"type": "image",
"attributes": {
"url": "https://www.pexels.com/photo/wide-angle-photography-of-city-near-body-of-water-702343/",
"photographer": "Anon",
"photographer_url": "https://www.pexels.com/@anon-213834",
"src": "https://images.pexels.com/photos/702343/pexels-photo-702343.jpeg",
"credit": "All image credit goes to Pexels.com and the photographer. This is an educational project only."
}
}
}- Required JSON body:
{
"email": "xx@beep.com",
"password": "flame",
"password_confirmation": "flame"
}POST /api/v1/users
{
"data": {
"id": "3",
"type": "users",
"attributes": {
"email": "xx@beep.com",
"api_key": "c7dbb4533fb8fb7b8c44"
}
}
}- Required JSON body:
{
"email": "xx@beep.com",
"password": "flame",
}POST /api/v1/sessions
{
"data": {
"id": "3",
"type": "users",
"attributes": {
"email": "xx@beep.com",
"api_key": "c7dbb4533fb8fb7b8c44"
}
}
}- Required JSON body:
{
"origin": "denver, co",
"destination": "fort myers, fl",
"api_key": "c7dbb4533fb8fb7b8c44"
}POST /api/v1/sessions
{
"data": {
"id": null,
"type": "roadtrip",
"attributes": {
"start_city": "denver, co",
"end_city": "fort myers, fl",
"travel_time": "29 hours, 2 minutes",
"weather_at_eta": {
"temperature": 72.66,
"conditions": "scattered clouds"
}
}
}
}- Rails 5.2.5
- Ruby 2.5.3
- RSpec 3.10.0
- Rbev 1.1.2