Giter Club home page Giter Club logo

bizfriendly-api's Introduction

Build Status Coverage Status

BizFriendly API

BizFriendly teaches you how to use the internet to increase your quality of life, be more effecient at work, and perhaps even how to be a better citizen.

About

This is the API that powers the various BizFriendly applications.

Made in Kansas City

                     `..----..`                    
                 .-://////////:-.                 
               .:////////////////:.               
              -////////////////////-              
             -////////-....-////////-             
            `://////:`      `://////:`            
            .///////.        .///////.            
            `///////-       `:///////`            
  `-:::-.    -///////:`    `:///////-    .::::-`  
  ://////-    :///////:`  `:///////-    -//////:  
  :///////-    -///////: `:///////-    -///////:  
  `:///////:    -/////:`.:///////-    :///////:`  
   `:///////:`   .///:`.////////-   `:///////:`   
    `:///////:`   .::`.////////-   `:///////:`    
     `:///////:`   ``.////////-   `:///////:`     
      `:///////:.   .////////-   `:///////:`      
        -///////:. -////////-`. `:///////:`       
        `:////////:////////-`:/-:///////:`        
          :///////////////.`://////////:`         
           -/////////////.`://////////:           
            -///////////- ://////////:            
             -/////////-  `:////////-`            
              -///////.    .://////:              
               `.---.`      `.----.               
                                                  


       oyyyyyyyyyyy+          .yyyyyyyyyyyy       
       ``:yyyyyyy-``       ``` ```osyyyyyo:`      
          oyyyyyo`:/+ossyyyyyyyysso+////-+yy/`    
          oyyyyyo.yyyyyyyyyyyyyyyyyyyyyyo/+yyy/`  
          oyyyyyo.yyo+/:-..`.//////+oyyyyyyyyyyy/`
       .+-oyyyyyo`.       `/yyyyyy+`  .:oyyyyyyys:
     `oyy-oyyyyyo       `/yyyyyyo.       `:oyys:  
    :yyyy-oyyyyyo     `/yyyyyyo.            .-    
   /yyyyy-oyyyyyo   `/yyyyyyo.                    
  :yyyyy/ oyyyyyo `/yyyyyyo.                      
 `yyyyy+  oyyyyyo/yyyyyyy/                        
 /yyyyy`  oyyyyyyyyyyyyyyyo.                      
:yyyyys   oyyyyyyyyyoyyyyyyy/`                    
.yyyyy+   oyyyyyyy+. .oyyyyyys:                   
 /yyyys   oyyyyys`     -syyyyyyo.                 
 `syyyy:  oyyyyyo        /yyyyyyy+`               
  -yyyyy- oyyyyyo         `+yyyyyyy:              
   -yyyyy:.syyyyo           -syyyyyys.         ./-
    .syyyyo-/yyyo             :yyyyyyy+`     `/yy/
      /yyyyyo-:++              `+yyyyyyy:  `/yyyy:
       `/syyyys/.                .oyyyyyys-/ys+-.`
          -+syyyyyo/-.`           `:syyyyyy+-     
          o+:-:+syyyyyyyssooooossyyo./yyyyyyy/    
       ``.syyys+:--::/+oossssssoo+/:-`.syyyyyys-` 
       oyyyyyyyyyyy+                :yyyyyyyyyyyy/

Demo

Some example API calls: http://app.bizfriend.ly/api/v1/categories http://app.bizfriend.ly/api/v1/lessons http://app.bizfriend.ly/api/v1/steps

Development Setup

BizFriendly is written in Python, and runs as a standalone Flask application.

  1. For local development, uncomment the settings in setup.sh and set the correct values for your environment.

  2. Run a virtual environment and install all the requirements. source setup.sh

  3. Run application. python runserver.py

  4. Add content through the Admin panel.

For continuous staging deployment: set the Travis CI github hook for codeforamerica/bizfriendly-api on

Contributing

In the spirit of free software, everyone is encouraged to help improve this project.

Here are some ways you can contribute:

  • by using alpha, beta, and prerelease versions
  • by reporting bugs
  • by suggesting new features
  • by translating to a new language
  • by writing or editing documentation
  • by writing specifications
  • by writing code (no patch is too small: fix typos, add comments, clean up inconsistent whitespace)
  • by refactoring code
  • by closing issues
  • by reviewing patches
  • financially

Submitting an Issue

We use the GitHub issue tracker to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. You can indicate support for an existing issue by voting it up. When submitting a bug report, please include a Gist that includes a stack trace and any details that may be necessary to reproduce the bug.

Submitting a Pull Request

  1. Fork the project.
  2. Create a topic branch.
  3. Implement your feature or bug fix.
  4. Commit and push your changes.
  5. Submit a pull request.

Copyright

Copyright (c) 2013 Code for America. See LICENSE for details.

Code for America Tracker

bizfriendly-api's People

Contributors

mayorholland avatar migurski avatar ondrae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bizfriendly-api's Issues

Redo the remember_thing process

Description

Right now for certain steps we need to remember certain data for later. I set up a temp database to handle that. I'm sure its not the right way to do it. What do you think? Should we create a user object and add it to that? Should it just be saved in memory?

Files

howtocity/init.py

Skills Needed

Python, Postgres

Tips

  • Ask smart people what to do.

Add progressive timeouts

Description

We are checking the service endpoints once a second, until sixty seconds pass when we return a timeout. The request will just repeat though. We need to add progressive timeouts, so that the second time the request comes in, we only check every five seconds. Next time we check every thirty seconds. All incase the user walks away.

Files

howtocity/init.py

Skills Needed

Python

Tips

  • Figure out all the edge cases about api request timing.
  • Should probably add a 'Are you there?' modal to the frontend.

Scheduled script to delete Test Users from db

Description

Our tests include creating Test Users. For security reasons, I don't allow deleting of the users from tests. We need a cron job that deletes users with the name Test User every night.

DELETE FROM bf_user WHERE name = 'Test User';

Full Back End Documentation

Description

For proper handover, BizFriend.ly needs to be fully documented.

  • Research best documentation tools
  • Describe high level purpose of each section
  • Function level documentation

Refactor Step Endpoints

Description

We need to refactor all of the endpoints used in the lesson steps. They are currently pretty specific to the lesson they were first coded for. For example, the check_for_new
endpoint does three different things. It first checks for a new addition to a specific api resource. Then it saves that to a temp db table, then returns two additional resource endpoints for use in the feedback. Those should be three different functions.

I don't yet know how to chain them together though. Through three different javascript calls? Should those flags be contained in the step information? Multiple step types at once?

Skills Needed

Python, Flask, API design

Standardize endpoint responses

Description

Each request to our backend endpoints should have two responses:

  1. An expected response.
  2. A timeout response.

Files

howtocity/init.py

Skills Needed

Python, Flask, Hanging get technique

Tips

  • Research hanging get / long polling best practices.
  • Pick the best time out technique.
  • Review each endpoint to make sure it offers these two responses.

Create UI for adding content.

We need a way to nicely add content to our site. A simple form should do the trick. It would be really cool to start on the prototype of a lesson builder. Maybe keep triggers out of it for now.

Set up SSL on Heroku

Description

We are sending plaintext passwords from our website to our server for encryption. We need to send them via HTTPS or we are doing it wrong.

We need to buy an SSL cert first. Do we have an account with someone?

Extended instructions here: https://devcenter.heroku.com/articles/ssl-endpoint

Tips

Add a database migration manager

Description

We power our whole service off an API. The database schema we use is still under development. I'm sick of having to retype everything every time I update it! A database migration manager will help retain data whenever we make amendments to the schema.

Skills Needed

Postgres, Python, Flask, DBA

Tips

  • Alembic is the recommended tool for our Flask app.

Check For New is broke!

Details

The check for new step is now broken for Facebook and Trello. Something in the Foursquare Tips fix broke it.

To replicate.

Go through the Facebook and Trello lessons. When creating a FB page or a new Trello board, we get an error. When you go to the next step, then back to the check for new step, the correct feedback shows up.

To Fix

  • Write tests for every step type.
  • Review that Foursquare commit for new errrors.

Let users see their services and skills when submitted.

Description

Need to give quick response to created content.

We need to email a link thanking them for their contribution as well as show their services and skills on the profile page.

Files

bizfriendly/routes.py

Examples

  • Add on to the new_content_email route to also email the creator.
  • Show services and skills on profile.html

Proper CORS Security Implementation

Description

We need to properly implement CORS. Right now its wide open.

Files

howtocity/init.py

Skills Needed

Flask, Security, API Design

Tips

  • Review CORS best practices.

OAuth implementation

Description

We need to handle many different OAuth implementations through our API. I envision having a standard endpoint such as howtocity.org/foursquare/login or howtocity.org/expensify/login Hitting this endpoint will run the user through the appropriate login process. It should return an access token that can be appended to each API call to that service. Refer to OAuth.io to see an example of how we are currently handling OAuth on the front end.

Skills Needed

Python, Flask, OAuth, API Design

Tips

  • Flask-OAuth is the best place to start.
  • Create howtocityAPI/foursquare/login endpoint for each service
  • Should have a small popup on the front end.
  • Response should be an access_token string.

Add logging to all requests

Description

Every request to our API should generate a log entry. Any errors generated should create an entry as well.

Files

logs/requests.log logs/error.log

Skills Needed

Python, Logging

Tips

Add sanitation to '/signup'

Details

We need to add validation and sanitation to the sign up form. Works in tandem with #47

Use regex to validate email and prevent against bad SQL attacks.

Tips

  • Add sanitation on the backend to prevent SQL injection.

Requests and responses need correct headers

Description

Do a pass of all the endpoints to ensure they have the correct headers, content-type, etc.

Skills Needed

REST API Design

Tips

  • Content type for responses should be application/json
  • Request headers from front end should be ???

Need a tester of APIs

I need to be notified when an API changes. There must be a servie out there that does this for me.

Add new Lesson attributes to db

Description

Our lessons have gotten a professional once over via the talented @SheilaLDugan. To support this great content, we need to add new attributes to the Lesson class.

Files

howtocity/init.py

Skills Needed

Python, Alembic, Postgres

New Columns to Add

  • Short Description
  • Long Description
  • Time
  • Difficulty
  • Additional Resources
  • Warnings

BizFriendly Status Report

We have a very simple status report that we'd like for Bizfriendly to publish, that will allow us to observe the app and know if anything has gone wrong.

Add a new URL to the site, here:
/.well-known/status

…and have it respond with a JSON structure that looks like this:

    {
            "status": "ok",
            "updated": 1380064049,
            "dependencies": [ ],
            "resources": { }
    }

Status "ok" should be representative, so if (for example) the project has a database attached, "ok" should mean that the database connection has been checked. We don't want the app to be entirely broken except for the part that says "ok". Updated should be a unix timestamp so we know if we're getting a stale response from any kind of cache.

Dependencies and resources are undefined for now, but should ultimately provide information about capacities of attached resources such as databases, and 3rd party dependencies like email services.

Here's an example that's running right now:
http://www.codeforamerica.org/.well-known/status

Image Upload needs to have different size limits

Description

There are three points where we upload images when creating lessons. Each of these needs to have its own rules around image sizes.

Files

bizfriendly/routes.py

Example

The images within the lesson need to fit in the popup window, so less than 340. In the service page, we upload both icons and larger media. Review the needs here.

Current code is below.

# Check image size
    img = Image.open("tmp/"+file.filename)
    # get the image's width and height in pixels
    width, height = img.size
    if width > 260:
        response = {}
        response["message"] = "Image too wide."
        return make_response(json.dumps(response), 401)

Facebook lesson not catching new page being created

Description

During several of our live demos, when we created the Facebook page, the feedback would not show. My best guess is due to the sloppy refactor of the check_for_new function. It used to fire for 60 seconds before returning a timeout. An earlier bug, now resolved, caused errors yet we wouldn't get the notice for 60 seconds. As part of that fix, I reduced the timing down to 5 seconds. Unfortunately, due to the current way the function works, that results in a one in five chance the created page will not trigger the right feedback.

How to reproduce

Create hella Facebook pages. You'll notice that about one fifth of the time, the app won't catch it.

Files

howtocity/init.py > check_for_new()

Skills Needed

Python

Tips

  • Refactor to get the count of facebook pages the user has once, at the beginning of the step, instead of every five seconds.

Add service name to lesson schema.

Description

Right now we are using the lesson.url field for the name of the service. We should add another field for the service and use the url field for its intended purpose.

Skills Needed

Flask, Python, Postgres, Alembic

Files

howtocity/init.py

Tips

  • Change the Lesson class
  • Use alembic to track the db changes.
  • Update the local, staging, and production database.
  • Update the frontend to use the new column name.

Responsive design

Even though the instructions won't work on mobile with our current tech, our main site should.

Error recording completing step in a lesson

Description

Sometimes we receive an error when trying to record the completion of a lesson.

To replicate

  1. Run through a lesson
  2. On the final step, when you get to completion, open your javascript console.
  3. You should see XMLHttpRequest cannot load https://howtocity.herokuapp.com/record_step. Origin http://bizfriend.ly is not allowed by Access-Control-Allow-Origin.

Files

bizfriendly/routes.py record_step()

Clues

It seems to work fine if you login to a lesson, then click on the last steps dot. It has something to do with clicking next to get to the final step.

Email notification when content is created

Description

When someone creates some new content, we should get an email notification. We need to quickly review the submission and publish it.

We currently submit drafts through the API, so we need to make another call to an endpoint that emails us.

Files

bizfriendly/routes.py, js/teach.js

  • Add an additional endpoint that emails us new when new content is created
  • Add a call to that endpoint on successful submissions on the frontend.

False CORS errors in frontend console

Description

When a request to our app generates an error on the server, such as not having an access token or whatever, the front end doesn't see this error. Instead it gets a a CORS error, which isn't correct or descriptive of the real problem.

Example

XMLHttpRequest cannot load http://howtocity.herokuapp.com/get_remembered_thing?access_token=null. Origin http://codeforamerica.github.io is not allowed by Access-Control-Allow-Origin.

How to duplicate

  1. Go to a lesson http://codeforamerica.github.io/howtocity-web/instructions.html?2
  2. Don't login, just skip a few steps ahead.
  3. Open the console and wait a few seconds.

Files

howtocity/init.py

Skills Needed

Flask, Security, Testing

Tips

  • We need to build in more descriptive error messages into our api endpoints.
  • These errors shouldn't trigger bad CORS requests.
  • Our tests should cover these errors.

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.