JDoodle.rb

Ruby client library for JDoodle API.

⬇ Installing

Bundler (recommended)

If you are using Bundler, add the following line to your Gemfile:

gem "jdoodle"

Gem

If you are not using Bundler, use the gem install command:

$ gem install jdoodle

🕹 Usage

First you need to create an account on JDoodle's website. After that you must pick a plan. That will give you a client ID and a client secret. You will need that to make requests. Now you can go back to your Ruby project, require JDoodle and instantiate a client:

# Requiring JDoodle client library
require "jdoodle"

# Instantiating a client
jdoodle = JDoodle::Client.new(
  client_id: "CLIENT_ID_HERE",
  client_secret: "CLIENT_SECRET_HERE"
)

Credits

To check how many credits the client has spent today, use Client#credit_spent:

jdoodle.credit_spent # => 4

Executing Snippets

To execute a snippet of code, use Client#execute:

# If your code takes up more than one line, it is
# recommended to use the squiggly heredoc syntax.
jdoodle.execute :c do
  <<~CODE
    #include <stdio.h>

    int main()
    {
      printf("Hello, World!");
      return 0;
    }
  CODE
end

# If not, go for the shorter way.
jdoodle.execute :ruby do
  'puts "Hello, World!"'
end

# Or
jdoodle.execute(:ruby) { 'puts "Hello, World!"' }

This will instantiate an ExecutionResponse object, which has four read-only attributes: cpu_time, memory, output and status_code.

response = jdoodle.execute :python3 do
  'print("Hello, World!")'
end

p response.cpu_time # => "0.01"
p response.memory # => "5280"
p response.output # => "Hello, World!\n"
p response.status_code # => 200

📦 Dependencies

Runtime

JDoodle.rb does not rely on any external dependencies. It uses Ruby's Net::HTTP to handle requests.

Development

  • Bundler ~> 2.0 — to manage dependencies
  • Fasterer ~> 0.5 — to look for code that could be faster
  • Rake ~> 12.3 — to automate tasks
  • YARD ~> 0.9 — to create beautiful documentation

📚 Documentation

Documentation is available online at RubyDoc. To generate offline documentation, run the following Rake task:

$ bundle exec rake doc

📋 Rake Tasks

To run tasks, execute bundle exec rake <task_name> in your terminal.

Task name Description
cleanup Run Rubocop & Fasterer
doc Generate YARD documentation

📑 License

JDoodle.rb is licensed under the MIT License.

✏ Contributors

JDoodle.rb by Nick Maloucaze