Skip to content

EPHEC-Enovatech/sensorygarden-api

Repository files navigation

SensoryGarden REST API

Useful links

Deployment Build Status
Code Quality Maintainability Test Coverage
Availability Uptime Robot status Uptime Robot ratio (30 days)
Code frequency GitHub last commit
Documentation Documentation

Explanation

This API was delevopped with Ruby on Rails on a period on three months for a school project. We used it to insert data coming from an IoT module we developped and to then fetch this data from a Progressive Web App

Technologies

Here's a non-exhaustive list of the technologies and dependencies used

  • Ruby on Rails 5
  • MySQL
  • JWT (with the Knock gem)
  • Unicorn (for production server)
  • Nginx (Reverse Proxy)
  • Capistrano (Deployment)
  • Travis-CI (Continuous deployment)
  • RSpec (Unit & integration tests)

Prerequirements

You'll need Ruby 2.5.1 or higher and Ruby on Rails 5.2.1 or higher installed on your device. You also need some sort of SGBD installed, for example MySQL, Postgres, MariaDB, SQlite, ...

Installation & Configuration

First clone the repository to your device :

$ git clone https://github.com/EPHEC-Enovatech/sensorygarden-api.git

Then inside the cloned repository, you need to change some configuration parameters. In /config/database.yml change in the development settings the username and password :

development:
  <<: *default
  database: sensorygarden_api_development
  username: {{YOUR USERNAME}}
  password: {{YOUR PASSWORD}}

Following the SGBD you choosed to install you'll need to change the database adapter. In /config/database.yml change in the default section :

default: &default
  adapter: {{eg: pg, mysql2, sqlite3, ...}}
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  host: localhost

Full list of available database adapters here.

Then you need to setup the database with the command :

$ bundle exec rake db:setup

You can now start a development server with the command :

$ rails s

The API is now accessible at localhost:3000

Usage

Once you have the developement server running you can test the API by openning an HTTP client (eg. Postman). You can now perform a GET request on localhost:3000/ping, you should get a response looking like this :

{
  "status": "SUCCESS",
  "message": "Pong !"
}

If you want to try out other endpoints you have a complete API documentation here

Testing

You can run the tests on the API yourself.

First you may want to change the database user and password in the /config/database.yaml file first :

test:
  <<: *default
  database: sensorygarden_api_test
  username: {{YOUR USERNAME}}
  password: {{YOUR PASSWORD}}

Then run the following command :

$ bundle exec rake spec

You can find the code for the tests in /spec/requests

Releases

No releases published

Packages

No packages published