Skip to content
πŸ’» Ruby client library for JDoodle API
Branch: master
Clone or download
Latest commit 8cda7b9 Jun 1, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Bump to 1.0.1 Jun 1, 2019
.gitignore First commit Jun 1, 2019
.rubocop.yml First commit Jun 1, 2019
Gemfile First commit Jun 1, 2019
LICENSE First commit Jun 1, 2019
README.md Fix metadata and online docs link Jun 1, 2019
Rakefile First commit Jun 1, 2019
jdoodle.gemspec Fix metadata and online docs link Jun 1, 2019

README.md

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

You can’t perform that action at this time.