Giter VIP home page Giter VIP logo

ridemyway-api's Introduction

Build Status Codacy Badge Coverage Status Maintainability

Ride My Way

Ride-my App is a carpooling application that provides drivers with the ability to create ride offers and passengers to join available ride offers.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

A few requirements to install, run and test this project.

Git : Use git to git clone this project locally. git Python-3.6.5

Installing

Type git clone https://github.com/JoshuaOndieki/ridemyway-api.git in your terminal.

  1. Install Python 3.6.5
  2. cd to the root dir of this repo cd ridemyway-api.
  3. Create a virtual env and pip install -r requirements.txt
  4. Run the app with python run.py or python3 run.py
  5. Checkout the endpoints and test them with a tool like POSTMAN

Heroku

This Flask API has been hosted and is live at Heroku here RideMyWay

Deployment

Check out this step by step guide on how to deploy this app to Heroku

API ENDPOINTS

EndPoint Functionality
POST /api/v1/rides Creates a new ride
GET /api/v1/rides Fetches all available rides
GET /api/v1/rides/<ride_id> Fetches a single ride
POST /api/v1/auth/rides/<ride_id>/requests Creates a ride request

A Pivotal tracker board was used in planning and managing this project. The board is publicly available here

Testing

Run nosetests --with-coverage --cover-package=ridemyway to see the coverage and passing tests. Manually test the endpoints with a tool like POSTMAN on the endpoints provided above.

Built With

  • Python-3.6.5
  • Flask-1.0.2

Versioning

This project uses tags for release and versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Andela for this wonderful learning opportunity
  • Inspiration
  • Andela21 Teammates and facilitators for their support.

ridemyway-api's People

Contributors

joshuaondieki avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

ridemyway-api's Issues

App crashes when migrating DB (Works for valid db and credentials | Crashes for invalid args)

Trying to migrate a DB with a nonexisting DB crashes with this error ๐Ÿ‘‡
screenshot from 2018-07-06 06-30-37

Trying to migrate with invalid credentials ๐Ÿ‘‡
screenshot from 2018-07-06 06-36-52

How can we solve this?

  • The app should catch this error to ensure a good user experience. This scenario should be presented to the user in a less technical way unlike as seen in the crash error log.
  • The app should prevent abrupt app exist.

Method could be a function (no self use)

Why is this an issue?

Used when there is no reference to the class, suggesting that the method could be used as a static function instead If the class method does not reference any of the class attributes it may be more clear to define the method as a static function instead.

Attempt using either of the decorators @classmethod or @staticmethod

Ex:

class Foo(object):
    ...
    def bar(self, baz):
        ...
        return llama

Try instead to use:

class Foo(object):
    ...
    @classmethod
    def bar(cls, baz):
        ...
        return llama

SOURCE

Related code pattern

Prohibits classes without referencing
Prohibits the usage of classes when there are no references for it, suggesting that the method could be used as a static function instead

Try, Except, Pass

Avoid pass in the except block
Example:

try:
  do_some_stuff()
except Exception:
  pass

Rationale:
This pattern is considered bad practice in general, but also represents a potential security issue. A larger than normal volume of errors from a service can indicate an attempt is being made to disrupt or interfere with it. Thus errors should, at the very least, be logged.

There are rare situations where it is desirable to suppress errors, but this is typically done with specific exception types, rather than the base Exception class (or no type).

Imports PEP8

IMPORTS

Imports should usually be on separate lines, e.g.:

Yes:

import os
import sys

No:

import sys, os

It's okay to say this though:

from subprocess import Popen, PIPE

Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.

Imports should be grouped in the following order:

  • Standard library imports.
  • Related third party imports.
  • Local application/library specific imports.
    You should put a blank line between each group of imports.

Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better error messages) if the import system is incorrectly configured (such as when a directory inside a package ends up on sys.path):

import mypkg.sibling
from mypkg import sibling
from mypkg.sibling import example

However, explicit relative imports are an acceptable alternative to absolute imports, especially when dealing with complex package layouts where using absolute imports would be unnecessarily verbose:

from . import sibling
from .sibling import example

Standard library code should avoid complex package layouts and always use absolute imports.

Implicit relative imports should never be used and have been removed in Python 3.

When importing a class from a class-containing module, it's usually okay to spell this:

from myclass import MyClass
from foo.bar.yourclass import YourClass

If this spelling causes local name clashes, then spell them

import myclass
import foo.bar.yourclass

and use "myclass.MyClass" and "foo.bar.yourclass.YourClass".

Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. There is one defensible use case for a wildcard import, which is to republish an internal interface as part of a public API (for example, overwriting a pure Python implementation of an interface with the definitions from an optional accelerator module and exactly which definitions will be overwritten isn't known in advance).

When republishing names this way, the guidelines below regarding public and internal interfaces still apply.

Identical blocks of code

Maintain DRY standards

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Edit User doesn't actually edit a user. Returns a false posititve!

The update_user DB query has a pass. No implementation of DB connection and edits made. Hence a false positive of changes being applied!

How can this kind of false positives be mitigated?

  • Try to ascertain directly that there was a change in the DB data.

#33 Should be revised!

Function cognitive complexity

Should not exceed 5

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

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.