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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 001863875eed57b773be63c9ae772bf42d80c791
4
- data.tar.gz: 530757e8307000be2aa9b2616efe98c26b397705
3
+ metadata.gz: a80d2e7351262112663d0229b3829a8711c7a1c9
4
+ data.tar.gz: f5c79917c54b81fff26c52c21a2aa00d114d4f88
5
5
  SHA512:
6
- metadata.gz: aa32c8b38d83f5e3c07b3d45caeae5523e29a83b55896aff9e0e9a320d7809d1c97c6f0a11763a59e72edad81bb91ccb50370aa9f457b1baedd01129b3bb1d66
7
- data.tar.gz: 0e48ce9bd2a067f7873a7e6d5be8b5bef087a99f0c387d8175cedbe3455fea721f3b6ce35dfb49c413f987637a57ccbdc16198fd90625fa331c0c2f04dff3737
6
+ metadata.gz: 8562a4d8112ef8b9b57fcce6d14c79e852258b85bf719d10291cbe7e8d6a60a4eabe9ab9442882c9bf5f56cd79936c94a22c5a167a579994caae02305aa856ad
7
+ data.tar.gz: 071fc2046c3f074599d2ee6eb63eaf32f35b57941aafeccaaf09fe38aa5b01bf9957c5b77cbd26310e65a95def1f0fdffaca29ecd99cdef31919a9649f3344dc
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.2
5
4
  - 1.9.3
5
+ - 2.0.0
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
 
@@ -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.0.0"
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-02-20"
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.require_paths = ["lib"]
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 (knny.myer@gmail.com)
6
- # Copyright:: Copyright (c) 2011
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
- class Ideone
12
-
13
- def initialize(username=nil, password=nil)
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
- def create_submission(source_code, lang_id, std_input="", run=true,
29
- is_private=false)
30
- request_body = @request_body
31
- request_body[:sourceCode] = source_code
32
- request_body[:language] = lang_id
33
- request_body[:input] = std_input
34
- request_body[:run] = run
35
- request_body[:private] = is_private
36
- response = @client.call(:create_submission, :message => @request_body)
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
- def submission_status(link)
43
- request_body = @request_body
44
- request_body[:link] = link
45
- response = @client.call(:get_submission_status, :message => request_body)
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
- check_error(response, :get_submission_status_response)
36
+ response = call_request(:create_submission, :message => @request_body)
48
37
 
49
- status = response.to_hash[:get_submission_status_response][:return][:item][1][:value].to_i
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
- return { :status => status, :result => result }
57
- end
41
+ def submission_status(link)
42
+ request_body = @request_body
43
+ request_body[:link] = link
58
44
 
59
- def submission_details(link,
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
- # Get a list of supported languages and cache it.
83
- def languages
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
- check_error(response, :get_languages_response)
50
+ if status < 0
51
+ status = -1
52
+ end
88
53
 
89
- languages = response.to_hash[:get_languages_response][:return][:item][1][:value][:item]
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
- check_error(response, :test_function_response)
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
- items = response.to_hash[:test_function_response][:return][:item]
103
- create_dict(items)
104
- end
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
- private
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
- def check_error(response, function_response)
109
- error = get_error(response.to_hash, function_response)
110
- if error != 'OK'
111
- raise error
94
+ items = response.to_hash[:test_function_response][:return][:item]
95
+
96
+ return create_dict(items)
112
97
  end
113
- end
114
-
115
- def get_error(response, function_response)
116
- begin
117
- return response[function_response][:return][:item][0][:value]
118
- rescue
119
- return response[function_response][:return][:item][:value]
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
- end
122
-
123
- def create_dict(items)
124
- dict = {}
125
-
126
- items.each do |item|
127
- key = item[:key]
128
- value = item[:value]
129
- value = "" if value == {:"@xsi:type"=>"xsd:string"}
130
- dict[key] = value
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
@@ -0,0 +1,3 @@
1
+ module Ideone
2
+ class AuthError < StandardError; end
3
+ end
@@ -1,7 +1,7 @@
1
1
  class Ideone
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -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.0.0
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-02-20 00:00:00.000000000 Z
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.0.6
96
+ rubygems_version: 2.2.2
96
97
  signing_key:
97
98
  specification_version: 4
98
99
  summary: Ruby binding for Ideone API