judge0 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5056245ed8277003c5865decae29d220b87d39d039fd6d00cd7867ae79334a72
4
+ data.tar.gz: 19dce00c0d65fc42650df386861978e4fc38ba2170fda1f8dade4ab3abbb0fb1
5
+ SHA512:
6
+ metadata.gz: 9178ae92997d90bda799b95b8c49ecc628f6d5120e25577b32653986faaebbd9d2740c80d2d98ffedf8f8b331ff43badb026834ae1d58d55c972dd5bbd627ec5
7
+ data.tar.gz: 67d1bbc546c76690cf99c3df360908b964191f970b08acf266c64e13060b5af8cd649e69c33715cb76452e50fcf4a8bbf7f4c916f7d4c4abb0ddd5b8fda5754c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Breno Nunes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # judge0-gem
2
+
3
+ interface for [judge0 api](https://api.judge0.com/)
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install judge0
9
+ ```
10
+
11
+ or
12
+
13
+ ```ruby
14
+ # Gemfile
15
+ gem 'judge0'
16
+ ```
17
+
18
+ ## Usage Examples
19
+
20
+ ### simple code execution
21
+
22
+ ```ruby
23
+ sub = Judge0::Submission.new do |config|
24
+ config.source_code = 'p "Hello world!"'
25
+ config.language_id = 72
26
+ end
27
+
28
+ sub.run # hash of the submission result
29
+ sub.stdout # output
30
+ ```
31
+
32
+ ### tests battery execution
33
+
34
+ ```ruby
35
+ sub = Judge0::Submission.new do |config|
36
+ config.source_code = 'p gets.to_i'
37
+ config.language_id = 72
38
+ end
39
+
40
+ tests = [
41
+ ['0', '0'],
42
+ ['1', '1']
43
+ ]
44
+
45
+ sub.tests_battery(tests)
46
+ ```
47
+
48
+ ```ruby
49
+ sub = Judge0::Submission.new do |config|
50
+ config.source_code = 'p gets.to_i'
51
+ config.language_id = 72
52
+ end
53
+
54
+ tests = [
55
+ {input: '0', output: '0'},
56
+ {input: '1', output: '1'}
57
+ ]
58
+
59
+ sub.tests_battery(tests)
60
+ ```
61
+
62
+ ```ruby
63
+ class Test
64
+ attr_accessor :input, :output
65
+
66
+ def initialize(input, output)
67
+ @input = input
68
+
69
+ @output = output
70
+ end
71
+ end
72
+
73
+ sub = Judge0::Submission.new do |config|
74
+ config.source_code = 'p gets.to_i'
75
+ config.language_id = 72
76
+ end
77
+
78
+ tests = [
79
+ Test.new('0', '0'),
80
+ Test.new('1', '1')
81
+ ]
82
+
83
+ sub.tests_battery(tests)
84
+ ```
85
+
86
+ ### utils
87
+
88
+ ```ruby
89
+ require 'pp'
90
+ pp Judge0::languages
91
+ pp Judge0::statuses
92
+ pp Judge0::system_info
93
+ pp Judge0::config_info
94
+ ```
data/judge0.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'judge0'
3
+ s.version = '0.0.1'
4
+ s.date = '2020-01-20'
5
+ s.summary = 'ruby interface for judge0 api.'
6
+ s.description = 'ruby interface for judge0 api.'
7
+ s.authors = ['Breno Nunes']
8
+ s.email = 'breno.nunesgalvao@protonmail.ch'
9
+ s.files = %w[LICENSE README.md judge0.gemspec] + Dir['lib/**/*.rb']
10
+ s.homepage = 'https://github.com/TopRoupi/judge0-gem'
11
+ s.license = 'MIT'
12
+
13
+ s.add_runtime_dependency 'faraday', '>= 1.0.0'
14
+ end
data/lib/judge0.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ require 'submission.rb'
5
+
6
+ module Judge0
7
+ def self.statuses
8
+ resp = Faraday.get('https://api.judge0.com/statuses')
9
+ JSON.parse(resp.body)
10
+ end
11
+
12
+ def self.system_info
13
+ resp = Faraday.get('https://api.judge0.com/system_info')
14
+ JSON.parse(resp.body)
15
+ end
16
+
17
+ def self.config_info
18
+ resp = Faraday.get('https://api.judge0.com/config_info')
19
+ JSON.parse(resp.body)
20
+ end
21
+
22
+ def self.languages
23
+ resp = Faraday.get('https://api.judge0.com/languages')
24
+ JSON.parse(resp.body)
25
+ end
26
+
27
+ def self.language(id)
28
+ resp = Faraday.get("https://api.judge0.com/languages/#{id}")
29
+ JSON.parse(resp.body)
30
+ end
31
+ end
data/lib/submission.rb ADDED
@@ -0,0 +1,90 @@
1
+ module Judge0
2
+ class Submission
3
+ attr_accessor :source_code, :language_id, :number_of_runs, :stdin,
4
+ :expected_output, :cpu_time_limit, :cpu_extra_time,
5
+ :wall_time_limit, :memory_limit, :stack_limit,
6
+ :max_processes_and_or_threads,
7
+ :enable_per_process_and_thread_time_limit,
8
+ :enable_per_process_and_thread_memory_limit,
9
+ :max_file_size
10
+
11
+ attr_reader :token, :stdout, :time, :memory, :stderr, :compile_out,
12
+ :status_id, :status_description
13
+
14
+ def initialize(options = {})
15
+ options.each do |key, value|
16
+ instance_variable_set("@#{key}", value)
17
+ end
18
+ yield(self) if block_given?
19
+ end
20
+
21
+ def run
22
+ res = wait_response(get_token)
23
+
24
+ @stdout = res['stdout']
25
+ @time = res['time'].to_f
26
+ @memory = res['memory']
27
+ @stderr = res['stderr']
28
+ @compile_out = res['compile_out']
29
+ @message = res['message']
30
+ @status_id = res['status']['id']
31
+ @status_description = res['status']['description']
32
+
33
+ result
34
+ end
35
+
36
+ def tests_battery (tests)
37
+ tests.map! do |test|
38
+ if test.respond_to?(:input) && test.respond_to?(:output)
39
+ @stdin = test.input
40
+ @expected_output = test.output
41
+ elsif test.include?(:input) && test.respond_to?(:output)
42
+ @stdin = test[:input]
43
+ @expected_output = test[:output]
44
+ else
45
+ @stdin = test[0]
46
+ @expected_output = test[1]
47
+ end
48
+ get_token
49
+ end
50
+ tests.map do |test|
51
+ wait_response(test)
52
+ end
53
+ end
54
+
55
+ def result
56
+ {
57
+ stdout: @stdout,
58
+ time: @time,
59
+ memory: @memory,
60
+ stderr: @stderr,
61
+ compile_out: @compile_out,
62
+ message: @message,
63
+ status: {
64
+ id: @status_id,
65
+ description: @status_description
66
+ }
67
+ }
68
+ end
69
+
70
+ private
71
+
72
+ def to_hash
73
+ Hash[instance_variables.map { |name| [name[1..-1].to_sym, instance_variable_get(name)] } ]
74
+ end
75
+
76
+ def get_token
77
+ resp = Faraday.post('https://api.judge0.com/submissions', to_hash)
78
+ @token = JSON.parse(resp.body)['token']
79
+ end
80
+
81
+ def wait_response(token)
82
+ begin
83
+ resp = Faraday.get("https://api.judge0.com/submissions/#{token}")
84
+ body = JSON.parse(resp.body)
85
+ puts "waiting: #{token} - #{body['status']['description']}"
86
+ end while body['status']['id'] <= 2
87
+ body
88
+ end
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: judge0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Breno Nunes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ description: ruby interface for judge0 api.
28
+ email: breno.nunesgalvao@protonmail.ch
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - judge0.gemspec
36
+ - lib/judge0.rb
37
+ - lib/submission.rb
38
+ homepage: https://github.com/TopRoupi/judge0-gem
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.0.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: ruby interface for judge0 api.
61
+ test_files: []