Class: Ideone

Inherits:
Object
  • Object
show all
Defined in:
lib/ideone.rb

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, password = nil) ⇒ Ideone

Returns a new instance of Ideone.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ideone.rb', line 13

def initialize(username=nil, password=nil)
  @username = username
  @password = password
  
  @client = Savon::Client.new do
    wsdl.document = "http://ideone.com/api/1/service.wsdl"
  end

  HTTPI.log = false
  disable_savon_logging()
  
  @request_body = {
    :user => @username,
    :pass => @password,
  }
  @languages_cache = nil
end

Instance Method Details

#create_submission(source_code, lang_id, std_input = "", run = true, is_private = false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ideone.rb', line 31

def create_submission(source_code, lang_id, std_input="", run=true,
                      is_private=false)
  request_body = @request_body
  request_body[:sourceCode] = source_code
  request_body[:language] = lang_id
  request_body[:input] = std_input
  request_body[:run] = run
  request_body[:private] = is_private
  response = @client.request :createSubmission, :body => @request_body

  check_error(response, :create_submission_response)
  return response.to_hash[:create_submission_response][:return][:item][1][:value]
end

#languagesObject

Get a list of supported languages and cache it.



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ideone.rb', line 86

def languages
  unless @languages_cache
    response = @client.request :getLanguages, :body => @request_body

    check_error(response, :get_languages_response)

    languages = response.to_hash[:get_languages_response][:return][:item][1][:value][:item]
    # Create a sorted hash
    @languages_cache = Hash[create_dict(languages).sort_by{|k,v| k.to_i}]
  end
  return @languages_cache
end

#submission_details(link, with_source = true, with_input = true, with_output = true, with_stderr = true, with_cmpinfo = true) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ideone.rb', line 62

def submission_details(link,
                       with_source=true,
                       with_input=true,
                       with_output=true,
                       with_stderr=true,
                       with_cmpinfo=true)
  request_body = @request_body
  request_body[:link] = link
  request_body[:withSource] = with_source
  request_body[:withInput] = with_input
  request_body[:withOutput] = with_output
  request_body[:withStderr] = with_stderr
  request_body[:withCmpinfo] = with_cmpinfo

  response = @client.request :getSubmissionDetails, :body => request_body
  
  check_error(response, :get_submission_details_response)

  details = response.to_hash[:get_submission_details_response][:return][:item]
  
  create_dict(details)
end

#submission_status(link) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ideone.rb', line 45

def submission_status(link)
  request_body = @request_body
  request_body[:link] = link
  response = @client.request :getSubmissionStatus, :body => request_body

  check_error(response, :get_submission_status_response)

  status = response.to_hash[:get_submission_status_response][:return][:item][1][:value].to_i
  result = response.to_hash[:get_submission_status_response][:return][:item][2][:value].to_i
  
  if status < 0
    status = -1
  end

  return { :status => status, :result => result }
end

#testObject

A test function that always returns the same thing.



100
101
102
103
104
105
106
107
# File 'lib/ideone.rb', line 100

def test
  response = @client.request :testFunction, :body => @request_body

  check_error(response, :test_function_response)

  items = response.to_hash[:test_function_response][:return][:item]
  create_dict(items)
end