ideone-ruby-api 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -2
- data/README.rdoc +34 -8
- data/VERSION +1 -1
- data/ideone-ruby-api.gemspec +2 -8
- data/lib/ideone.rb +68 -91
- data/test/test_ideone-ruby-api.rb +15 -7
- metadata +13 -35
data/Gemfile
CHANGED
@@ -7,10 +7,8 @@ gem 'savon'
|
|
7
7
|
# Add dependencies to develop your gem here.
|
8
8
|
# Include everything needed to run rake, tests, features, etc.
|
9
9
|
group :development do
|
10
|
-
gem "shoulda", ">= 0"
|
11
10
|
gem "bundler", "~> 1.0.0"
|
12
11
|
gem "jeweler", "~> 1.6.4"
|
13
12
|
gem "rcov", ">= 0"
|
14
13
|
gem "test-unit", "~> 2.3"
|
15
|
-
gem "rspec"
|
16
14
|
end
|
data/README.rdoc
CHANGED
@@ -1,32 +1,58 @@
|
|
1
1
|
= ideone-ruby-api
|
2
2
|
|
3
|
-
Ideone is a pastebin, as well as an online compiler and debugger. This
|
3
|
+
Ideone is a pastebin, as well as an online compiler and debugger. This
|
4
|
+
project is a Ruby binding to the Ideone API.
|
4
5
|
|
5
6
|
== Usage
|
6
7
|
|
7
8
|
require 'ideone'
|
8
9
|
|
9
10
|
# Authenticate with Ideone
|
10
|
-
i = Ideone('username', 'password')
|
11
|
-
|
11
|
+
i = Ideone.new('username', 'password')
|
12
|
+
=> #<Ideone:0x000000021dfd88 ... >
|
13
|
+
|
12
14
|
# Create submission
|
13
15
|
source_code = "puts 'hello, world'"
|
14
16
|
i.create_submission(source_code,
|
15
17
|
17) # Ruby
|
18
|
+
=> 'TOKEN'
|
16
19
|
|
17
20
|
# Get submission status
|
18
|
-
i.submission_status("
|
21
|
+
i.submission_status("TOKEN")
|
22
|
+
=> {:status=>0, :result=>15}
|
19
23
|
|
20
24
|
# Get all available languages
|
21
|
-
i.languages
|
25
|
+
i.languages
|
26
|
+
=> [{:key=>"7", :value=>"Ada (gnat-4.3.2)"},
|
27
|
+
{:key=>"13", :value=>"Assembler (nasm-2.07)"},
|
28
|
+
...
|
29
|
+
{:key=>"104", :value=>"AWK (gawk) (gawk-3.1.6)"},
|
30
|
+
{:key=>"6", :value=>"Whitespace (wspace 0.3)"}]
|
31
|
+
|
32
|
+
# Test that everything's working
|
33
|
+
i.test
|
34
|
+
=> {"error"=>"OK",
|
35
|
+
"moreHelp"=>"ideone.com",
|
36
|
+
"pi"=>"3.14",
|
37
|
+
"answerToLifeAndEverything"=>"42",
|
38
|
+
"oOok"=>true}
|
39
|
+
|
40
|
+
== Similar projects
|
22
41
|
|
23
|
-
|
24
|
-
|
42
|
+
- https://github.com/maveonair/ccpacona
|
43
|
+
- https://github.com/jonathanperret/ideone.rb
|
44
|
+
- https://github.com/Pistos/ideone-gem/blob/master/lib/ideone.rb
|
25
45
|
|
26
|
-
|
46
|
+
I stole the best ideas from each of the above projects, which, I
|
47
|
+
think, makes it much more robust, and it includes tests (which
|
48
|
+
actually pass).
|
49
|
+
|
50
|
+
== Running the test suite
|
27
51
|
|
28
52
|
To run the test suite, please fill out USER and PASS in test/test_ideone-ruby-api.rb
|
29
53
|
|
54
|
+
Then, you can run `rake test`
|
55
|
+
|
30
56
|
== Contributing to ideone-ruby-api
|
31
57
|
|
32
58
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/ideone-ruby-api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ideone-ruby-api}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kenny Meyer"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-08-01}
|
13
13
|
s.description = %q{A better Ruby binding for the Ideone API }
|
14
14
|
s.email = %q{knny.myer@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -39,29 +39,23 @@ Gem::Specification.new do |s|
|
|
39
39
|
|
40
40
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
41
|
s.add_runtime_dependency(%q<savon>, [">= 0"])
|
42
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
43
42
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
44
43
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
45
44
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
46
45
|
s.add_development_dependency(%q<test-unit>, ["~> 2.3"])
|
47
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
48
46
|
else
|
49
47
|
s.add_dependency(%q<savon>, [">= 0"])
|
50
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
51
48
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
49
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
50
|
s.add_dependency(%q<rcov>, [">= 0"])
|
54
51
|
s.add_dependency(%q<test-unit>, ["~> 2.3"])
|
55
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
56
52
|
end
|
57
53
|
else
|
58
54
|
s.add_dependency(%q<savon>, [">= 0"])
|
59
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
60
55
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
56
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
62
57
|
s.add_dependency(%q<rcov>, [">= 0"])
|
63
58
|
s.add_dependency(%q<test-unit>, ["~> 2.3"])
|
64
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
65
59
|
end
|
66
60
|
end
|
67
61
|
|
data/lib/ideone.rb
CHANGED
@@ -7,21 +7,10 @@
|
|
7
7
|
# License:: Distributes under the same terms as Ruby
|
8
8
|
|
9
9
|
require 'savon' # SOAP Client
|
10
|
-
require 'logger'
|
11
10
|
require 'pp'
|
12
11
|
|
13
|
-
Savon.configure do |config|
|
14
|
-
config.log = false # TODO: Make this a setting
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
12
|
class Ideone
|
19
13
|
|
20
|
-
# Keyword arguments
|
21
|
-
# -----------------
|
22
|
-
#
|
23
|
-
# * username: a valid Ideone username
|
24
|
-
# * password: a valid Ideone password
|
25
14
|
def initialize(username=nil, password=nil)
|
26
15
|
@username = username
|
27
16
|
@password = password
|
@@ -30,35 +19,16 @@ class Ideone
|
|
30
19
|
wsdl.document = "http://ideone.com/api/1/service.wsdl"
|
31
20
|
end
|
32
21
|
|
22
|
+
HTTPI.log = false
|
23
|
+
disable_savon_logging()
|
24
|
+
|
33
25
|
@request_body = {
|
34
26
|
:user => @username,
|
35
27
|
:pass => @password,
|
36
28
|
}
|
37
29
|
@languages_cache = nil
|
38
|
-
# Set up logger
|
39
|
-
@log = Logger.new(STDOUT)
|
40
|
-
@log.level = Logger::WARN
|
41
|
-
|
42
30
|
end
|
43
31
|
|
44
|
-
# Create a submission and upload it to Ideone.
|
45
|
-
#
|
46
|
-
# Keyword Arguments
|
47
|
-
# -----------------
|
48
|
-
#
|
49
|
-
# * source_code: a string of the program's source code
|
50
|
-
# * lang_id: the ID of the programming language.
|
51
|
-
# * std_input: the string to pass to the program on stdin
|
52
|
-
# * run: a boolean flag to signifying if Ideone should compile and
|
53
|
-
# run the program
|
54
|
-
# * is_private: a boolean flag to toggle visibility of code to others
|
55
|
-
#
|
56
|
-
# Returns
|
57
|
-
# -------
|
58
|
-
#
|
59
|
-
# A hash with the keys error and link. The link is the
|
60
|
-
# unique id of the program. The URL of the submission is
|
61
|
-
# http://ideone.com/LINK.
|
62
32
|
def create_submission(source_code, lang_id, std_input="", run=true,
|
63
33
|
is_private=false)
|
64
34
|
request_body = @request_body
|
@@ -69,62 +39,27 @@ class Ideone
|
|
69
39
|
request_body[:private] = is_private
|
70
40
|
response = @client.request :createSubmission, :body => @request_body
|
71
41
|
|
72
|
-
|
42
|
+
check_error(response, :create_submission_response)
|
43
|
+
return response.to_hash[:create_submission_response][:return][:item][1][:value]
|
73
44
|
end
|
74
45
|
|
75
|
-
# Given the unique link of a submission, returns its current status.
|
76
|
-
#
|
77
|
-
# Keyword Arguments
|
78
|
-
# -----------------
|
79
|
-
#
|
80
|
-
# * link: the unique id string of a submission
|
81
|
-
#
|
82
|
-
# Returns
|
83
|
-
# -------
|
84
|
-
#
|
85
|
-
# A hash of the error, the result code and the status code.
|
86
|
-
#
|
87
|
-
# Notes
|
88
|
-
# -----
|
89
|
-
#
|
90
|
-
# Status specifies the stage of execution.
|
91
|
-
#
|
92
|
-
# * status < 0 means the program awaits compilation
|
93
|
-
# * status == 0 means the program is done
|
94
|
-
# * status == 1 means the program is being compiled
|
95
|
-
# * status == 3 means the program is running
|
96
|
-
#
|
97
|
-
# Result specifies how the program finished.
|
98
|
-
#
|
99
|
-
# * result == 0 means not running, the program was submitted
|
100
|
-
# with run=False
|
101
|
-
# * result == 11 means compilation error
|
102
|
-
# * result == 12 means runtime error
|
103
|
-
# * result == 13 means timelimit exceeded
|
104
|
-
# * result == 15 means success
|
105
|
-
# * result == 17 means memory limit exceeded
|
106
|
-
# * result == 19 means illegal system call
|
107
|
-
# * result == 20 means Ideone internal error, submit a bug report
|
108
46
|
def submission_status(link)
|
109
47
|
request_body = @request_body
|
110
48
|
request_body[:link] = link
|
111
49
|
response = @client.request :getSubmissionStatus, :body => request_body
|
50
|
+
|
51
|
+
check_error(response, :get_submission_status_response)
|
52
|
+
|
53
|
+
status = response.to_hash[:get_submission_status_response][:return][:item][1][:value].to_i
|
54
|
+
result = response.to_hash[:get_submission_status_response][:return][:item][2][:value].to_i
|
112
55
|
|
113
|
-
|
56
|
+
if status < 0
|
57
|
+
status = -1
|
58
|
+
end
|
59
|
+
|
60
|
+
return { :status => status, :result => result }
|
114
61
|
end
|
115
62
|
|
116
|
-
# Return a hash of requested details about a submission with the id
|
117
|
-
# of link.
|
118
|
-
#
|
119
|
-
# Keyword Arguments
|
120
|
-
# -----------------
|
121
|
-
#
|
122
|
-
# * link: the unique string ID of a submission
|
123
|
-
# * with_source: should we request the source code
|
124
|
-
# * with_input: request the program input
|
125
|
-
# * with_output: request the program output
|
126
|
-
# * with_stderr: request the error output
|
127
|
-
# * with_cmpinfo: request compilation flags
|
128
63
|
def submission_details(link,
|
129
64
|
with_source=true,
|
130
65
|
with_input=true,
|
@@ -138,30 +73,72 @@ class Ideone
|
|
138
73
|
request_body[:withOutput] = with_output
|
139
74
|
request_body[:withStderr] = with_stderr
|
140
75
|
request_body[:withCmpinfo] = with_cmpinfo
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
76
|
+
|
77
|
+
response = @client.request :getSubmissionDetails, :body => request_body
|
78
|
+
|
79
|
+
check_error(response, :get_submission_details_response)
|
80
|
+
|
81
|
+
details = response.to_hash[:get_submission_details_response][:return][:item]
|
147
82
|
|
148
|
-
|
83
|
+
create_dict(details)
|
149
84
|
end
|
150
85
|
|
151
86
|
# Get a list of supported languages and cache it.
|
152
87
|
def languages
|
153
|
-
|
88
|
+
unless @languages_cache
|
154
89
|
response = @client.request :getLanguages, :body => @request_body
|
155
|
-
|
90
|
+
|
91
|
+
check_error(response, :get_languages_response)
|
92
|
+
|
93
|
+
languages = response.to_hash[:get_languages_response][:return][:item][1][:value][:item]
|
156
94
|
@languages_cache = languages
|
157
95
|
end
|
158
|
-
return
|
96
|
+
return @languages_cache
|
159
97
|
end
|
160
98
|
|
161
99
|
# A test function that always returns the same thing.
|
162
100
|
def test
|
163
101
|
response = @client.request :testFunction, :body => @request_body
|
102
|
+
|
103
|
+
check_error(response, :test_function_response)
|
104
|
+
|
105
|
+
items = response.to_hash[:test_function_response][:return][:item]
|
106
|
+
create_dict(items)
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def disable_savon_logging
|
112
|
+
Savon.configure do |config|
|
113
|
+
config.log = false
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_error(response, function_response)
|
118
|
+
error = get_error(response.to_hash, function_response)
|
119
|
+
if error != 'OK'
|
120
|
+
raise error
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_error(response, function_response)
|
125
|
+
begin
|
126
|
+
return response[function_response][:return][:item][0][:value]
|
127
|
+
rescue
|
128
|
+
return response[function_response][:return][:item][:value]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def create_dict(items)
|
133
|
+
dict = {}
|
134
|
+
|
135
|
+
items.each do |item|
|
136
|
+
key = item[:key]
|
137
|
+
value = item[:value]
|
138
|
+
dict[key] = value
|
139
|
+
end
|
164
140
|
|
165
|
-
|
141
|
+
dict
|
166
142
|
end
|
143
|
+
|
167
144
|
end
|
@@ -20,7 +20,12 @@ class TestIdeoneRubyApi < Test::Unit::TestCase
|
|
20
20
|
instance = Ideone.new(USER, PASS)
|
21
21
|
|
22
22
|
result = instance.test
|
23
|
-
|
23
|
+
|
24
|
+
def compare_intersecting_keys(a, b)
|
25
|
+
(a.keys & b.keys).all? {|k| a[k] == b[k]}
|
26
|
+
end
|
27
|
+
|
28
|
+
assert compare_intersecting_keys(result,{"error"=>"OK", "moreHelp"=>"ideone.com", "pi"=>"3.14", "answerToLifeAndEverything"=>"42", "oOok"=>true}) == true
|
24
29
|
assert_not_nil result
|
25
30
|
end
|
26
31
|
|
@@ -31,7 +36,7 @@ class TestIdeoneRubyApi < Test::Unit::TestCase
|
|
31
36
|
|
32
37
|
result = instance.languages
|
33
38
|
|
34
|
-
|
39
|
+
assert result.count > 10
|
35
40
|
assert_not_nil result
|
36
41
|
end
|
37
42
|
|
@@ -45,7 +50,7 @@ puts "This is a test submission created from ideone-ruby-api. https://github.com
|
|
45
50
|
eos
|
46
51
|
result = instance.create_submission(code, 17)
|
47
52
|
|
48
|
-
|
53
|
+
assert result.is_a?(String)
|
49
54
|
assert_not_nil result
|
50
55
|
end
|
51
56
|
|
@@ -54,9 +59,11 @@ puts "This is a test submission created from ideone-ruby-api. https://github.com
|
|
54
59
|
|
55
60
|
instance = Ideone.new(USER, PASS)
|
56
61
|
|
57
|
-
result = instance.submission_status("
|
58
|
-
|
62
|
+
result = instance.submission_status("nDRJO")
|
63
|
+
|
59
64
|
assert_not_nil result
|
65
|
+
assert_not_nil result[:status]
|
66
|
+
assert_not_nil result[:result]
|
60
67
|
end
|
61
68
|
|
62
69
|
def test_submission_details
|
@@ -64,8 +71,9 @@ puts "This is a test submission created from ideone-ruby-api. https://github.com
|
|
64
71
|
|
65
72
|
instance = Ideone.new(USER, PASS)
|
66
73
|
|
67
|
-
result = instance.submission_details("
|
68
|
-
|
74
|
+
result = instance.submission_details("nDRJO")
|
75
|
+
|
76
|
+
assert result.count == 16
|
69
77
|
assert_not_nil result
|
70
78
|
end
|
71
79
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ideone-ruby-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-08-01 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: savon
|
17
|
-
requirement: &
|
17
|
+
requirement: &16794180 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,21 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: shoulda
|
28
|
-
requirement: &11567980 !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
|
-
requirements:
|
31
|
-
- - ! '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: *11567980
|
25
|
+
version_requirements: *16794180
|
37
26
|
- !ruby/object:Gem::Dependency
|
38
27
|
name: bundler
|
39
|
-
requirement: &
|
28
|
+
requirement: &16792980 !ruby/object:Gem::Requirement
|
40
29
|
none: false
|
41
30
|
requirements:
|
42
31
|
- - ~>
|
@@ -44,10 +33,10 @@ dependencies:
|
|
44
33
|
version: 1.0.0
|
45
34
|
type: :development
|
46
35
|
prerelease: false
|
47
|
-
version_requirements: *
|
36
|
+
version_requirements: *16792980
|
48
37
|
- !ruby/object:Gem::Dependency
|
49
38
|
name: jeweler
|
50
|
-
requirement: &
|
39
|
+
requirement: &16791600 !ruby/object:Gem::Requirement
|
51
40
|
none: false
|
52
41
|
requirements:
|
53
42
|
- - ~>
|
@@ -55,10 +44,10 @@ dependencies:
|
|
55
44
|
version: 1.6.4
|
56
45
|
type: :development
|
57
46
|
prerelease: false
|
58
|
-
version_requirements: *
|
47
|
+
version_requirements: *16791600
|
59
48
|
- !ruby/object:Gem::Dependency
|
60
49
|
name: rcov
|
61
|
-
requirement: &
|
50
|
+
requirement: &16790440 !ruby/object:Gem::Requirement
|
62
51
|
none: false
|
63
52
|
requirements:
|
64
53
|
- - ! '>='
|
@@ -66,10 +55,10 @@ dependencies:
|
|
66
55
|
version: '0'
|
67
56
|
type: :development
|
68
57
|
prerelease: false
|
69
|
-
version_requirements: *
|
58
|
+
version_requirements: *16790440
|
70
59
|
- !ruby/object:Gem::Dependency
|
71
60
|
name: test-unit
|
72
|
-
requirement: &
|
61
|
+
requirement: &16789640 !ruby/object:Gem::Requirement
|
73
62
|
none: false
|
74
63
|
requirements:
|
75
64
|
- - ~>
|
@@ -77,18 +66,7 @@ dependencies:
|
|
77
66
|
version: '2.3'
|
78
67
|
type: :development
|
79
68
|
prerelease: false
|
80
|
-
version_requirements: *
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: rspec
|
83
|
-
requirement: &11562600 !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
|
-
requirements:
|
86
|
-
- - ! '>='
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
89
|
-
type: :development
|
90
|
-
prerelease: false
|
91
|
-
version_requirements: *11562600
|
69
|
+
version_requirements: *16789640
|
92
70
|
description: ! 'A better Ruby binding for the Ideone API '
|
93
71
|
email: knny.myer@gmail.com
|
94
72
|
executables: []
|
@@ -123,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
101
|
version: '0'
|
124
102
|
segments:
|
125
103
|
- 0
|
126
|
-
hash:
|
104
|
+
hash: 1053003594121317126
|
127
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
106
|
none: false
|
129
107
|
requirements:
|