sphere_engine 1.2.0.pre → 1.3.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95dd43bce3035dfb25da29ca8f9030042c84b9e7
4
- data.tar.gz: a86375f56f07089e18aeed201ebf3d3dd162e280
3
+ metadata.gz: 85ffebbdcb50dd3a459d3f218d5f0a71ea013b71
4
+ data.tar.gz: c56fbeb10283601a2e519798cddeb12890599d99
5
5
  SHA512:
6
- metadata.gz: 3abe457a37ea224933c5520ef4460222a9f8db15c51cb73de90e12377de7c8787008a5d479f308c5b893662e82150d91345c78dcdde33dccaf11b58e0e406d30
7
- data.tar.gz: 9879b770557422348a2c1904b0d9031ff9d0c789f379b924869bac1879fdeb586487f34c2153a029302b83031f1d5bf06dea7044a3950be6c94ceaa16e0abbc0
6
+ metadata.gz: 5e4b68f18ab79b7b3442c5874768207d719dfddaa6dab3518e4984f5c11a8245b6a61a63d117aaffd420900aa50a630cf17760e3e2e355318c313b6f773e15f5
7
+ data.tar.gz: d1c931605c1f609e2e884069d71bba064207e10013b56fc3f4e67232476bba7bec23a028c7fcab4d61265371d34b5924b7aa49442b75486d5a84b2ab6663d54c
data/README.md CHANGED
@@ -41,34 +41,139 @@ end
41
41
  ## Usage Examples
42
42
  After configuring a client, you can do the following things:
43
43
 
44
- ### Get compilers
45
- ```ruby
46
- client.all_compilers
47
- ```
44
+ ### Compilers Service
48
45
 
49
- ### Get languages
46
+ #### Get languages
50
47
  ```ruby
51
48
  client.all_languages
52
49
  ```
53
50
 
51
+ #### Get compilers
52
+ ```ruby
53
+ client.all_compilers
54
+ ```
54
55
 
55
- ### Create a submission (Compilers service)
56
+ #### Create a submission
56
57
 
57
58
  This method return a submission_id
58
59
  ```ruby
59
60
  client.create_submission_compiler(
60
61
  language: 11, #LanguageID
61
- sourceCode: "#include int main(){ printf(\"Hello!\"); return 0; }" #Code
62
+ sourceCode: "#include <iostream>\n using namespace std;\n int main()\n {\n cout << \"Hello World\" << endl;\n return 0;\n }" #Code example
62
63
  )
63
64
  ```
64
65
 
65
- ### Fetch a submission (Compilers service)
66
+ *Other params: input [string]*
67
+
68
+ #### Fetch a submission
66
69
  ```ruby
67
70
  client.fetch_submission_compilers(submission_id)
68
71
  ```
69
72
 
70
73
  ### Problems service
71
- Coming soon
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
+ #### Create testcase to problem
87
+
88
+ ```ruby
89
+ client.create_problem_testcase(
90
+ "PROBLEM_ID",
91
+ input: "input content",
92
+ timelimit: 10,
93
+ output: "output content"
94
+ )
95
+ ```
96
+
97
+ #### Update a problem
98
+
99
+ ```ruby
100
+ client.update_problem("PROBLEM_ID", name: "NEW_NAME")
101
+ ```
102
+
103
+ *Other params: type [string], interactive [boolean], masterjudgeId [integer], activeTestcases [array]*
104
+
105
+ #### Get a list testcases of a problem
106
+
107
+ ```ruby
108
+ client.list_testcases("PROBLEM_ID")
109
+ ```
110
+
111
+ #### Get a testcase of a problem
112
+
113
+ ```ruby
114
+ client.get_testcase("PROBLEM_ID", "TESTCASE_ID")
115
+ ```
116
+
117
+ #### Get a file testcases of a problem
118
+ ```ruby
119
+ client.get_testcase_file("PROBLEM_ID", "TESTCASE_ID", "FILENAME")
120
+ ```
121
+
122
+ *Filename is obtained from get_testcase request in uri params*
123
+
124
+ #### Get judge list
125
+
126
+ ```ruby
127
+ client.all_judges()
128
+ ```
129
+
130
+ *Other params: limit [Integer], offset [Integer], type [String]*
131
+
132
+ #### Create judge
133
+
134
+ ```ruby
135
+ client.create_judge(
136
+ name: "NameJudge",
137
+ source: "<source code>"
138
+ )
139
+ ```
140
+
141
+ *Other params: type [String], compilerId [Integer]*
142
+
143
+ #### Get judge details
144
+
145
+ ```ruby
146
+ client..get_judge("JUDGE_ID")
147
+ ```
148
+
149
+ #### Update judge
150
+
151
+ ```ruby
152
+ client.update_judge(
153
+ "JUDGE_ID",
154
+ name: "NewNameJudge",
155
+ )
156
+ ```
157
+
158
+ *Other params: source [String], compilerId [Integer]*
159
+
160
+ #### Create a submission
161
+
162
+ ```ruby
163
+ client.create_submission_problem(
164
+ problemCode: "RUBY_001", #problem_id
165
+ compilerId: 1, # get of all_request
166
+ source: "#include <iostream>\n using namespace std;\n int main()\n {\n cout << \"Hello World\" << endl;\n return 0;\n }" #Example
167
+ )
168
+ ```
169
+
170
+ *Other params: userId [Integer]*
171
+
172
+ #### Fetch a submission
173
+
174
+ ```ruby
175
+ client.fetch_submission_problems("SUBMISSION_ID")
176
+ ```
72
177
 
73
178
  ## Development
74
179
 
@@ -80,8 +185,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
80
185
 
81
186
  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.
82
187
 
83
-
84
188
  ## License
85
189
 
86
190
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
87
191
 
192
+
@@ -43,19 +43,8 @@ module SphereEngine
43
43
  def parse_error(body)
44
44
  if body.nil? || body.empty?
45
45
  ['', nil]
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]
46
+ elsif body["message"] || body[:message]
47
+ [ body["message"] || body[:message], nil]
59
48
  end
60
49
  end
61
50
  end
@@ -2,6 +2,9 @@ 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'
5
8
 
6
9
  module SphereEngine
7
10
  module REST
@@ -11,6 +14,9 @@ module SphereEngine
11
14
  include SphereEngine::REST::Languages
12
15
  include SphereEngine::REST::Compilers
13
16
  include SphereEngine::REST::Submissions
17
+ include SphereEngine::REST::Problems
18
+ include SphereEngine::REST::TestCases
19
+ include SphereEngine::REST::Judges
14
20
  end
15
21
  end
16
22
  end
@@ -0,0 +1,28 @@
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
@@ -0,0 +1,30 @@
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
@@ -27,10 +27,18 @@ module SphereEngine
27
27
  # @return [Array, Hash]
28
28
  def perform
29
29
  response = build_http_request
30
- response_body = response.body.empty? ? '' : JSON.parse(response.to_s)
30
+ response_body = response.body.empty? ? '' : format_to_response(response)
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
+
34
42
  def fail_or_return_response_body(code, body)
35
43
  error = error(code, body)
36
44
  raise(error) if error
@@ -59,6 +67,8 @@ module SphereEngine
59
67
  HTTP.get(uri, params: build_request_params)
60
68
  when :post
61
69
  HTTP.post(uri, params: build_request_params)
70
+ when :put
71
+ HTTP.put(uri, params: build_request_params)
62
72
  end
63
73
  end
64
74
 
@@ -1,6 +1,8 @@
1
1
  module SphereEngine
2
2
  module REST
3
3
  module Submissions
4
+ include SphereEngine::REST::Utils
5
+
4
6
  # @param options [Hash]
5
7
  # This request you should send a compilerId and source
6
8
  def create_submission_compiler(options = {})
@@ -12,6 +14,16 @@ module SphereEngine
12
14
  def fetch_submission_compilers(submission_id, options = {})
13
15
  perform_get_requests_of_compílers_service("/submissions/#{submission_id}")
14
16
  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
15
27
  end
16
28
  end
17
- end
29
+ end
@@ -0,0 +1,33 @@
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
+ def get_testcase(problem_id, testcase_id)
20
+ perform_get_requests_of_problems_service("/problems/#{problem_id}/testcases/#{testcase_id}")
21
+ end
22
+
23
+ # @param problem_id [String]
24
+ # @param testcase_id [String]
25
+ # @param filename [String]
26
+ def get_testcase_file(problem_id, testcase_id, filename)
27
+ perform_get_requests_of_problems_service(
28
+ "/problems/#{problem_id}/testcases/#{testcase_id}/#{filename}"
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -20,6 +20,10 @@ 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
+
23
27
  def perform_request(request_method, service, path, options = {})
24
28
  SphereEngine::REST::Request.new(self, request_method, service, path, options).perform
25
29
  end
@@ -1,5 +1,5 @@
1
1
  module SphereEngine
2
2
  unless defined?(SphereEngine::VERSION)
3
- VERSION = "1.2.0.pre".freeze
3
+ VERSION = "1.3.0.pre".freeze
4
4
  end
5
5
  end
@@ -16,7 +16,7 @@ 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}
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
20
  spec.homepage = "https://github.com/14tinchov/sphere-engine.git"
21
21
  spec.license = "MIT"
22
22
 
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.2.0.pre
4
+ version: 1.3.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-15 00:00:00.000000000 Z
11
+ date: 2017-04-16 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,9 +105,12 @@ 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
108
109
  - lib/sphere_engine/rest/languages.rb
110
+ - lib/sphere_engine/rest/problems.rb
109
111
  - lib/sphere_engine/rest/request.rb
110
112
  - lib/sphere_engine/rest/submissions.rb
113
+ - lib/sphere_engine/rest/test_cases.rb
111
114
  - lib/sphere_engine/rest/utils.rb
112
115
  - lib/sphere_engine/version.rb
113
116
  - sphere_engine.gemspec