judge0 0.0.1 → 0.0.9
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 +4 -4
- data/LICENSE +0 -0
- data/README.md +66 -1
- data/judge0.gemspec +1 -1
- data/lib/judge0.rb +24 -6
- data/lib/submission.rb +39 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a8486852c12336f3ec463280981363f553ca8a41c82849c28904881f7f86f7d
|
4
|
+
data.tar.gz: 85e1f2015627fd56fce78da6c35cc58df87a6d409125cc262165b416e71746f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b54bf142a8bbf902b7593d39d77ed8732ca5464b9b499a8367a5c44d95cf61c42a8165c48c53b60ece9bbe6a79c69a02b4e6560dc9a7d5d8380ff2ebc45d3d58
|
7
|
+
data.tar.gz: 867311cbcd6469f9b54bc1b4911158b3e74a39a8adfbc1a239dc21728f86a9e8bdaf04403b4ede77b71da1f3bbb0ed986071fa99155cad3b72e3ed987e502ad7
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -17,8 +17,15 @@ gem 'judge0'
|
|
17
17
|
|
18
18
|
## Usage Examples
|
19
19
|
|
20
|
+
### set a custom url
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
Judge0.base_url = 'http://api.custom-judge0.com'
|
24
|
+
```
|
25
|
+
|
20
26
|
### simple code execution
|
21
27
|
|
28
|
+
|
22
29
|
```ruby
|
23
30
|
sub = Judge0::Submission.new do |config|
|
24
31
|
config.source_code = 'p "Hello world!"'
|
@@ -29,6 +36,44 @@ sub.run # hash of the submission result
|
|
29
36
|
sub.stdout # output
|
30
37
|
```
|
31
38
|
|
39
|
+
### wait the response on another thread
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
sub = Judge0::Submission.new do |config|
|
43
|
+
config.source_code = 'sleep 2; p "Hello world!"'
|
44
|
+
config.language_id = 72
|
45
|
+
end
|
46
|
+
|
47
|
+
sub.get_token
|
48
|
+
|
49
|
+
t = Thread.new {
|
50
|
+
sub.wait_response!
|
51
|
+
}
|
52
|
+
|
53
|
+
puts "🛏️ waiting..." # doing something while the code is running
|
54
|
+
|
55
|
+
t.join
|
56
|
+
|
57
|
+
puts sub.output
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
##### same thing but without creating a Judge0::submission object
|
62
|
+
|
63
|
+
this is useful when you are trying to wait the response on a rails job but cant pass a submission as a params without writing a serializer, maybe in future i will make a job serializer and configure it out of the box
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
params = {
|
67
|
+
"source_code": "sleep 2; p 'Hello word!'",
|
68
|
+
"language_id": 72
|
69
|
+
}
|
70
|
+
|
71
|
+
token = Judge0.get_token(params)
|
72
|
+
|
73
|
+
Judge0.wait_response(token)
|
74
|
+
|
75
|
+
```
|
76
|
+
|
32
77
|
### tests battery execution
|
33
78
|
|
34
79
|
```ruby
|
@@ -91,4 +136,24 @@ pp Judge0::languages
|
|
91
136
|
pp Judge0::statuses
|
92
137
|
pp Judge0::system_info
|
93
138
|
pp Judge0::config_info
|
94
|
-
```
|
139
|
+
```
|
140
|
+
|
141
|
+
## development
|
142
|
+
|
143
|
+
### test
|
144
|
+
|
145
|
+
```bash
|
146
|
+
irb -Ilib -r judge0
|
147
|
+
```
|
148
|
+
|
149
|
+
### build
|
150
|
+
|
151
|
+
```bash
|
152
|
+
gem build judge0.gemspec
|
153
|
+
```
|
154
|
+
|
155
|
+
### push
|
156
|
+
|
157
|
+
```bash
|
158
|
+
gem push judge0-x.x.x.gem
|
159
|
+
```
|
data/judge0.gemspec
CHANGED
data/lib/judge0.rb
CHANGED
@@ -4,28 +4,46 @@ require 'json'
|
|
4
4
|
require 'submission.rb'
|
5
5
|
|
6
6
|
module Judge0
|
7
|
+
@@base_url = 'http://roupi.xyz:3000/'
|
8
|
+
|
9
|
+
def self.get_token(params)
|
10
|
+
Judge0::Submission.new(params).get_token
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.wait_response(token)
|
14
|
+
Judge0::Submission.new(token: token).wait_response
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.base_url=(url)
|
18
|
+
@@base_url = url
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.url(params = '')
|
22
|
+
@@base_url + params
|
23
|
+
end
|
24
|
+
|
7
25
|
def self.statuses
|
8
|
-
resp = Faraday.get('
|
26
|
+
resp = Faraday.get(url '/statuses')
|
9
27
|
JSON.parse(resp.body)
|
10
28
|
end
|
11
29
|
|
12
30
|
def self.system_info
|
13
|
-
resp = Faraday.get('
|
31
|
+
resp = Faraday.get(url '/system_info')
|
14
32
|
JSON.parse(resp.body)
|
15
33
|
end
|
16
34
|
|
17
35
|
def self.config_info
|
18
|
-
resp = Faraday.get('
|
36
|
+
resp = Faraday.get(url '/config_info')
|
19
37
|
JSON.parse(resp.body)
|
20
38
|
end
|
21
39
|
|
22
40
|
def self.languages
|
23
|
-
resp = Faraday.get('
|
41
|
+
resp = Faraday.get(url '/languages')
|
24
42
|
JSON.parse(resp.body)
|
25
43
|
end
|
26
44
|
|
27
45
|
def self.language(id)
|
28
|
-
resp = Faraday.get("
|
46
|
+
resp = Faraday.get(url "/languages/#{id}")
|
29
47
|
JSON.parse(resp.body)
|
30
48
|
end
|
31
|
-
end
|
49
|
+
end
|
data/lib/submission.rb
CHANGED
@@ -6,9 +6,9 @@ module Judge0
|
|
6
6
|
:max_processes_and_or_threads,
|
7
7
|
:enable_per_process_and_thread_time_limit,
|
8
8
|
:enable_per_process_and_thread_memory_limit,
|
9
|
-
:max_file_size
|
9
|
+
:max_file_size, :token
|
10
10
|
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :stdout, :time, :memory, :stderr, :compile_out,
|
12
12
|
:status_id, :status_description
|
13
13
|
|
14
14
|
def initialize(options = {})
|
@@ -19,18 +19,9 @@ module Judge0
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def run
|
22
|
-
|
22
|
+
get_token
|
23
23
|
|
24
|
-
|
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
|
24
|
+
wait_response!
|
34
25
|
end
|
35
26
|
|
36
27
|
def tests_battery (tests)
|
@@ -48,7 +39,7 @@ module Judge0
|
|
48
39
|
get_token
|
49
40
|
end
|
50
41
|
tests.map do |test|
|
51
|
-
wait_response
|
42
|
+
wait_response
|
52
43
|
end
|
53
44
|
end
|
54
45
|
|
@@ -61,30 +52,57 @@ module Judge0
|
|
61
52
|
compile_out: @compile_out,
|
62
53
|
message: @message,
|
63
54
|
status: {
|
64
|
-
id: @status_id,
|
55
|
+
id: @status_id,
|
65
56
|
description: @status_description
|
66
57
|
}
|
67
58
|
}
|
68
59
|
end
|
69
60
|
|
70
|
-
|
61
|
+
def output
|
62
|
+
msg = ''
|
63
|
+
msg = @stdout if @stdout
|
64
|
+
msg +="ERROR:\n#{@stderr}\n" if @stderr
|
65
|
+
msg += "MESSAGE:\n#{@message}\n" if @message
|
66
|
+
msg
|
67
|
+
end
|
71
68
|
|
72
69
|
def to_hash
|
73
|
-
Hash[
|
70
|
+
Hash[
|
71
|
+
instance_variables.map do |name|
|
72
|
+
[name[1..-1].to_sym, instance_variable_get(name)]
|
73
|
+
end
|
74
|
+
]
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_submission(response)
|
78
|
+
@stdout = response['stdout']
|
79
|
+
@time = response['time'].to_f
|
80
|
+
@memory = response['memory']
|
81
|
+
@stderr = response['stderr']
|
82
|
+
@compile_out = response['compile_out']
|
83
|
+
@message = response['message']
|
84
|
+
@status_id = response['status']['id']
|
85
|
+
@status_description = response['status']['description']
|
86
|
+
|
87
|
+
result
|
74
88
|
end
|
75
89
|
|
76
90
|
def get_token
|
77
|
-
resp = Faraday.post('
|
91
|
+
resp = Faraday.post(Judge0.url('/submissions/?base64_encoded=false&wait=false'), to_hash)
|
78
92
|
@token = JSON.parse(resp.body)['token']
|
79
93
|
end
|
80
94
|
|
81
|
-
def wait_response
|
95
|
+
def wait_response
|
82
96
|
begin
|
83
|
-
resp = Faraday.get("
|
97
|
+
resp = Faraday.get(Judge0.url("/submissions/#{@token}"))
|
84
98
|
body = JSON.parse(resp.body)
|
85
|
-
puts "waiting: #{token} - #{body['status']['description']}"
|
99
|
+
puts "waiting: #{token} - #{body['status']['description']}" unless ENV['RAILS_ENV'] == 'test'
|
86
100
|
end while body['status']['id'] <= 2
|
87
101
|
body
|
88
102
|
end
|
103
|
+
|
104
|
+
def wait_response!
|
105
|
+
to_submission(wait_response)
|
106
|
+
end
|
89
107
|
end
|
90
108
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: judge0
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Breno Nunes
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
57
|
+
rubygems_version: 3.1.2
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: ruby interface for judge0 api.
|