Skip to content

michaeljhicks/whether_sweater

Repository files navigation

Whether Sweater

languages rspec simplecov All Contributors

Description

Sweater Weather is a BE application that is designed to return desired weather conditions for a specific area. The current weather, a five day forecast, and a 48 hour forecast are all available. Directions from one location to another are also available. By combining the two, Sweater Weather is able to geocode a destination location based on its name, find the route to that destination, and also return what the current weather conditions will be upon arrival of the desired destination. Sweater weather consumes data from an active weather API, an active mapquest API, and the Unsplash photo API. By creating endpoints in a new API, Whether Sweater is able to serialize, and send data to the FE team, ssatisfying their needs for their application.

APIs Used

Learning Goals

  • Create a functioning BE API with new endpoints through the consumption and exposure of other API endpoints
  • Follow SOA convention
  • Create new endpoints
  • Use serializers to package, and send JSON responses
  • Implement sessions after user sign in
  • Test API exposure
  • Test JSON response of newsly created endpoints
  • Combine the consumption of multiple APIs for a single JSON response

Versions

  • Ruby 2.7.2
  • Rails 7.0.3

Gems

  #Global Scope 
  gem 'bcrypt', '~> 3.1.7'
  gem 'faraday'
  gem 'jsonapi-serializer'
  gem 'figaro'
  
  #group :development, :test
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rspec-rails'
  gem 'pry'
  gem 'faker'
  gem 'simplecov'
  gem 'factory_bot_rails'
  
  #group :test
  gem 'capybara'
  gem 'launchy'
  gem 'shoulda-matchers'
  gem 'simplecov'
  gem 'vcr'
  gem 'webmock'

Local Setup

  1. Fork & Clone the repo
$ git clone git@github.com:michaeljhicks/whether_sweater.git
  1. Navigate to the directory
$ cd whether_sweater
  1. Install gem packages:
$ bundle install
  1. Update gem packages:
$ bundle update
  1. Run the migrations:
$ rails db:{drop,create,migrate,seed}

Test Suite

To properly run the test suite, you will need to follow the below instructions and run the following commands in terminal:

  1. Navigate to the above mentioned API websites (three in total) and request a developer API key for each of the respective APIs. This allows you to access the data properly.
  2. Upon having been granted all required API keys and navigate to the whether_sweather/config/application.yml file.
  3. If you are unable to locate the /config/application.yml file in your IDE, run the command shell bundle exec figaro install In the terminal. The /config/application.yml should appear. If you are still having problems, please references the Figaro documentation as shown below.
  4. Add your API keys in this format at the bottom of the ruby/config/application.yml file:
  • mapquest_api_key: 'api_key'
  • weather_api_key: 'api_key'
  • unsplash_api_key: 'api_key'
  1. Once you have the API keys in place, you can run the entire test suite! To do this simply run the command bundle exec rspec
  2. Upon executing the initial test suite, you will notice it's running at a concerningly glacial pace. This is because of of the suite actually hitting the real API endpoints. However thanks to VCR, this initial run is the only slower execution whereby VCR records the API response on first execution, and then stores the responses in a file known as a 'cassette' to reduce API rate limits, thus optimizing the test suite performance.

Created End Points

  • GET /api/v1/forecast?location=denver,co
  • GET /api/v1backgrounds?location=denver,co
  • POST /api/v1/users JSON Params Passed for User create
  • key: email value: your_email@here
  • key: password value: password
  • key: password_confirmation value: password
  • POST /api/v1/sessions JSON Params Passed for User login/Session Creation
  • key: email value: your_email@here
  • key: password value: 'Password123"
  • key: password_confirmation value: 'Password123'
  • POST /api/v1/road_trip
  • *JSON Params Passed for Road Trip Creation
  • key: origin value:Denver,CO
  • key: destination value: Pueblo,CO
  • key: api_key value: "your api key here"

Exposed End Points

All string interpolated values are dynamic values being passed in the code as query params. The param "imperial" on the weather API is the preferred form of measurement. API is metric by defualt. End Points are as they appear in the API services in the code.

  • GET http://www.mapquestapi.com/geocoding/v1/address?location=#{location}
  • GET http://www.mapquestapi.com/directions/v2/route?from=#{trip_params[:from]}&to=#{trip_params[:to]}
  • GET https://api.openweathermap.org/data/2.5/onecall?lat=#{lat}&lon=#{lng}&units=imperial
  • GET https://api.unsplash.com/search/photos?page=1&query=#{city}")

Schema

Screen Shot 2022-06-15 at 8 18 41 AM

Project Contributors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors