sphere_engine 1.1.0.pre → 1.1.0

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: 19dd5822f35e71acf45b5a681638263f902fb5ac
4
- data.tar.gz: 4ec00eef5296ed39f3d7a4eecf215354aadcfa9c
3
+ metadata.gz: 5b3ca098e7a4a9a7c1f4e26e57c1b26dda122f0e
4
+ data.tar.gz: f5cac2729b6692aced04e82d4f779a3c9810f28e
5
5
  SHA512:
6
- metadata.gz: 68eadff2c3fb4b4069d0efcb88a5722007b6317d9af36e7352a40eb7f41654d81297c015e69021c64be3051a8666ea426dc4d800cfb4c4d00f3f160a04dfe917
7
- data.tar.gz: 4180592fef9526408906a01b7be6247c1922191c6bcca97b1bf2bee1ca9565f63da7cf90cdf0ec801a16917c9a7455cc19de4fa4d67c215abf58375196624035
6
+ metadata.gz: 3421580af61881a0ef3d119d8bf1e8aae84dcd16c95fb1dba637f42b5ab0fb2bbee00bbef677c78ef9f57e7060b39889a9943aaaae1ec05d6ca259b69405ad88
7
+ data.tar.gz: 7e58c0bdef13bf8ca3644840c91d2e687b848a3c058b42d64f27c16b6851dbf7abc096bd088ed493a512f9d0895e6acc3035ce9deba9fe3052f6bb6dc0469885
data/README.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # SphereEngine
2
2
 
3
- I'm working right now!
3
+ A Ruby interface to SphereEngine API. This gem was made as an interface to the SphereEngine API. It abstract in the best way all his methods that SphereEngine give us. This gem separates the requests into two types (compilers and problems), according to the SphereEngine documentation. For more information about SphereEngine visit this [Link](http://sphere-engine.com)
4
+
5
+ ## Prerequisites
6
+
7
+ You need the following tokens:
8
+
9
+ * Token for Compilers API
10
+ * Token for problems API
11
+
12
+ [SphereEngine Tokens](http://sphere-engine.com/tokens)
4
13
 
5
14
  ## Installation
6
15
 
@@ -18,9 +27,170 @@ Or install it yourself as:
18
27
 
19
28
  $ gem install sphere_engine
20
29
 
21
- ## Usage
30
+ ## Configuration
31
+
32
+ SphereEngine provide two services, one for compilers and another for problems. To start using a SpherEengine client do the following:
33
+
34
+ ```ruby
35
+ client = SphereEngine::REST::Client.new do |config|
36
+ config.access_token_compilers = "YOUR_ACCESS_TOKEN_COMPILERS"
37
+ config.access_token_problems = "YOUR_ACCESS_TOKEN_PROBLEMS"
38
+ end
39
+ ```
40
+
41
+ ## Usage Examples
42
+ After configuring a client, you can do the following things:
43
+
44
+ ### Compilers Service
45
+
46
+ #### Get languages
47
+ ```ruby
48
+ client.all_languages
49
+ ```
50
+
51
+ #### Get compilers
52
+ ```ruby
53
+ client.all_compilers
54
+ ```
22
55
 
23
- TODO: Write usage instructions here
56
+ #### Create a submission
57
+
58
+ This method return a submission_id
59
+ ```ruby
60
+ client.create_submission_compiler(
61
+ language: 11, #LanguageID
62
+ sourceCode: "#include <iostream>\n using namespace std;\n int main()\n {\n cout << \"Hello World\" << endl;\n return 0;\n }" #Code example
63
+ )
64
+ ```
65
+
66
+ *Other params: input [string]*
67
+
68
+ #### Fetch a submission
69
+ ```ruby
70
+ client.fetch_submission_compilers(submission_id)
71
+ ```
72
+
73
+ ### 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
+ ```
24
194
 
25
195
  ## Development
26
196
 
@@ -32,8 +202,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
202
 
33
203
  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.
34
204
 
35
-
36
205
  ## License
37
206
 
38
207
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
208
 
209
+
data/bin/console CHANGED
@@ -8,7 +8,7 @@ require "sphere_engine"
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
10
  require "pry"
11
- Pry.start
11
+ # Pry.start
12
12
 
13
13
  require "irb"
14
14
  IRB.start(__FILE__)
@@ -31,7 +31,7 @@ module SphereEngine
31
31
  # @return[String]
32
32
  def get_token(service)
33
33
  return case service
34
- when :compillers
34
+ when :compilers
35
35
  access_token_compilers
36
36
  when :problems
37
37
  access_token_problems
@@ -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
@@ -1,12 +1,22 @@
1
1
  require 'sphere_engine/rest/access'
2
+ require 'sphere_engine/rest/languages'
2
3
  require 'sphere_engine/rest/compilers'
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'
3
8
 
4
9
  module SphereEngine
5
10
  module REST
6
11
  # @note All methods have been separated into modules and follow the same grouping used in {http://sphere-engine.com/services the SphereEngine API Documentation}.
7
12
  module API
8
13
  include SphereEngine::REST::Access
14
+ include SphereEngine::REST::Languages
9
15
  include SphereEngine::REST::Compilers
16
+ include SphereEngine::REST::Submissions
17
+ include SphereEngine::REST::Problems
18
+ include SphereEngine::REST::TestCases
19
+ include SphereEngine::REST::Judges
10
20
  end
11
21
  end
12
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,11 @@
1
+ module SphereEngine
2
+ module REST
3
+ module Languages
4
+ include SphereEngine::REST::Utils
5
+
6
+ def all_languages
7
+ perform_get_requests_of_compílers_service('/languages')
8
+ end
9
+ end
10
+ end
11
+ 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
@@ -1,10 +1,11 @@
1
1
  require 'addressable/uri'
2
2
  require 'http'
3
+ require 'json'
3
4
 
4
5
  module SphereEngine
5
6
  module REST
6
7
  class Request
7
- BASE_URL_COMPILERS_SERVICE = 'https://09de42b6.compilers.sphere-engine.com/api/V3/'.freeze
8
+ BASE_URL_COMPILERS_SERVICE = 'https://09de42b6.compilers.sphere-engine.com/api/V3'.freeze
8
9
  BASE_URL_PROBLEMS_SERVICE = 'https://09de42b6.problems.sphere-engine.com/api/v3'.freeze
9
10
  attr_accessor :client, :headers, :options, :service, :path, :request_method, :uri
10
11
 
@@ -17,6 +18,7 @@ module SphereEngine
17
18
  @client = client
18
19
  @token = client.get_token(service)
19
20
  @service = service
21
+ @request_method = request_method
20
22
  @uri = Addressable::URI.parse(path.start_with?('http') ? path : build_base_url + path)
21
23
  @path = uri.path
22
24
  @options = options
@@ -24,11 +26,19 @@ module SphereEngine
24
26
 
25
27
  # @return [Array, Hash]
26
28
  def perform
27
- response = HTTP.get(uri, :params => {:access_token => @token})
28
- response_body = response.body.empty? ? '' : symbolize_keys!(response.parse)
29
+ response = build_http_request
30
+ response_body = response.body.empty? ? '' : format_to_response(response)
29
31
  fail_or_return_response_body(response.code, response_body)
30
32
  end
31
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
+
32
42
  def fail_or_return_response_body(code, body)
33
43
  error = error(code, body)
34
44
  raise(error) if error
@@ -42,27 +52,31 @@ module SphereEngine
42
52
  end
43
53
  end
44
54
 
45
- def symbolize_keys!(object)
46
- if object.is_a?(Array)
47
- object.each_with_index do |val, index|
48
- object[index] = symbolize_keys!(val)
49
- end
50
- elsif object.is_a?(Hash)
51
- object.keys.each do |key|
52
- object[key.to_sym] = symbolize_keys!(object.delete(key))
53
- end
54
- end
55
- object
56
- end
57
-
58
55
  def build_base_url
59
56
  return case @service
60
- when :compillers
57
+ when :compilers
61
58
  BASE_URL_COMPILERS_SERVICE
62
59
  when :problems
63
60
  BASE_URL_PROBLEMS_SERVICE
64
61
  end
65
62
  end
63
+
64
+ def build_http_request
65
+ return case @request_method
66
+ when :get
67
+ HTTP.get(uri, params: build_request_params)
68
+ when :post
69
+ HTTP.post(uri, params: build_request_params)
70
+ when :put
71
+ HTTP.put(uri, params: build_request_params)
72
+ end
73
+ end
74
+
75
+ def build_request_params
76
+ {
77
+ access_token: @token
78
+ }.merge(options)
79
+ end
66
80
  end
67
81
  end
68
82
  end
@@ -0,0 +1,29 @@
1
+ module SphereEngine
2
+ module REST
3
+ module Submissions
4
+ include SphereEngine::REST::Utils
5
+
6
+ # @param options [Hash]
7
+ # This request you should send a compilerId and source
8
+ def create_submission_compiler(options = {})
9
+ perform_post_requests_of_compílers_service('/submissions', options)
10
+ end
11
+
12
+ # @param options [Hash]
13
+ # This request you should send a submissionId
14
+ def fetch_submission_compilers(submission_id, options = {})
15
+ perform_get_requests_of_compílers_service("/submissions/#{submission_id}")
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
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,40 @@
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
@@ -12,6 +12,18 @@ module SphereEngine
12
12
  perform_request(:get, :compilers, path, options)
13
13
  end
14
14
 
15
+ def perform_post_requests_of_problems_service(path, options = {})
16
+ perform_request(:post, :problems, path, options)
17
+ end
18
+
19
+ def perform_post_requests_of_compílers_service(path, options = {})
20
+ perform_request(:post, :compilers, path, options)
21
+ end
22
+
23
+ def perform_put_requests_of_problems_service(path, options = {})
24
+ perform_request(:put, :problems, path, options)
25
+ end
26
+
15
27
  def perform_request(request_method, service, path, options = {})
16
28
  SphereEngine::REST::Request.new(self, request_method, service, path, options).perform
17
29
  end
@@ -1,5 +1,5 @@
1
1
  module SphereEngine
2
2
  unless defined?(SphereEngine::VERSION)
3
- VERSION = "1.1.0.pre".freeze
3
+ VERSION = "1.1.0".freeze
4
4
  end
5
5
  end
@@ -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 = spec.summary
20
- spec.homepage = "https://github.com/14tinchov/sphere-engine.git"
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"
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.1.0.pre
4
+ version: 1.1.0
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-14 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -80,7 +80,8 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.0'
83
- description: A Ruby interface to the SphereEngine API.
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
85
  email:
85
86
  - 14tinchov@gmail.com
86
87
  executables: []
@@ -104,11 +105,16 @@ files:
104
105
  - lib/sphere_engine/rest/api.rb
105
106
  - lib/sphere_engine/rest/client.rb
106
107
  - lib/sphere_engine/rest/compilers.rb
108
+ - lib/sphere_engine/rest/judges.rb
109
+ - lib/sphere_engine/rest/languages.rb
110
+ - lib/sphere_engine/rest/problems.rb
107
111
  - lib/sphere_engine/rest/request.rb
112
+ - lib/sphere_engine/rest/submissions.rb
113
+ - lib/sphere_engine/rest/test_cases.rb
108
114
  - lib/sphere_engine/rest/utils.rb
109
115
  - lib/sphere_engine/version.rb
110
116
  - sphere_engine.gemspec
111
- homepage: https://github.com/14tinchov/sphere-engine.git
117
+ homepage: https://github.com/14tinchov/sphere-engine
112
118
  licenses:
113
119
  - MIT
114
120
  metadata:
@@ -124,9 +130,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
130
  version: '0'
125
131
  required_rubygems_version: !ruby/object:Gem::Requirement
126
132
  requirements:
127
- - - ">"
133
+ - - ">="
128
134
  - !ruby/object:Gem::Version
129
- version: 1.3.1
135
+ version: '0'
130
136
  requirements: []
131
137
  rubyforge_project:
132
138
  rubygems_version: 2.6.10