GithubHelp home page GithubHelp logo

creative_cuisines's Introduction

Creative Cuisines

A Lunch and Learn Experience

Creative Cuisines is a back-end application built with Ruby on Rails that exposes an API to provide data on cuisines by countries searched and as well as additional information about that country's culture. This app will allow users to search for recipes by country, favorite recipes, and learn more about a particular country. It aggregates data from multiple external API endpoints and handles user registration, log-in with authentication, and token authentication to access requests. This application presumes the team is working in a service-oriented architecture pattern and follows RESTful API conventions.

Learning Goals

This project is part of the Turing School of Software + Design's Back-End Engineering track, and is the final solo project for Module 3. See more details about the project requirements here. Completing this application demonstrates:
  • Exposing an API that aggregates data from multiple external APIs
  • Exposing an API that requires an authentication token
  • Exposing an API for CRUD functionality
  • Implementation of Basic Authentication
  • Ability to determine completion criteria based on the needs of other developers
  • Ability to test both API consumption and exposure, making use of at least one mocking tool (VCR, Webmock, etc).

Installation

Running the Application Locally

  1. Clone this repository from the command line: git clone [email protected]:aplasket/creative_cuisines.git
  2. Navigate to your local repository: cd creative_cuisines
  3. Install dependencies and gems: bundle install
  4. Set up the database and run migrations: rails db:{create, migrate}
  5. Configure Figaro to hide environment secret variables (see below): bundle exec figaro install
  6. Start the Rails server: rails s

With your local server running, you can use a tool like Postman or the ThunderClient extension for VS Code to make sample requests and view responses.

External APIs

Creative Cuisine's endpoints expose data from Edamam, RESTCountries, Youtube and UnSplash. You can sign up for free access to these APIs here:
  • Edamam - ability to search for recipes via query word for the /api/v1/recipes endpoint
  • RESTCountries - ability to get a random country name to input into Edamam's search query for the /api/v1/recipes endpoint. Additionally there is an endpoint to allow you to fetch that country's capital to utilize for the /api/v1/air_quality endpoint. You do not need an API from this site, however documentation is available above about the API.
  • Youtube - ability to receive video data to appear on the api/v1/learning_resources endpoint. You will need to have a google account in order to create an api_key.
  • Unsplash - ability to get random photos to appear on the api/v1/learning_resources endpoint
  • API NINJA - ability to get airquality data for an inputted city, utilized in the /api/v1/air_quality endpoint

Once you have your key for each site, add them to the config/application.yml file generated when you configure Figaro (see Step 5, above). Please ensure you include the exact variable names below:

  • EDAMAM_ID: <add your key here>
  • EDAMAM_KEY: <add your key here>
  • GOOGLE_TOKEN: <add your key here>
  • UNSPLASH_TOKEN: <add your key here>
  • API_NINJAS: <add your key here>

Testing

To run the full test suite: bundle exec rspec

CreativeCuisines uses Simplecov to monitor test coverage. At the time of writing, test coverage was at 100% with all tests passing. VCR with Webmock is used to mock calls to external APIs.

EndPoints

route: GET /api/v1/recipes?country="" Get Recipes For A Particular Country -- searching for cuisines by country. Example data:
{
"data": [
    {
        "id": null,
        "type": "recipe",
        "attributes": {
            "title": "Andy Ricker's Naam Cheuam Naam Taan Piip (Palm Sugar Simple Syrup)",
            "url": "https://www.seriouseats.com/recipes/2013/11/andy-rickers-naam-cheuam-naam-taan-piip-palm-sugar-simple-syrup.html",
            "country": "thailand",
            "image": "https://edamam-product-images.s3.amazonaws.com..."
        }
    },
    {etc...},
  ]
}

If the country parameter is either an empty string, or a value that doesn’t return any recipes, return an empty array:

{
  "data": []
}
route: GET /api/v1/learning_resources?country="" Get Learning Resources for a Particular Country -- include videos about that country's culture and images. Example data:
{
"data": {
    "id": null,
    "type": "learning_resource",
    "attributes": {
        "country": "laos",
        "video": {
            "title": "A Super Quick History of Laos",
            "youtube_video_id": "uw8hjVqxMXw"
        },
        "images": [
            {
                "alt_tag": "standing statue and temples",
                "url": "https://images.unsplash.com/photo-1528181304..."
            },
            {etc...},
          ]
    }
  }
}

If no videos or images are found, those keys should point to an empty object:

{
  "data": {
      "id": null,
      "type": "learning_resource",
      "attributes": {
          "country": "laos",
          "video": {},
          "images": []
      }
  }
}
route: POST /api/v1/users User Registration. Example data:

Example Request:

POST /api/v1/users
Content-Type: application/json
Accept: application/json

{
  "name": "Odell",
  "email": "[email protected]",
  "password": "treats4lyf",
  "password_confirmation": "treats4lyf"
}

Example Response:

{
  "data": {
    "type": "user",
    "id": "1",
    "attributes": {
      "name": "Odell",
      "email": "[email protected]",
      "api_key": "jgn983hy48thw9begh98h4539h4"
    }
  }
}

Email addresses must be unique. If a unique email address is not used for registration, an appropriate error message is returned in the response. If passwords do not match, an appropriate error message is returned in the response. Example:

{
  "errors": [
    {
        "status": "400",
        "title": "Email has already been taken and Password confirmation doesn't match Password"
    }
  ]
}
route: POST /api/v1/sessions Log In USer. Example data:

Example Request:

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

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

Example Response:

{
  "data": {
    "type": "user",
    "id": "1",
    "attributes": {
      "name": "Odell",
      "email": "[email protected]",
      "api_key": "jgn983hy48thw9begh98h4539h4"
    }
  }
}

An unsuccessful request returns an appropriate 400-level status code and body with a description of why the request wasn’t successful. Example:

{
  "errors": [
      {
          "status": "401",
          "title": "Unauthorized user"
      }
  ]
}
route: POST /api/v1/favorites Add Favorites Functionality to add recipes to a favorited list for a particular user can be done with the following request. Example data:

Example Request:

POST /api/v1/favorites
Content-Type: application/json
Accept: application/json

{
    "api_key": "jgn983hy48thw9begh98h4539h4",
    "country": "thailand",
    "recipe_link": "https://www.tastingtable.com/.....",
    "recipe_title": "Crab Fried Rice (Khaao Pad Bpu)"
}

Example Response:

{
    "success": "Favorite added successfully"
}

If the api_key is invalid (no user with that api key), an appropriate 400-level status code is returned, as well as a message explaining what went wrong.

{
  "errors": [
    {
        "status": "401",
        "title": "Unauthorized user"
    }
  ]
}
route: GET /api/v1/favorites?api_key="" Get a User’s Favorites -- ability for a user to see all their favorite recipes. Example data:

Response:

{
  "data": [
    {
        "id": "1",
        "type": "favorite",
        "attributes": {
            "recipe_title": "Recipe: Egyptian Tomato Soup",
            "recipe_link": "http://www.thekitchn.com/recipe-egyptian-tomato-soup-weeknight....",
            "country": "egypt",
            "created_at": "2022-11-02T02:17:54.111Z"
        }
    },
    {
        "id": "2",
        "type": "favorite",
        "attributes": {
            "recipe_title": "Crab Fried Rice (Khaao Pad Bpu)",
            "recipe_link": "https://www.tastingtable.com/.....",
            "country": "thailand",
            "created_at": "2022-11-07T03:44:08.917Z"
        }
    }
  ]
}

If the api_key is invalid (no user with that api key), an appropriate 400-level status code is returned, as well as a message explaining what went wrong.

{
  "errors": [
    {
        "status": "401",
        "title": "Unauthorized user"
    }
  ]
}

If the user does not have any favorite recipes saved, it returns empty []

{
   "data": []
}
route: DELETE /api/v1/favorites?api_key="" Delete a User’s Favorites -- ability for a user delete a favorited recipe. Example data:
no data is rendered for this

creative_cuisines's People

Contributors

aplasket 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.