Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit. Functional example.

  • Loading branch information...
commit 6bed26890f6e5b2c42f20bdbd1e90126ddde95ef 0 parents
authored August 01, 2010
21  LICENCE
... ...
@@ -0,0 +1,21 @@
  1
+The MIT Licence
  2
+
  3
+Copyright (c) 2008-2009 Pistos
  4
+
  5
+Permission is hereby granted, free of charge, to any person obtaining a copy
  6
+of this software and associated documentation files (the "Software"), to deal
  7
+in the Software without restriction, including without limitation the rights
  8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9
+copies of the Software, and to permit persons to whom the Software is
  10
+furnished to do so, subject to the following conditions:
  11
+
  12
+The above copyright notice and this permission notice shall be included in
  13
+all copies or substantial portions of the Software.
  14
+
  15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21
+THE SOFTWARE.
1  LICENSE
25  README.md
Source Rendered
... ...
@@ -0,0 +1,25 @@
  1
+# ideone.com gem
  2
+
  3
+A Ruby interface to the ideone.com API.
  4
+http://github.com/Pistos/ideone-gem
  5
+
  6
+Base code taken from http://github.com/staii/tgoa .  See References, below.
  7
+
  8
+## Examples
  9
+
  10
+See examples/ dir of repository or gem.
  11
+
  12
+## Contact
  13
+
  14
+Pistos in #mathetes on irc.freenode.net
  15
+
  16
+## Licence
  17
+
  18
+MIT.  See LICENCE file.
  19
+
  20
+## References
  21
+
  22
+http://ideone.com/api
  23
+http://ideone.com/api/1/service.wsdl
  24
+http://ideone.com/files/ideone-api.pdf
  25
+http://github.com/staii/tgoa/blob/7490b8564977f9a0b0dde4840e1c00f6a47cdcba/safe_code.rb
9  examples/hello-world.rb
... ...
@@ -0,0 +1,9 @@
  1
+require 'ideone'
  2
+
  3
+code = %{
  4
+  puts "Hello, World!"
  5
+}
  6
+
  7
+paste_id = Ideone.submit( :ruby, code )
  8
+p Ideone.run( paste_id, nil )
  9
+
63  lib/ideone.rb
... ...
@@ -0,0 +1,63 @@
  1
+require 'json'
  2
+require 'net/http'
  3
+require 'cgi'
  4
+
  5
+
  6
+module Ideone
  7
+
  8
+  class IdeoneError < StandardError; end
  9
+
  10
+  LANGUAGES = {
  11
+    :ruby => 17, :python => 4, :c => 11
  12
+  }
  13
+
  14
+  def self.submit( lang, code )
  15
+    if ! LANGUAGES.keys.include?( lang )
  16
+      raise "Invalid language: #{lang}"
  17
+    end
  18
+
  19
+    Net::HTTP.post_form(
  20
+      URI.parse("http://ideone.com/ideone/Index/submit/"),
  21
+      {
  22
+        'lang' => LANGUAGES[lang],
  23
+        'run' => 0,
  24
+        'file' => code
  25
+      }
  26
+    ).header['location'][1..-1]
  27
+  end
  28
+
  29
+  def self.run( id, input )
  30
+    res = JSON.load(
  31
+      Net::HTTP.post_form(
  32
+        URI.parse( "http://ideone.com/submit/parent/#{id}" ),
  33
+        {'input' => input}
  34
+      ).body
  35
+    )
  36
+    if res['status'] != 'ok'
  37
+      raise IdeoneError, "Posting of input failed."
  38
+    end
  39
+
  40
+    loc = res['link']
  41
+    i = 0
  42
+
  43
+    begin
  44
+      sleep 1 if i > 0
  45
+      res = JSON.load(Net::HTTP.post_form(URI.parse("http://ideone.com/ideone/Index/view/id/#{loc}/ajax/1"),{}).body)
  46
+      i += 1
  47
+    end while res['result'] != "15" and i < 4
  48
+
  49
+    if i == 4
  50
+      raise IdeoneError, "Timed out while waiting for code result."
  51
+    end
  52
+
  53
+    err = res['inouterr'].match(/<label>stderr:<\/label>.*?<pre.*?>(.*?)<\/pre>/m)
  54
+    if err
  55
+      err[1]
  56
+    else
  57
+      out = res['inouterr'].match(/<label>output:<\/label>.*?<pre.*?>(.*?)<\/pre>/m)
  58
+      raise IdeoneError, "Error parsing output." unless out
  59
+      out[1]
  60
+    end
  61
+  end
  62
+
  63
+end

0 notes on commit 6bed268

Please sign in to comment.
Something went wrong with that request. Please try again.