sphere_engine 1.1.0 → 1.2.0.pre
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/README.md +10 -132
- data/lib/sphere_engine/error.rb +13 -2
- data/lib/sphere_engine/rest/api.rb +0 -6
- data/lib/sphere_engine/rest/request.rb +1 -11
- data/lib/sphere_engine/rest/submissions.rb +1 -13
- data/lib/sphere_engine/rest/utils.rb +0 -4
- data/lib/sphere_engine/version.rb +1 -1
- data/sphere_engine.gemspec +2 -2
- metadata +6 -9
- data/lib/sphere_engine/rest/judges.rb +0 -28
- data/lib/sphere_engine/rest/problems.rb +0 -30
- data/lib/sphere_engine/rest/test_cases.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95dd43bce3035dfb25da29ca8f9030042c84b9e7
|
4
|
+
data.tar.gz: a86375f56f07089e18aeed201ebf3d3dd162e280
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3abe457a37ea224933c5520ef4460222a9f8db15c51cb73de90e12377de7c8787008a5d479f308c5b893662e82150d91345c78dcdde33dccaf11b58e0e406d30
|
7
|
+
data.tar.gz: 9879b770557422348a2c1904b0d9031ff9d0c789f379b924869bac1879fdeb586487f34c2153a029302b83031f1d5bf06dea7044a3950be6c94ceaa16e0abbc0
|
data/README.md
CHANGED
@@ -41,156 +41,34 @@ end
|
|
41
41
|
## Usage Examples
|
42
42
|
After configuring a client, you can do the following things:
|
43
43
|
|
44
|
-
###
|
45
|
-
|
46
|
-
#### Get languages
|
44
|
+
### Get compilers
|
47
45
|
```ruby
|
48
|
-
client.
|
46
|
+
client.all_compilers
|
49
47
|
```
|
50
48
|
|
51
|
-
|
49
|
+
### Get languages
|
52
50
|
```ruby
|
53
|
-
client.
|
51
|
+
client.all_languages
|
54
52
|
```
|
55
53
|
|
56
|
-
|
54
|
+
|
55
|
+
### Create a submission (Compilers service)
|
57
56
|
|
58
57
|
This method return a submission_id
|
59
58
|
```ruby
|
60
59
|
client.create_submission_compiler(
|
61
60
|
language: 11, #LanguageID
|
62
|
-
sourceCode: "#include
|
61
|
+
sourceCode: "#include int main(){ printf(\"Hello!\"); return 0; }" #Code
|
63
62
|
)
|
64
63
|
```
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
#### Fetch a submission
|
65
|
+
### Fetch a submission (Compilers service)
|
69
66
|
```ruby
|
70
67
|
client.fetch_submission_compilers(submission_id)
|
71
68
|
```
|
72
69
|
|
73
70
|
### Problems service
|
74
|
-
|
75
|
-
#### Create a problem
|
76
|
-
|
77
|
-
This method return a "code" is like a problem_id
|
78
|
-
```ruby
|
79
|
-
client.create_problem(
|
80
|
-
code: "RUBY_001", # Unique problem code. consist of 3 up to 16 capital letters. numbers and underscore
|
81
|
-
name: "Problem_Name", #String
|
82
|
-
body: "Write the fibonacci sequence" #String
|
83
|
-
)
|
84
|
-
```
|
85
|
-
|
86
|
-
#### Fetch a problem
|
87
|
-
```ruby
|
88
|
-
client.get_problem(problem_id)
|
89
|
-
```
|
90
|
-
|
91
|
-
#### Update a problem
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
client.update_problem("PROBLEM_ID", name: "NEW_NAME")
|
95
|
-
```
|
96
|
-
|
97
|
-
*Other params: type [string], interactive [boolean], masterjudgeId [integer], activeTestcases [array]*
|
98
|
-
|
99
|
-
#### Create testcase to problem
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
client.create_problem_testcase(
|
103
|
-
"PROBLEM_ID",
|
104
|
-
input: "input content",
|
105
|
-
timelimit: 10,
|
106
|
-
output: "output content"
|
107
|
-
)
|
108
|
-
```
|
109
|
-
|
110
|
-
#### Update a testcase
|
111
|
-
|
112
|
-
```ruby
|
113
|
-
client.update_problem_testcase(
|
114
|
-
"PROBLEM_ID",
|
115
|
-
"TESTCASE_ID",
|
116
|
-
name: "NEW_NAME"
|
117
|
-
input: "new input content",
|
118
|
-
output: "new output content"
|
119
|
-
)
|
120
|
-
```
|
121
|
-
|
122
|
-
#### Get a list testcases of a problem
|
123
|
-
|
124
|
-
```ruby
|
125
|
-
client.list_testcases("PROBLEM_ID")
|
126
|
-
```
|
127
|
-
|
128
|
-
#### Get a testcase of a problem
|
129
|
-
|
130
|
-
```ruby
|
131
|
-
client.get_testcase("PROBLEM_ID", "TESTCASE_ID")
|
132
|
-
```
|
133
|
-
|
134
|
-
#### Get a file testcases of a problem
|
135
|
-
```ruby
|
136
|
-
client.get_testcase_file("PROBLEM_ID", "TESTCASE_ID", "FILENAME")
|
137
|
-
```
|
138
|
-
|
139
|
-
*Filename is obtained from get_testcase request in uri params*
|
140
|
-
|
141
|
-
#### Get judge list
|
142
|
-
|
143
|
-
```ruby
|
144
|
-
client.all_judges()
|
145
|
-
```
|
146
|
-
|
147
|
-
*Other params: limit [Integer], offset [Integer], type [String]*
|
148
|
-
|
149
|
-
#### Create judge
|
150
|
-
|
151
|
-
```ruby
|
152
|
-
client.create_judge(
|
153
|
-
name: "NameJudge",
|
154
|
-
source: "<source code>"
|
155
|
-
)
|
156
|
-
```
|
157
|
-
|
158
|
-
*Other params: type [String], compilerId [Integer]*
|
159
|
-
|
160
|
-
#### Get judge details
|
161
|
-
|
162
|
-
```ruby
|
163
|
-
client..get_judge("JUDGE_ID")
|
164
|
-
```
|
165
|
-
|
166
|
-
#### Update judge
|
167
|
-
|
168
|
-
```ruby
|
169
|
-
client.update_judge(
|
170
|
-
"JUDGE_ID",
|
171
|
-
name: "NewNameJudge",
|
172
|
-
)
|
173
|
-
```
|
174
|
-
|
175
|
-
*Other params: source [String], compilerId [Integer]*
|
176
|
-
|
177
|
-
#### Create a submission
|
178
|
-
|
179
|
-
```ruby
|
180
|
-
client.create_submission_problem(
|
181
|
-
problemCode: "RUBY_001", #problem_id
|
182
|
-
compilerId: 1, # get of all_request
|
183
|
-
source: "#include <iostream>\n using namespace std;\n int main()\n {\n cout << \"Hello World\" << endl;\n return 0;\n }" #Example
|
184
|
-
)
|
185
|
-
```
|
186
|
-
|
187
|
-
*Other params: userId [Integer]*
|
188
|
-
|
189
|
-
#### Fetch a submission
|
190
|
-
|
191
|
-
```ruby
|
192
|
-
client.fetch_submission_problems("SUBMISSION_ID")
|
193
|
-
```
|
71
|
+
Coming soon
|
194
72
|
|
195
73
|
## Development
|
196
74
|
|
@@ -202,8 +80,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
202
80
|
|
203
81
|
Bug reports and pull requests are welcome on GitHub at https://github.com/14tinchov/sphere_engine. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
204
82
|
|
83
|
+
|
205
84
|
## License
|
206
85
|
|
207
86
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
208
87
|
|
209
|
-
|
data/lib/sphere_engine/error.rb
CHANGED
@@ -43,8 +43,19 @@ module SphereEngine
|
|
43
43
|
def parse_error(body)
|
44
44
|
if body.nil? || body.empty?
|
45
45
|
['', nil]
|
46
|
-
elsif
|
47
|
-
[
|
46
|
+
elsif body[:message]
|
47
|
+
[body[:message], nil]
|
48
|
+
elsif body[:errors]
|
49
|
+
extract_message_from_errors(body)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def extract_message_from_errors(body)
|
54
|
+
first = Array(body[:errors]).first
|
55
|
+
if first.is_a?(Hash)
|
56
|
+
[first[:message].chomp, first[:code]]
|
57
|
+
else
|
58
|
+
[first.chomp, nil]
|
48
59
|
end
|
49
60
|
end
|
50
61
|
end
|
@@ -2,9 +2,6 @@ require 'sphere_engine/rest/access'
|
|
2
2
|
require 'sphere_engine/rest/languages'
|
3
3
|
require 'sphere_engine/rest/compilers'
|
4
4
|
require 'sphere_engine/rest/submissions'
|
5
|
-
require 'sphere_engine/rest/problems'
|
6
|
-
require 'sphere_engine/rest/test_cases'
|
7
|
-
require 'sphere_engine/rest/judges'
|
8
5
|
|
9
6
|
module SphereEngine
|
10
7
|
module REST
|
@@ -14,9 +11,6 @@ module SphereEngine
|
|
14
11
|
include SphereEngine::REST::Languages
|
15
12
|
include SphereEngine::REST::Compilers
|
16
13
|
include SphereEngine::REST::Submissions
|
17
|
-
include SphereEngine::REST::Problems
|
18
|
-
include SphereEngine::REST::TestCases
|
19
|
-
include SphereEngine::REST::Judges
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end
|
@@ -27,18 +27,10 @@ module SphereEngine
|
|
27
27
|
# @return [Array, Hash]
|
28
28
|
def perform
|
29
29
|
response = build_http_request
|
30
|
-
response_body = response.body.empty? ? '' :
|
30
|
+
response_body = response.body.empty? ? '' : JSON.parse(response.to_s)
|
31
31
|
fail_or_return_response_body(response.code, response_body)
|
32
32
|
end
|
33
33
|
|
34
|
-
def format_to_response(response)
|
35
|
-
begin
|
36
|
-
JSON.parse(response.to_s)
|
37
|
-
rescue JSON::ParserError
|
38
|
-
response.to_s
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
34
|
def fail_or_return_response_body(code, body)
|
43
35
|
error = error(code, body)
|
44
36
|
raise(error) if error
|
@@ -67,8 +59,6 @@ module SphereEngine
|
|
67
59
|
HTTP.get(uri, params: build_request_params)
|
68
60
|
when :post
|
69
61
|
HTTP.post(uri, params: build_request_params)
|
70
|
-
when :put
|
71
|
-
HTTP.put(uri, params: build_request_params)
|
72
62
|
end
|
73
63
|
end
|
74
64
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module SphereEngine
|
2
2
|
module REST
|
3
3
|
module Submissions
|
4
|
-
include SphereEngine::REST::Utils
|
5
|
-
|
6
4
|
# @param options [Hash]
|
7
5
|
# This request you should send a compilerId and source
|
8
6
|
def create_submission_compiler(options = {})
|
@@ -14,16 +12,6 @@ module SphereEngine
|
|
14
12
|
def fetch_submission_compilers(submission_id, options = {})
|
15
13
|
perform_get_requests_of_compílers_service("/submissions/#{submission_id}")
|
16
14
|
end
|
17
|
-
|
18
|
-
# @param options [Hash]
|
19
|
-
def create_submission_problem(options = {})
|
20
|
-
perform_post_requests_of_problems_service('/submissions', options)
|
21
|
-
end
|
22
|
-
|
23
|
-
# @param options [Hash]
|
24
|
-
def fetch_submission_problems(submission_id)
|
25
|
-
perform_get_requests_of_problems_service("/submissions/#{submission_id}")
|
26
|
-
end
|
27
15
|
end
|
28
16
|
end
|
29
|
-
end
|
17
|
+
end
|
@@ -20,10 +20,6 @@ module SphereEngine
|
|
20
20
|
perform_request(:post, :compilers, path, options)
|
21
21
|
end
|
22
22
|
|
23
|
-
def perform_put_requests_of_problems_service(path, options = {})
|
24
|
-
perform_request(:put, :problems, path, options)
|
25
|
-
end
|
26
|
-
|
27
23
|
def perform_request(request_method, service, path, options = {})
|
28
24
|
SphereEngine::REST::Request.new(self, request_method, service, path, options).perform
|
29
25
|
end
|
data/sphere_engine.gemspec
CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.email = ["14tinchov@gmail.com"]
|
17
17
|
|
18
18
|
spec.summary = %q{A Ruby interface to the SphereEngine API.}
|
19
|
-
spec.description = %q{This gem was made as an interface to the SphereEngine API. I try to abstract in the best way all his methods that SphereEngine give us
|
20
|
-
spec.homepage = "https://github.com/14tinchov/sphere-engine"
|
19
|
+
spec.description = %q{This gem was made as an interface to the SphereEngine API. I try to abstract in the best way all his methods that SphereEngine give us}
|
20
|
+
spec.homepage = "https://github.com/14tinchov/sphere-engine.git"
|
21
21
|
spec.license = "MIT"
|
22
22
|
|
23
23
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sphere_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Villalba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.0'
|
83
83
|
description: This gem was made as an interface to the SphereEngine API. I try to abstract
|
84
|
-
in the best way all his methods that SphereEngine give us
|
84
|
+
in the best way all his methods that SphereEngine give us
|
85
85
|
email:
|
86
86
|
- 14tinchov@gmail.com
|
87
87
|
executables: []
|
@@ -105,16 +105,13 @@ files:
|
|
105
105
|
- lib/sphere_engine/rest/api.rb
|
106
106
|
- lib/sphere_engine/rest/client.rb
|
107
107
|
- lib/sphere_engine/rest/compilers.rb
|
108
|
-
- lib/sphere_engine/rest/judges.rb
|
109
108
|
- lib/sphere_engine/rest/languages.rb
|
110
|
-
- lib/sphere_engine/rest/problems.rb
|
111
109
|
- lib/sphere_engine/rest/request.rb
|
112
110
|
- lib/sphere_engine/rest/submissions.rb
|
113
|
-
- lib/sphere_engine/rest/test_cases.rb
|
114
111
|
- lib/sphere_engine/rest/utils.rb
|
115
112
|
- lib/sphere_engine/version.rb
|
116
113
|
- sphere_engine.gemspec
|
117
|
-
homepage: https://github.com/14tinchov/sphere-engine
|
114
|
+
homepage: https://github.com/14tinchov/sphere-engine.git
|
118
115
|
licenses:
|
119
116
|
- MIT
|
120
117
|
metadata:
|
@@ -130,9 +127,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
127
|
version: '0'
|
131
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
129
|
requirements:
|
133
|
-
- - "
|
130
|
+
- - ">"
|
134
131
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
132
|
+
version: 1.3.1
|
136
133
|
requirements: []
|
137
134
|
rubyforge_project:
|
138
135
|
rubygems_version: 2.6.10
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module SphereEngine
|
2
|
-
module REST
|
3
|
-
module Judges
|
4
|
-
include SphereEngine::REST::Utils
|
5
|
-
|
6
|
-
# @options [Hash]
|
7
|
-
def all_judges(options = {})
|
8
|
-
perform_get_requests_of_problems_service("/judges", options)
|
9
|
-
end
|
10
|
-
|
11
|
-
# @options [Hash]
|
12
|
-
def create_judge(options = {})
|
13
|
-
perform_post_requests_of_problems_service("/judges", options)
|
14
|
-
end
|
15
|
-
|
16
|
-
# @judge_id [String]
|
17
|
-
def get_judge(judge_id)
|
18
|
-
perform_get_requests_of_problems_service("/judges/#{judge_id}")
|
19
|
-
end
|
20
|
-
|
21
|
-
# @judge_id [String]
|
22
|
-
# @options [Hash]
|
23
|
-
def update_judge(judge_id, options = {})
|
24
|
-
perform_put_requests_of_problems_service("/judges/#{judge_id}", options)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module SphereEngine
|
2
|
-
module REST
|
3
|
-
module Problems
|
4
|
-
include SphereEngine::REST::Utils
|
5
|
-
|
6
|
-
# @param options [Hash]
|
7
|
-
# This request you could send a limit and offset
|
8
|
-
def all_problems(options = {})
|
9
|
-
perform_get_requests_of_problems_service('/problems', options)
|
10
|
-
end
|
11
|
-
|
12
|
-
# @param options [Hash]
|
13
|
-
# This request you could send a limit and offset
|
14
|
-
def create_problem(options = {})
|
15
|
-
perform_post_requests_of_problems_service('/problems', options)
|
16
|
-
end
|
17
|
-
|
18
|
-
# @param code [String]
|
19
|
-
def get_problem(code)
|
20
|
-
perform_get_requests_of_problems_service("/problems/#{code}")
|
21
|
-
end
|
22
|
-
|
23
|
-
# @param code [String]
|
24
|
-
# @param options [Hash]
|
25
|
-
def update_problem(code, options = {})
|
26
|
-
perform_put_requests_of_problems_service("/problems/#{code}", options)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module SphereEngine
|
2
|
-
module REST
|
3
|
-
module TestCases
|
4
|
-
include SphereEngine::REST::Utils
|
5
|
-
|
6
|
-
# @param problem_id [String]
|
7
|
-
def list_testcases(problem_id)
|
8
|
-
perform_get_requests_of_problems_service("/problems/#{problem_id}/testcases")
|
9
|
-
end
|
10
|
-
|
11
|
-
# @param problem_id [String]
|
12
|
-
# @options [Hash]
|
13
|
-
def create_problem_testcase(problem_id, options = {})
|
14
|
-
perform_post_requests_of_problems_service("/problems/#{problem_id}/testcases", options)
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param problem_id [String]
|
18
|
-
# @param testcase_id [String]
|
19
|
-
# @param options [Hash]
|
20
|
-
def update_problem_testcase(problem_id, testcase_id, options = {})
|
21
|
-
perform_put_requests_of_problems_service("/problems/#{problem_id}/testcases/#{testcase_id}", options)
|
22
|
-
end
|
23
|
-
|
24
|
-
# @param problem_id [String]
|
25
|
-
# @param testcase_id [String]
|
26
|
-
def get_testcase(problem_id, testcase_id)
|
27
|
-
perform_get_requests_of_problems_service("/problems/#{problem_id}/testcases/#{testcase_id}")
|
28
|
-
end
|
29
|
-
|
30
|
-
# @param problem_id [String]
|
31
|
-
# @param testcase_id [String]
|
32
|
-
# @param filename [String]
|
33
|
-
def get_testcase_file(problem_id, testcase_id, filename)
|
34
|
-
perform_get_requests_of_problems_service(
|
35
|
-
"/problems/#{problem_id}/testcases/#{testcase_id}/#{filename}"
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|