Sweater Weather is a backend application that exposes a number of external APIs reformatted to provide a simpler service for a hypothetical front end app to consume.
- Fork and Clone the repo
- Install gem packages:
$ bundle install
- Setup the database:
$ rails db:{create,migrate}
- Sign up for API keys from the list below. Wait! How do I sign up for an API key?? It's going to be slightly different for each website, but you are essentially looking for something in the documentation where you can sign up for an account.
note One API key will suffice for both MapQuest endpoints. The links provided will take you to the respective documentation pages where you can sign up to get an API key for your device.
- MapQuest Geocoding API here
- MapQuest Directions API here
- OpenWeather One Call API here
- Unsplash here
- From the command line, run the following:
$ bundle exec figaro install
- In the command line, run
$ atom config/application.yml
to open up your file. If using a different text editor, replace the word "atom" with the proper command for your text editor. - Copy the following code and replace 'YOUR-API-KEY' with their corresponding credentials:
mapquest_key: 'YOUR-API-KEY'
weather_key: 'YOUR-API-KEY'
unsplash_key: 'YOUR-API-KEY'
Request
GET /api/v1/forecast?location=denver,co
Response
{
"data": {
"id": null,
"type": "forecast",
"attributes": {
"current_weather": {
"datetime": "2022-06-07 22:32:53 -0700",
"sunrise": "2022-06-07 04:32:14 -0700",
"sunset": "2022-06-07 19:25:42 -0700",
"temperature": 58.6,
"feels_like": 57.16,
"humidity": 64,
"uvi": 0,
"visibility": 10000,
"conditions": "broken clouds",
"icon": "04n"
},
"daily_weather": [
{
"date": "2022-06-07",
"sunrise": "2022-06-07 04:32:14 -0700",
"sunset": "2022-06-07 19:25:42 -0700",
"max_temp": 80.56,
"min_temp": 55.71,
"conditions": "light rain",
"icon": "10d"
},
{
"date": "2022-06-08",
"sunrise": "2022-06-08 04:32:01 -0700",
"sunset": "2022-06-08 19:26:16 -0700",
"max_temp": 81.36,
"min_temp": 55.85,
"conditions": "scattered clouds",
"icon": "03d"
},
{
"date": "2022-06-09",
"sunrise": "2022-06-09 04:31:51 -0700",
"sunset": "2022-06-09 19:26:49 -0700",
"max_temp": 90.37,
"min_temp": 63.5,
"conditions": "overcast clouds",
"icon": "04d"
},
{
"date": "2022-06-10",
"sunrise": "2022-06-10 04:31:42 -0700",
"sunset": "2022-06-10 19:27:21 -0700",
"max_temp": 91.92,
"min_temp": 63.21,
"conditions": "scattered clouds",
"icon": "03d"
},
{
"date": "2022-06-11",
"sunrise": "2022-06-11 04:31:35 -0700",
"sunset": "2022-06-11 19:27:50 -0700",
"max_temp": 92.66,
"min_temp": 69.24,
"conditions": "clear sky",
"icon": "01d"
}
],
"hourly_weather": [
{
"time": "22:00:00",
"temperature": 59.65,
"conditions": "light rain",
"icon": "10n"
},
{
"time": "23:00:00",
"temperature": 58.6,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "00:00:00",
"temperature": 58.62,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "01:00:00",
"temperature": 57.88,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "02:00:00",
"temperature": 57.29,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "03:00:00",
"temperature": 56.52,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "04:00:00",
"temperature": 55.85,
"conditions": "broken clouds",
"icon": "04n"
},
{
"time": "05:00:00",
"temperature": 56.12,
"conditions": "broken clouds",
"icon": "04d"
}
]
}
}
}
Request
GET /api/v1/backgrounds?location=sacramento
Response
{
"data": {
"type": "image",
"id": null,
"attributes": {
"image": {
"location": "Sacramento ",
"image_url": "https://images.unsplash.com/photo-1606188476311-f943475a7e1f?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjIxODV8MHwxfHNlYXJjaHwxfHxzYWNyYW1lbnRvfGVufDB8fHx8MTY1NDY2NzA4Nw&ixlib=rb-1.2.1&q=80",
"credit": {
"source": "unsplash.com",
"author": "Stephen Leonardi"
}
}
}
}
}
Request
POST /api/v1/users
Request body:
{
"email": "[email protected]",
"password": "password",
"password_confirmation": "password"
}
Response
{
"data": {
"type": "users",
"id": "1",
"attributes": {
"email": "[email protected]",
"api_key": "jgn983hy48thw9begh98h4539h4"
}
}
}
Request
POST /api/v1/sessions
Request body:
{
"email": "[email protected]",
"password": "password"
}
Response
{
"data": {
"type": "users",
"id": "1",
"attributes": {
"email": "[email protected]",
"api_key": "jgn983hy48thw9begh98h4539h4"
}
}
}
Request
POST /api/v1/road_trip
Request body:
{
"origin": "Denver,CO",
"destination": "Pueblo,CO",
"api_key": "jgn983hy48thw9begh98h4539h4"
}
Response
{
"data": {
"id": null,
"type": "roadtrip",
"attributes": {
"start_city": "Denver,CO",
"end_city": "Pueblo,CO",
"travel_time": "01:45:23",
"weather_at_eta": {
"temperature": 67.69,
"conditions": "clear sky"
}
}
}
}