ruby-eval-in 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/eval-in/exceptions.rb +7 -0
- data/lib/eval-in/result.rb +15 -28
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e956dc08f0fecadd9ea6a13901fdd8e4f0711e5f
|
4
|
+
data.tar.gz: 1b6baa4ae0f09bd7ae33fd0f09262abe569cbbfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad8bfb07c58b8aadb043eb40ffa7bc80a3b7cae7c7a566bcc6b154331c9e9216dcc8b72c4ebf350e95a2f4aa5c0349605d33c55841d236663c82f008cf42edda
|
7
|
+
data.tar.gz: 665806b04afb9b864e581aa7be38a69207eb2d64eba71068f91f0cc186b0161f0fe95a006469dd53ff7341fa3661ba24866ed592cbea5740e5d7def9fcb582ee
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
ruby-eval-in
|
2
2
|
============
|
3
3
|
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/ruby-eval-in.svg)](http://badge.fury.io/rb/ruby-eval-in)
|
5
|
+
[![Build Status](https://drone.io/github.com/woodruffw/ruby-eval-in/status.png)](https://drone.io/github.com/woodruffw/ruby-eval-in/latest)
|
6
|
+
|
4
7
|
A basic Ruby interface to the [eval.in](https://eval.in) online evaluation
|
5
8
|
service.
|
6
9
|
|
data/lib/eval-in/exceptions.rb
CHANGED
@@ -3,6 +3,13 @@ module EvalIn
|
|
3
3
|
class EvalInError < RuntimeError
|
4
4
|
end
|
5
5
|
|
6
|
+
# Raised when an error occurs during connection.
|
7
|
+
class ConnectionError < EvalInError
|
8
|
+
def initialize(error)
|
9
|
+
super "Connection error: #{error.to_s}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
# Raised when EvalIn.{EvalIn.eval} is given a bad input language.
|
7
14
|
class BadLanguageError < EvalInError
|
8
15
|
def initialize(lang)
|
data/lib/eval-in/result.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
-
require '
|
2
|
+
require 'net/http'
|
3
3
|
require 'uri'
|
4
4
|
|
5
5
|
module EvalIn
|
6
6
|
# A representation of a result produced by an eval.in query.
|
7
7
|
class Result
|
8
8
|
# @private
|
9
|
-
URL = "https://eval.in"
|
9
|
+
URL = URI("https://eval.in")
|
10
10
|
|
11
11
|
# The languages supported by eval.in.
|
12
12
|
# Any of these keys or values will work for the lang parameter in
|
@@ -67,35 +67,22 @@ module EvalIn
|
|
67
67
|
|
68
68
|
@lang = lang
|
69
69
|
@code = code
|
70
|
-
@html = get_page
|
71
|
-
@output = get_output
|
72
|
-
@status = get_status
|
73
|
-
@url = get_url
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def get_page
|
79
|
-
mech = Mechanize.new
|
80
|
-
page = mech.get(URL)
|
81
|
-
form = page.forms.first
|
82
|
-
|
83
|
-
form.field_with(:name => "code").value = @code
|
84
|
-
form.field_with(:name => "lang").value = @lang
|
85
|
-
Nokogiri::HTML(mech.submit(form).body)
|
86
|
-
end
|
87
70
|
|
88
|
-
|
89
|
-
|
90
|
-
|
71
|
+
result = Net::HTTP.post_form(URL,
|
72
|
+
"execute" => "on",
|
73
|
+
"lang" => lang,
|
74
|
+
"code" => code
|
75
|
+
)
|
91
76
|
|
92
|
-
|
93
|
-
|
94
|
-
end
|
77
|
+
if result.is_a? Net::HTTPFound
|
78
|
+
@url = URI(result["location"])
|
95
79
|
|
96
|
-
|
97
|
-
|
98
|
-
|
80
|
+
html = Nokogiri::HTML(Net::HTTP.get(@url))
|
81
|
+
@output = html.css("pre").last.text
|
82
|
+
@status = html.css("p")[1].text
|
83
|
+
else
|
84
|
+
raise ConnectionError.new(result)
|
85
|
+
end
|
99
86
|
end
|
100
87
|
end
|
101
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-eval-in
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
@@ -10,20 +10,6 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: mechanize
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: nokogiri
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|