Giter Club home page Giter Club logo

sweater_weather's Introduction

Sweater Weather

An API Rails App Project

Heroku

Build Status Badge Maintainability

Backend Development - Cohort 2006

Nico Rithner - 2020

Contact Information

         

Table of Contents

Overview

Sweater Weather is a Turing Module 3 project that provides the developer with a series of wireframes and instructions to produce endpoints that the project front-end developers (ficticious) could use. Using request such as GET /api/v1/forecast?location=denver,co the app can

  • retrieve the weather for a city,
  • retrieve a background image for that city,
  • register and user,
  • log an existing user and
  • plan a road trip (duration of the trip and weather at arrival)


sample wireframe

The projects asks for T.D.D. (test driven development) to develop the project functionality. Gems such as simplecov, webmock, and vcr, among others help us drive this process.
The testing requirements expect 'sad path' path testing along with functionality. This means to test for when the user doesn't do what is expected. For example, entering the wrong password or omitting the confirmation password.


sample json

back to top


Specifications

This project runs on Rails: 6.0.34 and Ruby: 2.5.3

To check your current versions, run:

$ ruby -v
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin19]
$ rails -v
Rails 6.0.3.4


Gems

This project uses the following additional gems:
You can find the most current version at Rubygems.org

Production

  • bcrypt: The bcrypt Ruby gem provides a simple wrapper for safely handling passwords.
  • faraday: HTTP/REST API client library
  • figaro: Simple, Heroku-friendly Rails app configuration using ENV and a single YAML file
  • jsonapi-serializer: Fast, simple and easy to use JSON:API serialization library (also known as fast_jsonapi).

Test and Development

  • pry: Pry is a runtime developer console and IRB alternative that attempts to bring REPL driven programming to the Ruby language
  • rspec-rails: rspec-rails is a testing framework for Rails 5+
  • rubocop: RuboCop is a Ruby code style checking and code formatting tool. It aims to enforce the community-driven Ruby Style Guide.
  • simplecov: Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
  • shoulda-matchers: Shoulda Matchers provides RSpec compatible one-liners to test common Rails functionality
  • webmock: WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.
  • vcr: Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests

APIs

In this project we used the following APIs:

  • OpenWeather: Weather information for any location on the globe. Some apis are paid. We used OneCall
  • MapQuest Developer: Mapping, Geocoding, Directions, and Search provider. Free and paid APIs
  • Pixabay Developer API: Access to over 2.1 million photos, illustrations, vector graphics, and videos.

back to top


Installation

Fork and Clone The Repo

Fork this Github repository: Sweater_weather

Clone your 'Sweater_weather' repository using SSH:

  $ git clone [email protected]:<your-github-username>/Sweater_weather.git

Initial Installation

In the command line run the following commands in order:

  1. $ rails db:{create,migrate}
  2. $ rails generate rspec:install
  3. $ bundle exec figaro install
  4. $ bundle install

Set Up API Keys

Find the application.yml file in the config folder and add your API keys example:

MAP_API_KEY: <api key here without strings>
WEATHER_API_KEY: <api key here without strings>
IMAGE_API_KEY: <api key here without strings>

back to top


Testing

RSpec

We can check the test on the spec folder by running rspec

In the command line run

$ bundle exec rspec

All tests should be passing.

If you get a nil or a vcr error, you may need to delete vcr_cassettes in the /spec/fixtures folder.

Simplecov

After running the tests simplecov gathers the coverage and neatly reports them in an html page.

In the command line you should see something like this:

Coverage report generated for RSpec to /Users/nicomacbook/turing/3module/sweater_weather/coverage. 196 / 196 LOC (100.0%) covered.


sample rspec/simplecov terminal output

Rubocop

Rubocop helps us clean up the code.

In the command line run:

$ rubocop

Rubocop will highlight styling errors - according to rails standards - and make recommendations on how to improve the code.

back to top


API Endpoints

The exposing these endpoints is the chief purpose of this application. To test this out your self in your computer follow the instructions below.

Expose the endpoints in Postman

  1. Open the terminal in your computer and navigate to where sweater_weather is located and cd into it.
  2. Once in the directory run the following command in your terminal: $ rails server
  3. Open Postman and type the following in the address bar: http://localhost:3000/
  4. Add the requests below to call each endpoint. example: http://localhost:3000/api/v1/backgrounds?location=denver,co
  5. Change the verb to one corresponding to the call for example: Post
  6. Send your request by clicking Send

Notice that some of the call require you add the paramteres to the body. In postman:

  1. Click on body
  2. Select raw
  3. Select json (by default show as text)


sample Postman setup

Forecast

Retrieve weather for a city

Shows the current, hourly, and daily forecast for the location queried. It accepts city and state as parameters.

Request:

  • Content-Type: application/json
  • Accept: application/json

get api/v1/forecast?location=denver, co



sample forecast request

Test it Out In Postman

Run in Postman

back to top

Background Image

Retrieves background Image for the City

Using Pixabay's API, retrieves an image that is related to the searched location and outputs a serialized json.

Request:

  • Content-Type: application/json
  • Accept: application/json

get api/v1/backgrounds?location=denver, co



sample background request

Test it Out In Postman

Run in Postman

back to top

User Registration

Registers a new user

Registers a new user and generates a unique API key for the user

Request:

  • Content-Type: application/json
  • Accept: application/json

The params are passed on in the body of the request not in the uri:

{
  "email": "[email protected]",
  "password": "password",
  "password_confirmation": "password"
}

post /api/v1/users



sample users request

back to top

Test it Out In Postman

Run in Postman

User Login

Authenticates a User

This request authenticates a user and logs it into the application

Request:

  • Content-Type: application/json
  • Accept: application/json
{
  "email": "[email protected]",
  "password": "password"
}

post /api/v1/sessions



sample login request

Test it Out In Postman

Run in Postman

back to top

Road Trip

Returns estimated travel time and arrival forecast for a road trip

This request produces trip duration and destination weather forecast at eta.

Request:

  • Content-Type: application/json
  • Accept: application/json
{
  "origin": "Denver,CO",
  "destination": "Pueblo,CO",
  "api_key": "jgn983hy48thw9begh98h4539h4"
}

post /api/v1/road_trip



sample road_trip request

Test it Out In Postman

Run in Postman

back to top


Heroku API Endpoints

This api-application has been deployed to Heroku. You can test the endpoints in postman by following the link below and running postman in your browser.

Run in Postman

If you have postman installed locally you can run it in the app directly

https://sweater-weather-api-nico.herokuapp.com/api/v1/<type here the desired endpoint>



Heroku-app user registration request

back to top

sweater_weather's People

Contributors

dependabot[bot] avatar nicorithner avatar

Watchers

 avatar

sweater_weather's Issues

1b. Background Image for the City

  • Implement a new API service to use the name of the city to get the URL of an appropriate background image.
  • Give picture credit if the provide it requires it.

Extension:

  • Determine the time of day and current weather and include that in your search; for example, searching for “denver evening snow” might return a far more interesting result

Story 3 Refactor

Check and refactor:

  • that rubrics are met
  • test completion
  • code quality
  • sad path where needed

Sad path for image querying

Add sad path for image querying. If no images are returned a json with a body message "no images available for this query' is returned along with the appropriate status (406? or 204?)

  • There is sad path for no image available
  • Tests updated for sad path.

Overview

Write overview to about the project

  • Explains what the app does.
  • Explains what learning objectives are
  • Reference to Turing's project instruction's and rubric.

API endpoints with screenshots

List the endpoints with text code sample - like in the instructions - with succinct description:

  • Forecast
  • Background Image
  • User Registration
  • User Login
  • Road trip

Roadtrip Request Sad Path

Blank destination and blank origin tests are passing with correct http message but they are not working in postman.

  • Fix sad path origin blank
  • Fix sad path destination blank

Table of content

Create a table of content with links to each H2 heading

  • includes each heading
  • completed

Specifications

Display specs in more detail.
What ruby and rails version, what gems. Add brief tag next to each gem to say what the gem does - short sentence. what APIs did I use.

  • Ruby, Rails version
  • Gems list
    • gems have succinct description.
  • APIs list.
    • titles are links to the apis developers' page

Story 2 Refactor

Check and refactor:

  • that rubrics are met
  • test completion
  • code quality
  • sad path where needed

  • email already in use

Road trip facade

The facade will run:

  • MapService.get_route(origin, destination) to get the trip duration
  • Calculate ETA (estimated time of arrival) using Time.now as starting point (self.find_eta)
  • MapService.get_coordinates(location) to get the coordinates to obtain the weather at ETA
  • Create new instance of RoadTrip with trip_data
    @user.roadtrips.create(origin: route.origin, destination: route.destination, duration: route.duration, temperature: destination_weather.temp, description: destination_weather.description)

Install Gems and configure

Gems

Install gems:

General

  • faraday
  • figaro
  • jsonapi-serializer
  • rack-cors

Development

Test

  • capybara
  • factory_bot_rails
  • faker
  • launchy
  • pry
  • rspec-rails. Configure.
  • simplecov. Configure.
  • shoulda-matchers. Configure.
  • webmock
  • vcr. Configure.

Development

  • rubocop. Configure.

Store city/state coordinates query to the database.

Create table 'locations'
city --> string
state --> string
lat --> numeric
lng --> numeric

When a query is made we check first whether the city/state combination exist in the database. If it does we use those coordinates. If it doesn't we get them making the api call to mapquest and then we create a new location object and save it to the database for future use.

Road trip routes and controller

Create road trip routes and controller

  • Create road_trip routes

  • Create road_trip_controller, action 'create'

    • create action happy path
    • create action sad path

1a. Retrieve weather for a city

Requirements:

  • Endpoint needs to use the city and state from the GET request’s query parameter and send it to MapQuest’s Geocoding API to retrieve the latitude and longitude for the city.

    • Use of the MapQuest’s Geocoding API is a hard requirement.
  • Retrieve forecast data from the OpenWeather One Call API using the latitude and longitude from MapQuest.

  • Testing should look for more than just the presence of attribute fields in the response.

    • Testing should also determine which fields should NOT be present. (don’t send unnecessary data)

Sad path for impossible trips

If we attempt to the the trip duration for a destination overseas we should get trip not possible by car.

  • Add sad path for trips that are not possible.

example: origin: 'New York, NY', destination: 'London, UK'

Story 4 Refactor

Check and refactor:

  • that rubrics are met
  • test completion
  • code quality
  • sad path where needed

Upgrade image querying capabilities

Upgrade image querying to include other params to have a more specific picture

  • Can query for 'morning', 'afternoon', 'evening'
  • Can query for things like 'skyline', 'parks', etc

Note:
Nov/13/2020. Most apis I find return a lot of bad images that wouldn't be relevant to query.
For example 'denver evening snow' gets me a chicago picture, or someone swimming butterfly...

User Login

Story 3

User Login

  • A successful request returns the user’s api key.
  • An unsuccessful request returns an appropriate 400-level status code and body with a description of why the request wasn’t successful
    Potential reasons a request would fail:
    • credentials are bad
    • empty field

Request:

$ POST /api/v1/sessions
Content-Type: application/json
Accept: application/json

{
  "email": "[email protected]",
  "password": "password"
}

Create road_trip model and spec

  • Create model specs validations and relationships
    road_trip belongs to user, a user has_many road_trips
  • Create a road_trip model to store trip data in the database
    table road_trips
    rails g migration CreateRoadTrips user:references origin destination duration temperature description

Story 1a Refactor

Check and refactor:

  • that rubrics are met
  • test completion
  • code quality
  • sad path where needed

User registration

Create

  • Users request spec
  • Users routes
  • Users controller
    • Users create
      • Create user
      • Render json
        • json body
        • status 201
  • User database
  • Registration serializer

Installation instructions

Explain how to fork, clone, basic installation including gems and how to run the tests.

  • Explanation on how to fork
  • Explanation on how to clone
  • Explanation on how to do the basic installation
    • rails db:{create,migrate}
    • Gemfile: Rspec -> rails generate rspec:install (config brief explanation? ref to docs?)
    • Gemfile: Figaro -> bundle exec figaro install (config brief explanation? ref to docs?)
    • Gemfile: All other gems
  • Explanation on how to run the tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.