Built by Ruthie Rabinovitch: LinkedIn | Turing alumni portfolio
Continuous integration and deployment with CircleCI:
This repo serves as a solo, final project for Module 3 of Turing School of Software & Design's Back-End program. The submission of this project entailed a techincal presentation including a live demo and discussion regarding of code organization as well as happy and sad path test coverage.
Sweater Weather is the back-end of a hypothetical application for planning road trips. The app allows users to see the current weather as well as the forecasted weather at their destination. This repo exposes the API that satisfies the (hypothetical) front-end team’s requirements.
To follow OOP principles, this project uses a facade design pattern and also implements POROs - yielding skinnier controllers and DRYer code, better following SPR, and only sending objects to serializers.
- Expose an API that aggregates data from multiple external APIs:
road trip
endpoint aggregates data from three third party end points (MapQuest geocoding API, MapQuest directions API, and OpenWeather OneCall APIforecast
endpoint aggregates data from two third party endpoints (MapQuest geocoding API and OpenWeather OneCall API)
- Expose an API that requires an authentication token:
roadtrip
endpoint requires API key included in request body - Expose an API for CRUD functionality:
users
endpoint creates User records - Determine completion criteria based on the needs of other developers: each issue in my project board outlines implementation details and includes screenshots of relevant info provided by the "front end"
- Research, select, and consume an API based on your needs as a developer: Pexels API selected for
backgrounds
endpoint
- Implement sad path conditions and testing for
forecast
androad trip
endpoints when location, origin, or destination information cannot be found and when entered using unrecognizable format - DRY up
RoadTripsController
andSessionsController
error message conditionals - Background image extension
Version Requirements
- ruby 2.5.3
- rails 5.2
git clone [email protected]:rrabinovitch/sweater_weather.git
cd sweater_weather
bundle install
rails db:{create,migrate}
figaro install
(this will generate a gitignoredconfig/application.yml
file)- obtain API keys from the following services:
- MapQuest
- OpenWeather
- Pexels (click 'Get Started')
- add the API keys you obtained to
application.yml
:MAPQUEST_API_KEY: <your mapquest key> OPEN_WEATHER_API_KEY: <your openweather key> PEXELS_API_KEY: <your pexels key>
- run
rails s
and explore the endpoints below! - run the test suite:
bundle exec rspec
- base url:
- use https://sweaterweather-app.herokuapp.com/api/v1 without local setup, OR
- use localhost:3000/api/v1 and make sure to follow the local set up instructions above and run
rails s
before consuming these endpoints
- responses are JSON API 1.0 Compliant
- GET requests require params submitted via query params
- POST requests require params submitted via the request body
- measurement units
- temperature: Fahrenheit
- time: Unix UTC format
- humidity: percentage
- visitbility: meters
- precipitation: millimeters (combined value of rain and snow)
- road trip travel time: hours
Returns location info and current weather, as well as forecast info for the upcoming 8 hours and upcoming 5 days.
Request: GET localhost:3000/api/v1/forecast?location=<city,state>
Request: GET localhost:3000/api/v1/forecast?location=denver,co
Response body:
{
"data": {
"id": null,
"type": "forecast",
"attributes": {
"location": {
"coordinates": {
"lat": 39.738453,
"lng": -104.984853
},
"city": "Denver",
"state": "CO",
"country": "US"
},
"current": {
"datetime": 1600906634,
"temp": 78.85,
"description": "few clouds",
"feels_like": 73.78,
"humidity": 26,
"visibility": 10000,
"uv_index": 7.24,
"sunrise": 1600865338,
"sunset": 1600908912
},
"hourly": [
{
"datetime": 1600905600,
"temp": 78.85
},
{
"datetime": 1600909200,
"temp": 79.47
},
< six more hourly forecasts >
],
"daily": [
{
"datetime": 1600884000,
"description": "scattered clouds",
"precipitation": 0.0,
"high_temp": 83.48,
"low_temp": 67.48
},
{
"datetime": 1600970400,
"description": "scattered clouds",
"precipitation": 0.0,
"high_temp": 87.66,
"low_temp": 67.24
},
< three more daily forecasts >
]
}
}
}
Returns location parameter, image url, and image credit info.
Request: GET localhost:3000/api/v1/backgrounds?location=<city,state>
Request: GET localhost:3000/api/v1/backgrounds?location=denver,co
Response body:
{
"data": {
"id": null,
"type": "image",
"attributes": {
"location": "denver,co",
"image_url": "https://www.pexels.com/photo/photo-of-people-holding-each-other-s-hands-3184423/",
"credit": {
"source": "pexels.com",
"photographer": "fauxels"
}
}
}
}
Returns new user's id, email, and api key.
Request: POST localhost:3000/api/v1/users
- body must include
email
,password
, andpassword_confirmation
params - you will receive a 400 bad request error if an email is already in use, if there are any missing fields, and/or if the password fields do not match
Request: POST localhost:3000/api/v1/users
Request body:
{"email": "[email protected]",
"password": "password",
"password_confirmation": "password"}
Response body:
{
"data": {
"id": "1",
"type": "user",
"attributes": {
"email": "[email protected]",
"api_key": "8a32cb12-61bf-4746-8cab-118dcf6373c0"
}
}
}
Returns authorized user's id, email, and api key.
Request: POST localhost:3000/api/v1/sessions
- body must include
email
andpassword
params - you will receive a 401 unauthorized error if bad credentials are submitted
Request: POST localhost:3000/api/v1/sessions
Request body:
{"email": "[email protected]",
"password": "password"}
Response body:
{
"data": {
"id": "1",
"type": "user",
"attributes": {
"email": "[email protected]",
"api_key": "9167e13a-9fb2-49c9-8165-c64c2ff335b1"
}
}
}
Returns road trip info: origin, destination, travel time, forecast temperature, forecast description, and user that road trip was created by
Request: POST localhost:3000/api/v1/road_trip
- body must include
origin
,destination
, andapi_key
params - you will receive a 401 unauthorized error if bad credentials are submitted
Request: POST localhost:3000/api/v1/road_trip
Request body:
{"origin": "Denver, CO",
"destination": "Pueblo, CO",
"api_key": "9167e13a-9fb2-49c9-8165-c64c2ff335b1"}
Response body:
{
"data": {
"id": "1",
"type": "road_trip",
"attributes": {
"origin": "Denver, CO",
"destination": "Pueblo, CO",
"travel_time": 1.7,
"forecast_temp": 86,
"forecast_description": "clear sky",
"user_id": 1
}
}
}
Sweater Weather is written in Ruby with Ruby on Rails, uses a postgresql database, and is hosted on Heroku with continuous integration and deployment executed via CircleCI.
Language and Framework Versions
- ruby 2.5.3
- rails 5.2
Gems
- Faraday
- Figaro
- BCrypt
- FastJSON
Testing
- SimpleCov - yielding 100% coverage
- RSpec
- WebMock
- VCR
- ShouldaMatchers
- FactoryBot
Third Party APIs and Endpoints