Code Monkey home page Code Monkey logo

sweater_weather's Introduction

Sweater Weather

Sweater weather is an api application that exposes 5 endpoints for front end plug in. It has weather data by city, photo search by city and key word, user registration and login, and roadtrip creation.

There are 3 APIs consumed to build the engine endpoints. See details on the APIs below.

Created by:

Contents

Prerequisites

Built With

This project was tested with:

  • RSpec version 3.10

  • Ruby

    • The project is built with rubyonrails using ruby version 2.5.3p105, you must install ruby on your local machine first. Please visit the ruby home page to get set up. Please ensure you install the version of ruby noted above.
  • Rails

    gem install rails --version 5.2.5
  • Postgres database

    • Visit the postgresapp homepage and follow their instructions to download the latest version of Postgres app.

    Installing

    1. Clone the repo
    $ git clone [email protected]:<YOUR_GITHUB_USER_NAME>/sweater_weather.git
    
    1. Bundle Install
    $ bundle install
    
    1. Create, migrate and seed rails database
    $ rails db:{create,migrate,seed}
    
    1. Set up Environment Variables
      • run bundle exec figaro install
      • add the below variables to the config/application.yml
    mapquest_api_key: '<YOU_KEY_HERE>'
    weather_api_key: '<YOU_KEY_HERE>'
    photo_api_key: '<YOU_KEY_HERE>'
    
    

Project Design

Below is an example of how the API application is designed to consume multiple APIs so the front end can easily hook into the exposed endpoints (noted in black).

APIs Consumed

Postman

View API endpoints consumed on Postman View API endpoints exposted on Postman

Endpoints

HTTP verbs Paths Used for Output
GET /api/v1/forecast?location=denver,co Get the weather for a location json
GET /api/v1/backgrounds?location=denver,co Get a photo for a specific location json
POST /api/v1/users create a user account json
POST /api/v1/sessions create a user session (login a user) json
POST /api/v1/road_trip create a new road trip json

Application Design

The application uses the Facade Design pattern. The controllers talk to the respective facades to get the necessary information packaged to the serializer.

#Controller
class Api::V1::SalariesController < ApplicationController

  def city_info
    if SalariesFacade.location_check?(params[:destination])
      render json: SalariesSerializer.new(SalariesFacade.final_city_info(params[:destination]))
    else
      render json: NullSerializer.new, status: 204
    end
  end
end
#Facade
def self.location_check?(location)
  if SalaryService.search_ua_id(location) == nil
    false
  else
    true
  end
end

def self.final_city_info(location)
  city_info = {}
  city_info[:destination] = location
  city_info[:forecast] = city_forecast(location)
  city_info[:salaries] = SalaryService.city_salary_info(location)
  city_info
  final_city_info = OpenStruct.new(city_info)
end

def self.city_forecast(location)
  coords = MapQuestService.coordinates(SalaryService.full_name(location))
  weather = WeatherService.get_city_info(coords)
  forecast = {}
  forecast[:summary] = weather[:current_weather][:conditions]
  forecast[:temperature] = weather[:current_weather][:temperature]
  forecast
end
end
#Service
def self.city_all_salary_info(location)
  response = Faraday.get("https://api.teleport.org/api/urban_areas/teleport:#{search_ua_id(location)}/salaries/")
  if response.body == "Sorry, but the page you were trying to view does not exist."
    nil
  else
    raw_data = JSON.parse(response.body, symbolize_names: true)
    salaries = []
    raw_data[:salaries].map do |salary|
      salaries << salary_info(salary)
    end
    salaries
  end
end
...

sweater_weather's People

Contributors

amsmyth1 avatar

Watchers

 avatar

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.