Class: SphereEngine::SphereEngineClient

Inherits:
Object
  • Object
show all
Defined in:
lib/sphereengine-ruby/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ SphereEngineClient

Returns a new instance of SphereEngineClient.



7
8
9
# File 'lib/sphereengine-ruby/client.rb', line 7

def initialize(token)
  @access_token = token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



5
6
7
# File 'lib/sphereengine-ruby/client.rb', line 5

def access_token
  @access_token
end

Instance Method Details

#fetch_submission(id, with_source = true, with_input = true, with_output = true, with_stderr = true, with_cmpinfo = true) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sphereengine-ruby/client.rb', line 30

def fetch_submission(id, with_source = true, 
                         with_input = true, 
                         with_output = true, 
                         with_stderr = true, 
                         with_cmpinfo = true)
  uri = URI(SphereEngine::Request::BASE_URL + 
            SphereEngine::Request::FETCH_SUBMISSION_ENDPOINT.sub(':id', id.to_s))
  uri.query = URI.encode_www_form({"access_token" => access_token,
                                   "withSource" => with_source, 
                                   "withInput" => with_input, 
                                   "withOutput" => with_output,
                                   "withStderr" => with_stderr,
                                   "withCmpinfo" => with_cmpinfo})
  JSON.parse Net::HTTP.get_response(uri).body
end

#languagesObject



17
18
19
20
21
# File 'lib/sphereengine-ruby/client.rb', line 17

def languages
  uri = URI(SphereEngine::Request::BASE_URL + SphereEngine::Request::LANGUAGES_ENDPOINT)
  uri.query = URI.encode_www_form({"access_token" => access_token})
  JSON.parse Net::HTTP.get_response(uri).body
end

#send_submission(source_code, language, input) ⇒ Object



23
24
25
26
27
28
# File 'lib/sphereengine-ruby/client.rb', line 23

def send_submission(source_code, language, input)
  uri = URI(SphereEngine::Request::BASE_URL + SphereEngine::Request::SUBMISSIONS_ENDPOINT)
  uri.query = URI.encode_www_form({"access_token" => access_token})
  response = Net::HTTP.post_form(uri, {'sourceCode' => source_code, 'language' => language, 'input' => input})
  JSON.parse response.body
end

#test_connectionObject



11
12
13
14
15
# File 'lib/sphereengine-ruby/client.rb', line 11

def test_connection
  uri = URI(SphereEngine::Request::BASE_URL + SphereEngine::Request::TEST_ENDPOINT)
  uri.query = URI.encode_www_form({"access_token" => access_token})
  JSON.parse Net::HTTP.get_response(uri).body
end