ideone-ruby-api 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'savon'
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ gem "rcov", ">= 0"
14
+ gem "rspec"
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kenny Meyer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = ideone-ruby-api
2
+
3
+ Ideone is a pastebin, as well as an online compiler and debugger. This project is a Ruby binding to the Ideone API.
4
+
5
+ == Usage
6
+
7
+ Please, see tests.
8
+
9
+ == Contributing to ideone-ruby-api
10
+
11
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
12
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
13
+ * Fork the project
14
+ * Start a feature/bugfix branch
15
+ * Commit and push until you are happy with your contribution
16
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
17
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2011 Kenny Meyer. See LICENSE.txt for
22
+ further details.
23
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ideone-ruby-api"
18
+ gem.homepage = "http://github.com/kennym/ideone-ruby-api"
19
+ gem.license = "MIT"
20
+ gem.summary = "Ruby binding for Ideone API"
21
+ gem.email = "knny.myer@gmail.com"
22
+ gem.authors = ["Kenny Meyer"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ test.rcov_opts << '--exclude "gems/*"'
40
+ end
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "ideone-ruby-api #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ideone-ruby-api}
8
+ s.version = "1.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kenny Meyer"]
12
+ s.date = %q{2011-07-11}
13
+ s.email = %q{knny.myer@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "LICENSE.txt",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "ideone-ruby-api.gemspec",
26
+ "lib/ideone-ruby-api.rb",
27
+ "test/helper.rb",
28
+ "test/test_ideone-ruby-api.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/kennym/ideone-ruby-api}
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.6.2}
34
+ s.summary = %q{Ruby binding for Ideone API}
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<savon>, [">= 0"])
41
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
42
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
43
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
44
+ s.add_development_dependency(%q<rcov>, [">= 0"])
45
+ s.add_development_dependency(%q<rspec>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<savon>, [">= 0"])
48
+ s.add_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
51
+ s.add_dependency(%q<rcov>, [">= 0"])
52
+ s.add_dependency(%q<rspec>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<savon>, [">= 0"])
56
+ s.add_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, [">= 0"])
61
+ end
62
+ end
63
+
@@ -0,0 +1,156 @@
1
+ # This program is a Ruby API to the Ideone web service. For more
2
+ # information about the Ideone API consult
3
+ # http://ideone.com/files/ideone-api.pdf
4
+ #
5
+ # Author:: Kenny Meyer (knny.myer@gmail.com)
6
+ # Copyright:: Copyright (c) 2011
7
+ # License:: Distributes under the same terms as Ruby
8
+
9
+ require 'savon' # SOAP Client
10
+
11
+ Savon.configure do |config|
12
+ config.log = false # disable logging
13
+ end
14
+
15
+
16
+ class Ideone
17
+
18
+ # Keyword arguments
19
+ # -----------------
20
+ #
21
+ # * username: a valid Ideone username
22
+ # * password: a valid Ideone password
23
+ def initialize(username=nil, password=nil)
24
+ @username = username
25
+ @password = password
26
+
27
+ @client = Savon::Client.new do
28
+ wsdl.document = "http://ideone.com/api/1/service.wsdl"
29
+ end
30
+
31
+ @request_body = {
32
+ :user => @username,
33
+ :pass => @password,
34
+ }
35
+ @languages_cache = nil
36
+ end
37
+
38
+ # Create a submission and upload it to Ideone.
39
+ #
40
+ # Keyword Arguments
41
+ # -----------------
42
+ #
43
+ # * source_code: a string of the program's source code
44
+ # * lang_id: the ID of the programming language.
45
+ # * std_input: the string to pass to the program on stdin
46
+ # * run: a boolean flag to signifying if Ideone should compile and
47
+ # run the program
48
+ # * private: a boolean flag to toggle visibility of code to others
49
+ #
50
+ # Returns
51
+ # -------
52
+ #
53
+ # A hash with the keys error and link. The link is the
54
+ # unique id of the program. The URL of the submission is
55
+ # http://ideone.com/LINK.
56
+ def create_submission(source_code, lang_id, std_input="", run=true,
57
+ private=false)
58
+ request_body = @request_body
59
+ request_body[:sourceCode] = source_code
60
+ request_body[:language] = lang_id
61
+ request_body[:input] = std_input
62
+ request_body[:run] = run
63
+ request_body[:private] = private
64
+ response = @client.request :createSubmission, :body => @request_body
65
+
66
+ return response.to_hash[:create_submission_response][:return][:item]
67
+ end
68
+
69
+ # Given the unique link of a submission, returns its current status.
70
+ #
71
+ # Keyword Arguments
72
+ # -----------------
73
+ #
74
+ # * link: the unique id string of a submission
75
+ #
76
+ # Returns
77
+ # -------
78
+ #
79
+ # A hash of the error, the result code and the status code.
80
+ #
81
+ # Notes
82
+ # -----
83
+ #
84
+ # Status specifies the stage of execution.
85
+ #
86
+ # * status < 0 means the program awaits compilation
87
+ # * status == 0 means the program is done
88
+ # * status == 1 means the program is being compiled
89
+ # * status == 3 means the program is running
90
+ #
91
+ # Result specifies how the program finished.
92
+ #
93
+ # * result == 0 means not running, the program was submitted
94
+ # with run=False
95
+ # * result == 11 means compilation error
96
+ # * result == 12 means runtime error
97
+ # * result == 13 means timelimit exceeded
98
+ # * result == 15 means success
99
+ # * result == 17 means memory limit exceeded
100
+ # * result == 19 means illegal system call
101
+ # * result == 20 means Ideone internal error, submit a bug report
102
+ def submission_status(link)
103
+ request_body = @request_body
104
+ request_body[:link] = link
105
+ response = @client.request :getSubmissionStatus, :body => request_body
106
+
107
+ return response.to_hash[:get_submission_status][:return][:item]
108
+ end
109
+
110
+ # Return a hash of requested details about a submission with the id
111
+ # of link.
112
+ #
113
+ # Keyword Arguments
114
+ # -----------------
115
+ #
116
+ # * link: the unique string ID of a submission
117
+ # * with_source: should we request the source code
118
+ # * with_input: request the program input
119
+ # * with_output: request the program output
120
+ # * with_stderr: request the error output
121
+ # * with_cmpinfo: request compilation flags
122
+ def submission_details(link,
123
+ with_source=true,
124
+ with_input=true,
125
+ with_output=true,
126
+ with_stderr=true,
127
+ with_cmpinfo=true)
128
+ request_body = @request_body
129
+ request_body[:withSource] = with_source
130
+ request_body[:withInput] = with_input
131
+ request_body[:withOutput] = with_output
132
+ request_body[:withStderr] = with_stderr
133
+ request_body[:withCmpinfo] = with_cmpinfo
134
+ response = @client.request :getSubmissionDetails, :body => request_body
135
+
136
+ return response.to_hash[:get_submission_details][:return][:item]
137
+ end
138
+
139
+ # Get a list of supported languages and cache it.
140
+ def languages
141
+ if !@languages_cache
142
+ response = @client.request :getLanguages, :body => @request_body
143
+ languages = response.to_hash[:get_languages_response][:return][:item]
144
+ @languages_cache = languages
145
+ return languages
146
+ end
147
+ return @languages_cache
148
+ end
149
+
150
+ # A test function that always returns the same thing.
151
+ def test
152
+ response = @client.request :testFunction, :body => @request_body
153
+
154
+ return response.to_hash[:test_function_response][:return][:item]
155
+ end
156
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'ideone-ruby-api'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+
3
+ USER = 'humpydumpy'
4
+ PASS = 'testing'
5
+
6
+ class TestIdeoneRubyApi < Test::Unit::TestCase
7
+ def test_initialize
8
+ instance = Ideone.new
9
+ assert_not_nil(instance)
10
+
11
+ instance = Ideone.new(USER, PASS)
12
+ assert_not_nil(instance)
13
+ end
14
+
15
+ def test_ideone_test
16
+ instance = Ideone.new(USER, PASS)
17
+
18
+ result = instance.test
19
+ assert_not_nil result
20
+ end
21
+
22
+ def test_languages
23
+ instance = Ideone.new(USER, PASS)
24
+
25
+ result = instance.languages
26
+
27
+ puts result
28
+ assert_not_nil result
29
+ end
30
+
31
+ def test_create_submission
32
+ instance = Ideone.new(USER, PASS)
33
+
34
+ code = "puts 'hello, world'"
35
+ result = instance.create_submission(code, 17)
36
+
37
+ puts result
38
+ assert_not_nil result
39
+ end
40
+
41
+ def test_submission_status
42
+ instance = Ideone.new(USER, PASS)
43
+
44
+ result = instance.submission_status("ZUIWF")
45
+ puts result
46
+ assert_not_nil result
47
+ end
48
+
49
+ def test_submission_details
50
+ instance = Ideone.new(USER, PASS)
51
+
52
+ result = instance.submission_details("ZUIWF")
53
+ puts result
54
+ assert_not_nil result
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ideone-ruby-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kenny Meyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-11 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: savon
17
+ requirement: &12370800 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *12370800
26
+ - !ruby/object:Gem::Dependency
27
+ name: shoulda
28
+ requirement: &12369940 !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: *12369940
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &12369080 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *12369080
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &12368000 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.4
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *12368000
59
+ - !ruby/object:Gem::Dependency
60
+ name: rcov
61
+ requirement: &12366640 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *12366640
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: &12363520 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *12363520
81
+ description:
82
+ email: knny.myer@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - LICENSE.txt
87
+ - README.rdoc
88
+ files:
89
+ - .document
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.rdoc
93
+ - Rakefile
94
+ - VERSION
95
+ - ideone-ruby-api.gemspec
96
+ - lib/ideone-ruby-api.rb
97
+ - test/helper.rb
98
+ - test/test_ideone-ruby-api.rb
99
+ has_rdoc: true
100
+ homepage: http://github.com/kennym/ideone-ruby-api
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
114
+ - 0
115
+ hash: -560738434367915780
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.6.2
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Ruby binding for Ideone API
128
+ test_files: []