ideone-ruby-api 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.rdoc +10 -2
- data/ideone-ruby-api.gemspec +6 -4
- data/lib/ideone.rb +110 -107
- data/lib/ideone/exceptions.rb +3 -0
- data/lib/ideone/version.rb +1 -1
- data/test/test_ideone-ruby-api.rb +15 -15
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a80d2e7351262112663d0229b3829a8711c7a1c9
|
4
|
+
data.tar.gz: f5c79917c54b81fff26c52c21a2aa00d114d4f88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8562a4d8112ef8b9b57fcce6d14c79e852258b85bf719d10291cbe7e8d6a60a4eabe9ab9442882c9bf5f56cd79936c94a22c5a167a579994caae02305aa856ad
|
7
|
+
data.tar.gz: 071fc2046c3f074599d2ee6eb63eaf32f35b57941aafeccaaf09fe38aa5b01bf9957c5b77cbd26310e65a95def1f0fdffaca29ecd99cdef31919a9649f3344dc
|
data/.travis.yml
CHANGED
data/README.rdoc
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
= ideone-ruby-api
|
2
2
|
|
3
3
|
{<img src="https://secure.travis-ci.org/kennym/ideone-ruby-api.png" />}[http://travis-ci.org/kennym/ideone-ruby-api]
|
4
|
+
{<img src="https://badge.fury.io/rb/ideone-ruby-api.png" alt="Gem Version" />}[http://badge.fury.io/rb/ideone-ruby-api]
|
5
|
+
{<img src="https://ga-beacon.appspot.com/UA-48308186-1/ideone-ruby-api/README.rdoc" alt="GA analytics" />}[https://ga-beacon.appspot.com/UA-48308186-1/ideone-ruby-api/README.rdoc]
|
4
6
|
|
5
7
|
Ideone is a pastebin, as well as an online compiler and debugger. This
|
6
8
|
project is a Ruby binding to the Ideone API.
|
7
9
|
|
10
|
+
Requires Ruby =>1.9.2
|
11
|
+
|
8
12
|
== Usage
|
9
13
|
|
10
14
|
require 'ideone'
|
@@ -12,7 +16,11 @@ project is a Ruby binding to the Ideone API.
|
|
12
16
|
# Authenticate with Ideone
|
13
17
|
i = Ideone.new('username', 'password')
|
14
18
|
=> #<Ideone:0x000000021dfd88 ... >
|
15
|
-
|
19
|
+
|
20
|
+
# Enable logging by setting flag to `true`
|
21
|
+
i = Ideone.new('username', 'password', true)
|
22
|
+
=> #<Ideone:0x000000021dfd88 ... >
|
23
|
+
|
16
24
|
# Create submission
|
17
25
|
source_code = "puts 'hello, world'"
|
18
26
|
i.create_submission(source_code,
|
@@ -34,7 +42,7 @@ project is a Ruby binding to the Ideone API.
|
|
34
42
|
"moreHelp"=>"ideone.com",
|
35
43
|
"pi"=>"3.14",
|
36
44
|
"answerToLifeAndEverything"=>"42",
|
37
|
-
"oOok"=>true}
|
45
|
+
"oOok"=>true}
|
38
46
|
|
39
47
|
== Similar projects
|
40
48
|
|
data/ideone-ruby-api.gemspec
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: ideone-ruby-api 2.1.0 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "ideone-ruby-api"
|
8
|
-
s.version = "2.
|
9
|
+
s.version = "2.1.0"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
11
13
|
s.authors = ["Kenny Meyer"]
|
12
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-05-10"
|
13
15
|
s.description = "A better Ruby binding for the Ideone API "
|
14
16
|
s.email = "kenny@kennymeyer.net"
|
15
17
|
s.extra_rdoc_files = [
|
@@ -26,14 +28,14 @@ Gem::Specification.new do |s|
|
|
26
28
|
"VERSION",
|
27
29
|
"ideone-ruby-api.gemspec",
|
28
30
|
"lib/ideone.rb",
|
31
|
+
"lib/ideone/exceptions.rb",
|
29
32
|
"lib/ideone/version.rb",
|
30
33
|
"test/helper.rb",
|
31
34
|
"test/test_ideone-ruby-api.rb"
|
32
35
|
]
|
33
36
|
s.homepage = "http://github.com/kennym/ideone-ruby-api"
|
34
37
|
s.licenses = ["MIT"]
|
35
|
-
s.
|
36
|
-
s.rubygems_version = "2.0.6"
|
38
|
+
s.rubygems_version = "2.2.2"
|
37
39
|
s.summary = "Ruby binding for Ideone API"
|
38
40
|
|
39
41
|
if s.respond_to? :specification_version then
|
data/lib/ideone.rb
CHANGED
@@ -2,135 +2,138 @@
|
|
2
2
|
# information about the Ideone API consult
|
3
3
|
# http://ideone.com/files/ideone-api.pdf
|
4
4
|
#
|
5
|
-
# Author:: Kenny Meyer (
|
6
|
-
# Copyright:: Copyright (c)
|
5
|
+
# Author:: Kenny Meyer (kenny@kennymeyer.net)
|
6
|
+
# Copyright:: Copyright (c) 2014
|
7
7
|
# License:: Distributes under the same terms as Ruby
|
8
8
|
|
9
|
+
require_relative 'ideone/exceptions'
|
9
10
|
require 'savon' # SOAP Client
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@username = username
|
15
|
-
@password = password
|
16
|
-
|
17
|
-
@client = Savon.client(wsdl: "http://ideone.com/api/1/service.wsdl")
|
18
|
-
|
19
|
-
HTTPI.log = false
|
20
|
-
|
21
|
-
@request_body = {
|
22
|
-
:user => @username,
|
23
|
-
:pass => @password,
|
24
|
-
}
|
25
|
-
@languages_cache = nil
|
12
|
+
module Ideone
|
13
|
+
def self.new(username, password, verbose=false)
|
14
|
+
return Ideone::Client.new(username, password, verbose)
|
26
15
|
end
|
27
16
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
check_error(response, :create_submission_response)
|
39
|
-
return response.to_hash[:create_submission_response][:return][:item][1][:value]
|
40
|
-
end
|
17
|
+
class Client
|
18
|
+
def initialize(username=nil, password=nil, verbose=false)
|
19
|
+
@client = Savon.client(wsdl: "http://ideone.com/api/1/service.wsdl", log: verbose)
|
20
|
+
@languages_cache = nil
|
21
|
+
@request_body = {
|
22
|
+
:user => username,
|
23
|
+
:pass => password,
|
24
|
+
}
|
25
|
+
end
|
41
26
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
27
|
+
def create_submission(source_code, lang_id, std_input="", run=true,
|
28
|
+
is_private=false)
|
29
|
+
request_body = @request_body
|
30
|
+
request_body[:sourceCode] = source_code
|
31
|
+
request_body[:language] = lang_id
|
32
|
+
request_body[:input] = std_input
|
33
|
+
request_body[:run] = run
|
34
|
+
request_body[:private] = is_private
|
46
35
|
|
47
|
-
|
36
|
+
response = call_request(:create_submission, :message => @request_body)
|
48
37
|
|
49
|
-
|
50
|
-
result = response.to_hash[:get_submission_status_response][:return][:item][2][:value].to_i
|
51
|
-
|
52
|
-
if status < 0
|
53
|
-
status = -1
|
38
|
+
return response.to_hash[:create_submission_response][:return][:item][1][:value]
|
54
39
|
end
|
55
40
|
|
56
|
-
|
57
|
-
|
41
|
+
def submission_status(link)
|
42
|
+
request_body = @request_body
|
43
|
+
request_body[:link] = link
|
58
44
|
|
59
|
-
|
60
|
-
with_source=true,
|
61
|
-
with_input=true,
|
62
|
-
with_output=true,
|
63
|
-
with_stderr=true,
|
64
|
-
with_cmpinfo=true)
|
65
|
-
request_body = @request_body
|
66
|
-
request_body[:link] = link
|
67
|
-
request_body[:withSource] = with_source
|
68
|
-
request_body[:withInput] = with_input
|
69
|
-
request_body[:withOutput] = with_output
|
70
|
-
request_body[:withStderr] = with_stderr
|
71
|
-
request_body[:withCmpinfo] = with_cmpinfo
|
72
|
-
|
73
|
-
response = @client.call(:get_submission_details, :message => request_body)
|
74
|
-
|
75
|
-
check_error(response, :get_submission_details_response)
|
76
|
-
|
77
|
-
details = response.to_hash[:get_submission_details_response][:return][:item]
|
78
|
-
|
79
|
-
create_dict(details)
|
80
|
-
end
|
45
|
+
response = call_request(:get_submission_status, :message => request_body)
|
81
46
|
|
82
|
-
|
83
|
-
|
84
|
-
unless @languages_cache
|
85
|
-
response = @client.call(:get_languages, :message => @request_body)
|
47
|
+
status = response.to_hash[:get_submission_status_response][:return][:item][1][:value].to_i
|
48
|
+
result = response.to_hash[:get_submission_status_response][:return][:item][2][:value].to_i
|
86
49
|
|
87
|
-
|
50
|
+
if status < 0
|
51
|
+
status = -1
|
52
|
+
end
|
88
53
|
|
89
|
-
|
90
|
-
# Create a sorted hash
|
91
|
-
@languages_cache = Hash[create_dict(languages).sort_by{|k,v| k.to_i}]
|
54
|
+
return { :status => status, :result => result }
|
92
55
|
end
|
93
|
-
return @languages_cache
|
94
|
-
end
|
95
|
-
|
96
|
-
# A test function that always returns the same thing.
|
97
|
-
def test
|
98
|
-
response = @client.call(:test_function, :message => @request_body)
|
99
56
|
|
100
|
-
|
57
|
+
def submission_details(link,
|
58
|
+
with_source=true,
|
59
|
+
with_input=true,
|
60
|
+
with_output=true,
|
61
|
+
with_stderr=true,
|
62
|
+
with_cmpinfo=true)
|
63
|
+
request_body = @request_body
|
64
|
+
request_body[:link] = link
|
65
|
+
request_body[:withSource] = with_source
|
66
|
+
request_body[:withInput] = with_input
|
67
|
+
request_body[:withOutput] = with_output
|
68
|
+
request_body[:withStderr] = with_stderr
|
69
|
+
request_body[:withCmpinfo] = with_cmpinfo
|
70
|
+
|
71
|
+
response = call_request(:get_submission_details, :message => request_body)
|
72
|
+
|
73
|
+
details = response.to_hash[:get_submission_details_response][:return][:item]
|
74
|
+
|
75
|
+
create_dict(details)
|
76
|
+
end
|
101
77
|
|
102
|
-
|
103
|
-
|
104
|
-
|
78
|
+
# Get a list of supported languages and cache it.
|
79
|
+
def languages
|
80
|
+
unless @languages_cache
|
81
|
+
response = call_request(:get_languages, :message => @request_body)
|
82
|
+
|
83
|
+
languages = response.to_hash[:get_languages_response][:return][:item][1][:value][:item]
|
84
|
+
# Create a sorted hash
|
85
|
+
@languages_cache = Hash[create_dict(languages).sort_by{|k,v| k.to_i}]
|
86
|
+
end
|
87
|
+
return @languages_cache
|
88
|
+
end
|
105
89
|
|
106
|
-
|
90
|
+
# A test function that always returns the same thing.
|
91
|
+
def test
|
92
|
+
response = call_request(:test_function, :message => @request_body)
|
107
93
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
raise error
|
94
|
+
items = response.to_hash[:test_function_response][:return][:item]
|
95
|
+
|
96
|
+
return create_dict(items)
|
112
97
|
end
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def check_error(response, function_response)
|
102
|
+
error = get_error(response.to_hash, function_response)
|
103
|
+
if error != 'OK'
|
104
|
+
raise Ideone::AuthError, "Invalid Ideone credentials provided"
|
105
|
+
end
|
120
106
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
107
|
+
|
108
|
+
def call_request(api_endpoint, **params)
|
109
|
+
begin
|
110
|
+
response = @client.call(api_endpoint, params)
|
111
|
+
rescue Exception => e
|
112
|
+
raise e
|
113
|
+
end
|
114
|
+
check_error(response, "#{api_endpoint}_response".to_sym)
|
115
|
+
return response
|
116
|
+
end
|
117
|
+
|
118
|
+
def get_error(response, function_response)
|
119
|
+
begin
|
120
|
+
return response[function_response][:return][:item][0][:value]
|
121
|
+
rescue
|
122
|
+
return response[function_response][:return][:item][:value]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def create_dict(items)
|
127
|
+
dict = {}
|
128
|
+
|
129
|
+
items.each do |item|
|
130
|
+
key = item[:key]
|
131
|
+
value = item[:value]
|
132
|
+
value = "" if value == {:"@xsi:type"=>"xsd:string"}
|
133
|
+
dict[key] = value
|
134
|
+
end
|
135
|
+
|
136
|
+
dict
|
131
137
|
end
|
132
|
-
|
133
|
-
dict
|
134
138
|
end
|
135
|
-
|
136
139
|
end
|
data/lib/ideone/version.rb
CHANGED
@@ -6,18 +6,18 @@ PASS = 'testing' # YOUR IDEONE PASSWORD
|
|
6
6
|
class TestIdeoneRubyApi < Test::Unit::TestCase
|
7
7
|
def test_initialize
|
8
8
|
omit_if(USER.empty? || PASS.empty?, "Specify ideone USER and PASS")
|
9
|
-
|
10
|
-
instance = Ideone.new
|
9
|
+
|
10
|
+
instance = Ideone::Client.new
|
11
11
|
assert_not_nil(instance)
|
12
|
-
|
13
|
-
instance = Ideone.new(USER, PASS)
|
12
|
+
|
13
|
+
instance = Ideone::Client.new(USER, PASS)
|
14
14
|
assert_not_nil(instance)
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_ideone_test
|
18
18
|
omit_if(USER.empty? || PASS.empty?, "Specify ideone USER and PASS")
|
19
|
-
|
20
|
-
instance = Ideone.new(USER, PASS)
|
19
|
+
|
20
|
+
instance = Ideone::Client.new(USER, PASS)
|
21
21
|
|
22
22
|
result = instance.test
|
23
23
|
|
@@ -31,8 +31,8 @@ class TestIdeoneRubyApi < Test::Unit::TestCase
|
|
31
31
|
|
32
32
|
def test_languages
|
33
33
|
omit_if(USER.empty? || PASS.empty?, "Specify ideone USER and PASS")
|
34
|
-
|
35
|
-
instance = Ideone.new(USER, PASS)
|
34
|
+
|
35
|
+
instance = Ideone::Client.new(USER, PASS)
|
36
36
|
|
37
37
|
result = instance.languages
|
38
38
|
|
@@ -42,8 +42,8 @@ class TestIdeoneRubyApi < Test::Unit::TestCase
|
|
42
42
|
|
43
43
|
def test_create_submission
|
44
44
|
omit_if(USER.empty? || PASS.empty?, "Specify ideone USER and PASS")
|
45
|
-
|
46
|
-
instance = Ideone.new(USER, PASS)
|
45
|
+
|
46
|
+
instance = Ideone::Client.new(USER, PASS)
|
47
47
|
|
48
48
|
code = <<-eos
|
49
49
|
puts "This is a test submission created from ideone-ruby-api. https://github.com/kennym/ideone-gem/blob/master/lib/ideone.rb"
|
@@ -56,8 +56,8 @@ puts "This is a test submission created from ideone-ruby-api. https://github.com
|
|
56
56
|
|
57
57
|
def test_submission_status
|
58
58
|
omit_if(USER.empty? || PASS.empty?, "Specify ideone USER and PASS")
|
59
|
-
|
60
|
-
instance = Ideone.new(USER, PASS)
|
59
|
+
|
60
|
+
instance = Ideone::Client.new(USER, PASS)
|
61
61
|
|
62
62
|
result = instance.submission_status("PD2kqM")
|
63
63
|
|
@@ -65,11 +65,11 @@ puts "This is a test submission created from ideone-ruby-api. https://github.com
|
|
65
65
|
assert_not_nil result[:status]
|
66
66
|
assert_not_nil result[:result]
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_submission_details
|
70
70
|
omit_if(USER.empty? || PASS.empty?, "Specify ideone USER and PASS")
|
71
|
-
|
72
|
-
instance = Ideone.new(USER, PASS)
|
71
|
+
|
72
|
+
instance = Ideone::Client.new(USER, PASS)
|
73
73
|
|
74
74
|
result = instance.submission_details("PD2kqM")
|
75
75
|
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ideone-ruby-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenny Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.3.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.3.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jeweler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.0.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.0.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.3'
|
55
55
|
description: 'A better Ruby binding for the Ideone API '
|
@@ -60,8 +60,8 @@ extra_rdoc_files:
|
|
60
60
|
- LICENSE.txt
|
61
61
|
- README.rdoc
|
62
62
|
files:
|
63
|
-
- .document
|
64
|
-
- .travis.yml
|
63
|
+
- ".document"
|
64
|
+
- ".travis.yml"
|
65
65
|
- Gemfile
|
66
66
|
- LICENSE.txt
|
67
67
|
- README.rdoc
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- VERSION
|
70
70
|
- ideone-ruby-api.gemspec
|
71
71
|
- lib/ideone.rb
|
72
|
+
- lib/ideone/exceptions.rb
|
72
73
|
- lib/ideone/version.rb
|
73
74
|
- test/helper.rb
|
74
75
|
- test/test_ideone-ruby-api.rb
|
@@ -82,17 +83,17 @@ require_paths:
|
|
82
83
|
- lib
|
83
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
85
|
requirements:
|
85
|
-
- -
|
86
|
+
- - ">="
|
86
87
|
- !ruby/object:Gem::Version
|
87
88
|
version: '0'
|
88
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
90
|
requirements:
|
90
|
-
- -
|
91
|
+
- - ">="
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
95
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.2.2
|
96
97
|
signing_key:
|
97
98
|
specification_version: 4
|
98
99
|
summary: Ruby binding for Ideone API
|