Skip to content

ptrikutam/code-corps-api

 
 

Repository files navigation

Code Corps Rails API

Code Climate Test Coverage Dependency Status Codeship Status for code-corps/code-corps-api Slack Status

The Code Corps API is an open source Rails::API backend that powers the Code Corps platform. It includes:

  • developer and project matchmaking
  • project management tooling
  • a donations engine that distributes donations to projects

Developer installation guide

First steps

  1. Install and configure PostgreSQL 9.3+.
  2. Run postgres -V to see if you already have it.
  3. Make sure that the server's messages language is English; this is required by the ActiveRecord Postgres adapter.
  4. Install Ruby 2.2.2 and Bundler.
  5. Clone the project and bundle.

Before you start Rails

  1. bundle install
  2. bundle exec rake db:create db:migrate db:test:prepare db:seed
  3. bundle exec rake db:seed_fu
  4. Try running the specs: bundle exec rake spec
  5. Install and make sure you can run redis:
    • Follow the official quickstart guide
    • It's best to install it as a service instead of running it manually
    • To make sure everything works and the service is running, execute redis-cli ping in the console. It should respond with PONG

From here you can either:

Use foreman to run processes

  1. Stop your existing redis-server process
  2. Run the api with foreman start -f Procfile.dev. This will start any service listed in that Procfile.

Alternatively, run processes individually

  1. You already have redis-server running. In the future, you'll need to run it, as well.
  2. Start Sidekiq with bundle exec sidekiq
  3. Start the Rails server with rails s

To make sure the API is running properly

Point your browser (or make a direct request) to http://api.lvh.me:3000/ping. There should be a {"ping":"pong"} response from it.

Testing helpers

We've written some convenience helpers to help with API testing. The helpers are found in spec/support/helpers as:

  • ApiHelpers
    • authenticate which is an authentication helper that uses OAuth2 to authenticate requests and return a token used to make future requests.
  • RequestHelpers
    • json which returns the JSON of the last response as a Ruby object
    • authenticated_get(path, args, token) (and _post, _put, _delete) which takes the URL path, any arguments, and the token generated by the authenticate method above. You can grep for good examples of these in action.

These helpers are included in specs by default via the rails_helper. You can just call these methods directly.

Working with Ember

The CodeCorps API is intended to work alongside a client written in Ember. For that purpose, the rails application exposes all of it's API endpoints behind an api. subdomain.

On the Ember client side of things, we use ember-cli-deploy with a redis plugin to deploy the client application to redis. Multiple revisions are maintained this way.

Any server request pointing to the main domain and not the api. subdomain is redirected to ember_index_controller#index. There, depending on the remainder of the request path and the current environment, a specific revision of the ember app is retrieved from redis and rendered. This can be

  • the development revision, if the current environment is development
  • a specific deployed revision in production if the request contains a revision parameter in SHORT_UUID format
  • the latest deployed revision in production if the request does not contain a revision parameter
  • A plain text string containing "INDEX NOT FOUND" if a revision was specified, but the key for the specified revision was not found by redis

Built with

  • Rails::API — Our backend API is a Rails::API app which uses JSON API to respond RESTfully to requests.
  • Ember.js — Our frontend is an Ember.js app that communicates with the Rails API.
  • PostgreSQL — Our primary data store uses Postgres.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 98.7%
  • HTML 1.3%