Skip to content

triglav-dataflow/triglav

Repository files navigation

Triglav

Core API and message queue server of Triglav.

API Spec

./doc

Requirements

  • Ruby >= 2.3.0
  • MySQL >= 5.6

Development

Prepare

Copy config files and modify them if you want.

cp config/database.yml{.development,}
cp config/settings.yml{.development,}
cp config/secrets.yml{.development,}
cp db/seeds.rb{.development,}

Migrate

./bin/rails db:create
./bin/rails db:apply # using ridgepole
./bin/rails db:seed

Start

bundle exec foreman start

Try

$ curl -H "Content-type: application/json" http://localhost:3000/api/v1/auth/token -X POST -d '{"username":"triglav_test", "password": "triglav_test", "authenticator":"local"}'
{"access_token":"xxxxxxxxxxxxxxxxxx","expires_at":1430458696}
$ curl -H "Content-type: application/json" -H "Authorization: xxxxxxxxxxxxxxxxxx" http://localhost:7800/api/v1/auth/me -X GET

Test

Do migration with RAILS_ENV=test bundle exec rails db:create db:apply, then

bundle exec rspec

You may generate API doc from requests spec as

AUTODOC=1 bundle exec rspec

You may run your tests with spring to make it faster to finish:

bundle exec spring binstubs rspec
bin/rspec

Swagger

We use swagger to describe API specification. Write API doc on rails controllers, and serializers referring Swagger Documentation Specification v2.0.

Trying with Swaggeer UI

swagger-ui is already bundled. You can start swagger-ui as

bundle exec rails s

and access to http://localhost:7800/apidocs. By the way, swagger-ui is a full javascript application, so serving this with nginx is also fine.

Authenticate with POST /auth/token.

image

Click Try it out! button, you will get an access token

image

Go to top bar of Swagger UI, and click Authorize button.

image

Paste your access token to the value field, then click Authorize.

image

Now, you should be able to hit any APIs.

Generating Swagger API Specification

To generate a static swagger.json, run

bundle exec rake swagger:generate

Generating Swagger API Clients

wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.0/swagger-codegen-cli-2.2.0.jar -O bin/swagger-codegen-cli.jar

Generate ../triglav-client-ruby

bundle exec rails swagger:codegen-ruby

Generate ../triglav-client-java

bundle exec rails swagger:codegen-java

Generate both

bundle exec rails swagger:codegen

Release

Edit VERSION

Release ../triglav-client-ruby

bundle exec rails release:client-ruby

Release ../triglav-client-java

bundle exec rails release:client-java

Release triglav itself (tagging version)

bundle exec rails release:core

Release all

bundle exec rails release:all