Release of Scalingo Ruby Library v2

December 16, 2019 - 5 min read
Release of Scalingo Ruby Library v2

The whole Scalingo platform is API-driven, all the tools you are manipulating as a user, are communicating with our public APIs: the dashboard and the command line tool scalingo. Our APIs are accessible and documented, you can build and use your own tools against them to improve your workflows. To help you doing so, we just released the v2 version of our official Ruby library.

Changes Since the 1st Version

The first version of this library was not an official release, it had been designed by a platform's user in the need of a deeper integration. Later the project was transferred to us, but lacked some love for a few years.

Since then, we revamped our authentication system and we expanded on multiple regions this year, the gem is now compatible with both these major changes of the platform.

Plus, different resources were not yet implemented and couldn't be modified easily with this library, their support has been added:

Find about the different resources you can manipulate in our developers documentation.

Integration of the library

To use our Ruby library, you need to add it in your Gemfile:

gem 'scalingo-ruby-api', '~> 2'

Configuration

Then it has to be configured in your project. The following snippet would configure the library to use the API token from the environment in the SCALINGO_API_TOKEN variable, and to use the region osc-fr.

Scalingo.configure do |config|
  config.token = ENV['SCALINGO_API_TOKEN']
  config.region = 'osc-fr1'
end
For a Ruby on Rails application, create an initializer `config/initializers/scalingo.rb` to add this configuration

Note that if you need to use different tokens or different regions in your project, you can configure these per client instance in your code:

client_osc_fr1 = Scalingo::Client.new(region: 'osc-fr1')
client_user_1 = Scalingo::Client.new(token: ENV['SCALINGO_USER1_TOKEN'])

Usage examples

  • List all apps:
client = Scalingo::Client.new
apps = client.apps.all
apps.each do |app|
  puts app.name
end
  • Associate a domain to an app:
client = Scalingo::Client.new
app = client.apps.find('my-app')
app.domains.create('example.com')
  • Get current metrics of your app containers:
client = Scalingo::Client.new
app = client.apps.find('my-app')
stats = app.stats.all
stats.each do |stat|
 puts "Container #{s.id}: Memory: #{s.memory_usage/1024/1024}MB/#{s.memory_limit/1024/1024}MB"
end

Which would output:

Container clock-1: Memory: 147MB/512MB
Container web-1: Memory: 357MB/512MB
Container web-2: Memory: 329MB/512MB
Container web-3: Memory: 275MB/5128MB
Container worker-1: Memory: 167MB/512MB

Contributions and questions

The project is under MIT license and available on GitHub: https://github.com/Scalingo/scalingo-ruby-api. You'll find more information in the README of the project. If you have any question don't hesitate to open an issue, we'll help you as soon as possible.

You're not working with Ruby? We're officially developing and supporting libraries in other languages:

Photo by Jonny Lew from Pexels

Share the article
Étienne Michon
Étienne Michon
Étienne Michon is one of the first employee at Scalingo. With a PhD in computer science Étienne takes care of Research and Development at Scalingo. He also regularly contributes to this blog with technical articles.

Try Scalingo for free

30-day free trial / No credit card required / Hosted in Europe