Class: Ideone

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

Defined Under Namespace

Modules: Version

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
# File 'lib/ideone.rb', line 13

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

  HTTPI.log = false
  
  @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



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ideone.rb', line 28

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.call(:create_submission, :message => @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.



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ideone.rb', line 83

def languages
  unless @languages_cache
    response = @client.call(:get_languages, :message => @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



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

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.call(:get_submission_details, :message => 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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ideone.rb', line 42

def submission_status(link)
  request_body = @request_body
  request_body[:link] = link
  response = @client.call(:get_submission_status, :message => 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.



97
98
99
100
101
102
103
104
# File 'lib/ideone.rb', line 97

def test
  response = @client.call(:test_function, :message => @request_body)

  check_error(response, :test_function_response)

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