Class: Ideone::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, password = nil, verbose = false) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
# File 'lib/ideone.rb', line 18

def initialize(username=nil, password=nil, verbose=false)
  @client = Savon.client(wsdl: "http://ideone.com/api/1/service.wsdl", log: verbose)
  @languages_cache = nil
  @request_body = {
    :user => username,
    :pass => password,
  }
end

Instance Method Details

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



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

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 = call_request(:create_submission)

  return response.to_hash[:create_submission_response][:return][:item][1][:value]
end

#languagesObject

Get a list of supported languages and cache it.



79
80
81
82
83
84
85
86
87
88
# File 'lib/ideone.rb', line 79

def languages
  unless @languages_cache
    response = call_request(:get_languages)

    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



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

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 = call_request(:get_submission_details)

  details = response.to_hash[:get_submission_details_response][:return][:item]

  create_dict(details)
end

#submission_status(link) ⇒ Object



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

def submission_status(link)
  request_body = @request_body
  request_body[:link] = link

  response = call_request(:get_submission_status)

  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.



91
92
93
94
95
96
97
# File 'lib/ideone.rb', line 91

def test
  response = call_request(:test_function)

  items = response.to_hash[:test_function_response][:return][:item]

  return create_dict(items)
end