sphere_engine 1.0.0 → 1.1.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: bb4c0b4802e0142d313d57835ca9e61df92b74dd
4
- data.tar.gz: 7faa61513560ef2f210603f7a8d08723b07eba2b
3
+ metadata.gz: 19dd5822f35e71acf45b5a681638263f902fb5ac
4
+ data.tar.gz: 4ec00eef5296ed39f3d7a4eecf215354aadcfa9c
5
5
  SHA512:
6
- metadata.gz: 99ffaa5b7d41ffb32c1940e0e9af831bb5dcde4cc4eae54cbaff7f1d5bf3547b8dd1429e2e2a666bc0317dbb2a5883372b6f0e9569b28ef838a62e097dc5794e
7
- data.tar.gz: 72d6196504a31309d15f0b97beb3932d167a54057d11c7e5cb3fa5ea70be088bb9ab328b84e7508841c5c0e9ad4c159209d1991c558430681953feaf714684d1
6
+ metadata.gz: 68eadff2c3fb4b4069d0efcb88a5722007b6317d9af36e7352a40eb7f41654d81297c015e69021c64be3051a8666ea426dc4d800cfb4c4d00f3f160a04dfe917
7
+ data.tar.gz: 4180592fef9526408906a01b7be6247c1922191c6bcca97b1bf2bee1ca9565f63da7cf90cdf0ec801a16917c9a7455cc19de4fa4d67c215abf58375196624035
data/README.md CHANGED
@@ -1,15 +1,6 @@
1
1
  # SphereEngine
2
2
 
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)
3
+ I'm working right now!
13
4
 
14
5
  ## Installation
15
6
 
@@ -27,153 +18,9 @@ Or install it yourself as:
27
18
 
28
19
  $ gem install sphere_engine
29
20
 
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
- ```
55
-
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
- #### 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
21
+ ## Usage
106
22
 
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
- ```
23
+ TODO: Write usage instructions here
177
24
 
178
25
  ## Development
179
26
 
@@ -185,8 +32,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
185
32
 
186
33
  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.
187
34
 
35
+
188
36
  ## License
189
37
 
190
38
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
191
39
 
192
-
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 :compilers
34
+ when :compillers
35
35
  access_token_compilers
36
36
  when :problems
37
37
  access_token_problems
@@ -43,8 +43,19 @@ module SphereEngine
43
43
  def parse_error(body)
44
44
  if body.nil? || body.empty?
45
45
  ['', nil]
46
- elsif body["message"] || body[:message]
47
- [ body["message"] || body[:message], 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]
48
59
  end
49
60
  end
50
61
  end
@@ -1,22 +1,12 @@
1
1
  require 'sphere_engine/rest/access'
2
- require 'sphere_engine/rest/languages'
3
2
  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'
8
3
 
9
4
  module SphereEngine
10
5
  module REST
11
6
  # @note All methods have been separated into modules and follow the same grouping used in {http://sphere-engine.com/services the SphereEngine API Documentation}.
12
7
  module API
13
8
  include SphereEngine::REST::Access
14
- include SphereEngine::REST::Languages
15
9
  include SphereEngine::REST::Compilers
16
- include SphereEngine::REST::Submissions
17
- include SphereEngine::REST::Problems
18
- include SphereEngine::REST::TestCases
19
- include SphereEngine::REST::Judges
20
10
  end
21
11
  end
22
12
  end
@@ -1,11 +1,10 @@
1
1
  require 'addressable/uri'
2
2
  require 'http'
3
- require 'json'
4
3
 
5
4
  module SphereEngine
6
5
  module REST
7
6
  class Request
8
- BASE_URL_COMPILERS_SERVICE = 'https://09de42b6.compilers.sphere-engine.com/api/V3'.freeze
7
+ BASE_URL_COMPILERS_SERVICE = 'https://09de42b6.compilers.sphere-engine.com/api/V3/'.freeze
9
8
  BASE_URL_PROBLEMS_SERVICE = 'https://09de42b6.problems.sphere-engine.com/api/v3'.freeze
10
9
  attr_accessor :client, :headers, :options, :service, :path, :request_method, :uri
11
10
 
@@ -18,7 +17,6 @@ module SphereEngine
18
17
  @client = client
19
18
  @token = client.get_token(service)
20
19
  @service = service
21
- @request_method = request_method
22
20
  @uri = Addressable::URI.parse(path.start_with?('http') ? path : build_base_url + path)
23
21
  @path = uri.path
24
22
  @options = options
@@ -26,19 +24,11 @@ module SphereEngine
26
24
 
27
25
  # @return [Array, Hash]
28
26
  def perform
29
- response = build_http_request
30
- response_body = response.body.empty? ? '' : format_to_response(response)
27
+ response = HTTP.get(uri, :params => {:access_token => @token})
28
+ response_body = response.body.empty? ? '' : symbolize_keys!(response.parse)
31
29
  fail_or_return_response_body(response.code, response_body)
32
30
  end
33
31
 
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
32
  def fail_or_return_response_body(code, body)
43
33
  error = error(code, body)
44
34
  raise(error) if error
@@ -52,31 +42,27 @@ module SphereEngine
52
42
  end
53
43
  end
54
44
 
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
+
55
58
  def build_base_url
56
59
  return case @service
57
- when :compilers
60
+ when :compillers
58
61
  BASE_URL_COMPILERS_SERVICE
59
62
  when :problems
60
63
  BASE_URL_PROBLEMS_SERVICE
61
64
  end
62
65
  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
80
66
  end
81
67
  end
82
68
  end
@@ -12,18 +12,6 @@ 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
-
27
15
  def perform_request(request_method, service, path, options = {})
28
16
  SphereEngine::REST::Request.new(self, request_method, service, path, options).perform
29
17
  end
@@ -1,5 +1,5 @@
1
1
  module SphereEngine
2
2
  unless defined?(SphereEngine::VERSION)
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.1.0.pre".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 = %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 = spec.summary
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.0.0
4
+ version: 1.1.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-16 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -80,8 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.0'
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.
83
+ description: A Ruby interface to the SphereEngine API.
85
84
  email:
86
85
  - 14tinchov@gmail.com
87
86
  executables: []
@@ -105,16 +104,11 @@ files:
105
104
  - lib/sphere_engine/rest/api.rb
106
105
  - lib/sphere_engine/rest/client.rb
107
106
  - 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
111
107
  - lib/sphere_engine/rest/request.rb
112
- - lib/sphere_engine/rest/submissions.rb
113
- - lib/sphere_engine/rest/test_cases.rb
114
108
  - lib/sphere_engine/rest/utils.rb
115
109
  - lib/sphere_engine/version.rb
116
110
  - sphere_engine.gemspec
117
- homepage: https://github.com/14tinchov/sphere-engine
111
+ homepage: https://github.com/14tinchov/sphere-engine.git
118
112
  licenses:
119
113
  - MIT
120
114
  metadata:
@@ -130,9 +124,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
124
  version: '0'
131
125
  required_rubygems_version: !ruby/object:Gem::Requirement
132
126
  requirements:
133
- - - ">="
127
+ - - ">"
134
128
  - !ruby/object:Gem::Version
135
- version: '0'
129
+ version: 1.3.1
136
130
  requirements: []
137
131
  rubyforge_project:
138
132
  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,11 +0,0 @@
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
@@ -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,29 +0,0 @@
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
@@ -1,33 +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
- 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