Giter VIP home page Giter VIP logo

sweater_weather's Introduction

Sweater Weather AKA Whether Sweater?

Build Status

Sweater weather is a service oriented API meant to be the back end for a road trip planning app. Endpoints are available to get weather data and pictures for a location, register and login users, and fetch weather data for the time of arrival at trip destinations.


Getting Started:

To get started with the API, first clone this repo to your local machine, then run $ bundle install, $ figaro install and $ bundle exec rake db:{create,migrate}. To make use of the API, you will first need to obtain API keys for the MapQuest API, Unsplash API, and OpenWeather API, then add them to your application.yml file. Finally, run $ rails s to start your local server and start making calls to the available endpoints!


Endpoints

If you are running sweater weather with $ rails s, the root url will be localhost:3000.

The following headers should be included on all API calls:

Content-Type: application/json
Accept: application/json
Forecasts
GET /api/v1/forecast?location=<LOCATION>

Response:

{
  "data": {
    "id": null,
    "type": "forecast",
    "attributes": {
      "current_weather": {
        "datetime": "2020-09-30 13:27:03 -0600",
        "temperature": 79.4,
        etc
      },
      "daily_weather": [
        {
          "date": "2020-10-01",
          "sunrise": "2020-10-01 06:10:43 -0600",
          etc
        },
        {...} etc
      ],
      "hourly_weather": [
        {
          "time": "14:00:00",
          "wind_speed": "4 mph",
          "wind_direction": "from NW",
          etc
        },
        {...} etc
      ]
    }
  }
}
Location Backgrounds
GET /api/v1/backgrounds?location=<LOCATION>

Response:

{
  "data": {
    "type": "image",
    "id": null,
    "attributes": {
      "image": {
        "location": "...",
        "image_url": "..."
        "alt_description": "..."
        "credit": {...}
      }
    }
  }
}
User Registration
POST /api/v1/users
Body:
{
  "email": "[email protected]",
  "password": "password",
  "password_confirmation": "password"
}

Response:

{
  "data": {
    "type": "users",
    "id": "1",
    "attributes": {
      "email": "[email protected]",
      "api_key": "jgn983hy48thw9begh98h4539h4"
    }
  }
}
User Login
POST /api/v1/sessions
Body:
{
  "email": "[email protected]",
  "password": "password"
}

Response:

{
  "data": {
    "type": "users",
    "id": "1",
    "attributes": {
      "email": "[email protected]",
      "api_key": "jgn983hy48thw9begh98h4539h4"
    }
  }
}
Road Trip
POST /api/v1/road_trip
Body:
{
  "origin": "Denver,CO",
  "destination": "Pueblo,CO",
  "api_key": "jgn983hy48thw9begh98h4539h4"
}

Response:

{
  "data": {
    "id": null,
    "type": "roadtrip",
    "attributes": {
      "start_city": "Denver, CO",
      "end_city": "Estes Park, CO",
      "travel_time": "2 hours, 13 minutes"
      "weather_at_eta": {
        "temperature": 59.4,
        "conditions": "partly cloudy with a chance of meatballs"
      }
    }
  }
}

If you would like to try sending requests to the deployed API, Sweater Weather is deployed at https://curtis-sweater-weather.herokuapp.com/.


Built with

  • Rails 5.2.4.3
  • Ruby 2.5.3
  • PostgreSQL 13
  • MapQuest API
  • Unsplash API
  • OpenWeather API

Authors

sweater_weather's People

Contributors

c-bartell avatar

Stargazers

 avatar

Watchers

 avatar

sweater_weather's Issues

1a. Retrieve weather for a city

Front end application request:

GET /api/v1/forecast?location=denver,co
Content-Type: application/json
Accept: application/json
  • GET verb
  • /api/v1 namespace
  • /forcast uri
  • location=CITY,STATE_CODE_ETC query param appended to uri
  • Content-Type in header
  • Accept in header

Response:

{
  "data": {
    "id": null,
    "type": "forecast",
    "attributes": {
      "current_weather": {
        "datetime": "2020-09-30 13:27:03 -0600",
        "temperature": 79.4,
        etc
      },
      "daily_weather": [
        {
          "date": "2020-10-01",
          "sunrise": "2020-10-01 06:10:43 -0600",
          etc
        },
        {...} etc
      ],
      "hourly_weather": [
        {
          "time": "14:00:00",
          "wind_speed": "4 mph",
          "wind_direction": "from NW",
          etc
        },
        {...} etc
      ]
    }
  }
}

The response data should contain exactly these elements and nothing more:

  • a data attribute, under which all other attributes are present:
    • id, always set to null
    • type, always set to “forecast”
    • attributes, an object containing weather information:
      • current_weather, holds current weather data:
        • datetime, in a human-readable format such as “2020-09-30 13:27:03 -0600”
        • sunrise, in a human-readable format such as “2020-09-30 06:27:03 -0600”
        • sunset, in a human-readable format such as “2020-09-30 18:27:03 -0600”
        • temperature, floating point number indicating the current temperature in Fahrenheit
        • feels_like, floating point number indicating a temperature in Fahrenheit
        • humidity, numeric (int or float), as given by OpenWeather
        • uvi, numeric (int or float), as given by OpenWeather
        • visibility, numeric (int or float), as given by OpenWeather
        • conditions, the first ‘description’ field from the weather data as given by OpenWeather
        • icon, string, as given by OpenWeather
      • daily_weather, array of the next 5 days of daily weather data:
        • date, in a human-readable format such as “2020-09-30”
        • sunrise, in a human-readable format such as “2020-09-30 06:27:03 -0600”
        • sunset, in a human-readable format such as “2020-09-30 18:27:03 -0600”
        • max_temp, floating point number indicating the maximum expected temperature in Fahrenheit
        • min_temp, floating point number indicating the minimum expected temperature in Fahrenheit
        • conditions, the first ‘description’ field from the weather data as given by OpenWeather
        • icon, string, as given by OpenWeather
      • hourly_weather, array of the next 8 hours of hourly weather data:
        • time, in a human-readable format such as “14:00:00”
        • temperature, floating point number indicating the current temperature in Fahrenheit
        • wind_speed, string, in miles per hour
        • wind_direction, string, check wikipedia for how to convert this numeric value
        • conditions, the first ‘description’ field from the weather data as given by OpenWeather
        • icon, string, as given by OpenWeather

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)

Consume OpenWeather Endpoint

Consume the OpenWeather One Call endpoint

Endpoint:
GET https://api.openweathermap.org/data/2.5/onecall
Request Headers:

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

Request params:
?lat=LATTITUDE&lon=LONGITUDE&exclude=minutely,alerts&units=imperial&appid=API_KEY

  • Create Weather service object
  • Add in VCR
  • Happy Path Tested

Consume Geocoding Endpoint

Consume the MapQuest Geocoding API endpoint to turn a location into lat and long coordinates.

Endpoint:
POST http://www.mapquestapi.com/geocoding/v1/address
Request Headers:

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

Request body (JSON):

{
    "location": "LOCATION",
    "options": {
        "thumbMaps": false,
        "maxResults": 1,
        "intlMode": "AUTO"
    }
}
  • Create Geocoding service object
  • Add in VCR
  • Happy Path Tested

Downcase user email when saving to db during registration and login

Currently, the user may register the same email multiple times if it is not exactly the same case as when they registered the first time.

  • Downcase the email when registering a user to the DB
  • Downcase the email when searching for a user in the DB
  • Add testing to verify that the user cannot register multiple times with the same email in different cases

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.