Skip to content

unepwcmc/protectedplanet-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2865cff · Mar 21, 2022
Mar 3, 2022
Feb 2, 2022
Jul 16, 2019
Oct 30, 2017
Sep 1, 2021
Mar 3, 2022
Jul 15, 2019
Mar 3, 2022
Apr 9, 2019
Jun 20, 2016
Sep 1, 2021
Apr 11, 2019
Jan 19, 2016
Jul 16, 2019
Mar 21, 2022
Sep 18, 2016
Feb 1, 2022
Feb 1, 2022
Jan 19, 2016
Sep 7, 2021
Apr 9, 2016
Oct 16, 2017
Sep 20, 2016
Sep 27, 2016

Repository files navigation

Protected Planet API

This is the repository for the official Protected Planet API. If you are interested in consuming the API, head to the API documentation. If you are a developer and intend contributing to the API codebase, keep reading.

The stack

The Protected Planet API is a Rack application, written in Ruby. It is composed of two sections, each handled by a different framework.

The two frameworks are then cascaded inside Rack, in the config.ru file:

require ‘api/root’
require ‘web/root’
[…]
run Rack::Cascade.new [Web::Root, API::Root]

Both frameworks share a bunch ofActiveRecord models, which form a subset of the ProtectedPlanet models, with the addition of the ApiUser model.

The API uses RABL and grape-rabl for views, while Sinatra renders ERB and markdown for the documentation.

The design is implemented in the bower package protectedplanet-frontend, which makes possible to share exactly the same style between this project and ProtectedPlanet itself.

Finally, the db folder is a git submodule, linked to protectedplanet-db. More on this in the Development section.

Installation

  • Install correct ruby version using rbenv (see .ruby-version)
  • Install bower npm install -g bower
- `git clone git@github.com:unepwcmc/protectedplanet-api.git`
- `cd protectedplanet-api`
- `bundle install`
- `bower install`
- Create .env file and copy contents from LastPass
- `rake db:create db:migrate` # does nothing if db is already present
- `rackup`

Now fire up your browser at localhost:9292!

Further hints

This example demonstrates accessing an api_user from the terminal using irb.

$ RAILS_ENV=development bundle exec irb

> $LOAD_PATH.unshift("#{File.dirname(__FILE__)}"); require 'config/environment.rb'; require 'lib/mailer.rb'

=> true

2.3.0 :002 > ApiUser.first

Troubleshooting

An error occurred while installing pg (0.18.4), and Bundler cannot continue.

Try running: gem install pg -v '0.18.1' -- --with-cflags="-Wno-error=implicit-function-declaration"