Skip to content

Ada Dev Academy Capstone, part 1: Flask API supporting the Actionist iOS App

License

Notifications You must be signed in to change notification settings

brookseakate/actionist-api

Repository files navigation

Actionist API

Actionist is an iOS app and REST API created for my Capstone Project at Ada Developers Academy. Actionist is intended to streamline engagement with social justice and political actions from a mobile device.

From the iOS App, Users can retrieve a list of (and act on): Call-, Email-, or Event-type Actions. The Actionist API manages CRUD operations for the User, Call Action, Email Action, and Event Action resources.

Learn more about the project at: http://actionistapp.com/

See the iOS app code at: https://github.com/brookseakate/actionist-ios

Installation

The Actionist API is written in Python using Flask.

Dependencies

Core Dependencies:

Database Dependencies (if using Postgres):

Etc:

Getting Started

Before cloning, be sure all necessary packages listed above are installed and executable from your path. Most packages can be installed with pip. (Here are some helpful getting-started guides for Flask and for Using PostgreSQL with Flask.)

Clone the repo:

$ git clone <this-repository-url>
$ cd actionist-api

Configuration

Actionist API endpoints require HTTP Basic authentication. Assign a username and password for authorized HTTP requests. The application also needs to know your database path.

Define the following environment variables in a .env file at the project root:

# .env

HTTP_AUTH_PASSWORD = "password"

HTTP_AUTH_USERNAME = "username"

SQLALCHEMY_DATABASE_URI = "database://your/database/URI"
# see sample db URI formats here: http://flask-sqlalchemy.pocoo.org/2.1/config/#configuration-keys

Running for Development

To run the application locally:

$ source venv/bin/activate
$ python application.py

When launched successfully, the application logs will confirm the local server's IP:

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

You can now make requests against your local server, running at: http://localhost:5000

Seeding the Database

To populate your database using the included seed generator scripts, run python manage.py dbseed with the -c flag to specify a quantity.

For example, to seed 10 each of Users, Call Actions, Email Actions, and Event Actions, run:

$ python manage.py dbseed -c 10

Usage

Authenticating API requests

Actionist API endpoints require HTTP Basic authentication. Include your username and password with each request.

REST Endpoints

All responses are provided in JSON format.

NOTE: When running locally, <yourserver> will be localhost:5000 by default.

Base URI:

http://<yourserver>/api/v1.0/

Actions:

http://<yourserver>/api/v1.0/actions/
  • GET: Retrieve a list of all Actions (Call, Email, or Event)

Call Actions:

http://<yourserver>/api/v1.0/call_actions/
  • GET: Retrieve a list of all Call Actions
  • POST: Create a new Call Action
http://<yourserver>/api/v1.0/call_actions/<id>
  • GET: Retrieve the specified Call Action
  • PUT: Update the specified Call Action
  • DELETE: Delete the specified Call Action

Email Actions:

http://<yourserver>/api/v1.0/email_actions/
  • GET: Retrieve a list of all Email Actions
  • POST: Create a new Email Action
http://<yourserver>/api/v1.0/email_actions/<id>
  • GET: Retrieve the specified Email Action
  • PUT: Update the specified Email Action
  • DELETE: Delete the specified Email Action

Event Actions:

http://<yourserver>/api/v1.0/event_actions/
  • GET: Retrieve a list of all Event Actions
  • POST: Create a new Event Action
http://<yourserver>/api/v1.0/event_actions/<id>
  • GET: Retrieve the specified Event Action
  • PUT: Update the specified Event Action
  • DELETE: Delete the specified Event Action

Users:

http://<yourserver>/api/v1.0/users/
  • GET: Retrieve a list of all Users
  • POST: Create a new User
http://<yourserver>/api/v1.0/users/<id>
  • GET: Retrieve the specified User
  • PUT: Update the specified User
  • DELETE: Delete the specified User

Sample Curl Requests

The below sample requests run against a default local server (localhost:5000). Substitute your server location if running on a different host.

  • Get a list of all Actions:
curl -i -H "Content-Type: application/json" -X GET http://localhost:5000/api/v1.0/actions -u username:password
  • Create a new User:
curl -i -H "Content-Type: application/json" -X POST -d '{ "user_name": "lunarox", "first_name": "Luna", "last_name": "Lovegood", "about": "Spells and outer space", "zip": "98101" }' http://localhost:5000/api/v1.0/users -u username:password
  • Update a Call Action:
curl -i -H "Content-Type: application/json" -X PUT -d '{ "target_phone_number": "2065551212" }' http://localhost:5000/api/v1.0/call_actions/1 -u username:password
  • Delete an Event Action:
curl -i -H "Content-Type: application/json" -X DELETE http://localhost:5000/api/v1.0/event_actions/123 -u username:password

Resource Relationships and Parameters

For more information about API resources and parameters, see the Actionist ERD.

License

This project is released as open source under the MIT License.

Links