Skip to content

Commit 94aeb94

Browse files
authorMarco Giosa
committed
switched to open-uri, fixed compatibility issues and tested on ruby >= 1.9.1
1 parent 80a8548 commit 94aeb94

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
# checkhost-ruby
22
checkhost-ruby is a Ruby gem to check-host.net API, supporting all the checks so far published (ping, http, tcp, dns and udp). The official API reference can be found [here](http://check-host.net/about/api).
3-
## Requirements
4-
Ruby2.0.0+, standard library.
3+
4+
## Compatibility
5+
Only standard library is required.
6+
Tested on:
7+
* 1.9.1-p431
8+
* 1.9.3-p194
9+
* 1.9.3-p551
10+
* 2.0.0-p643
11+
* 2.1.5-p273
12+
* 2.2.1-p85
13+
514
## Attributes
615
##### nodes
716

checkhost.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Gem::Specification.new do |s|
22
s.name = 'checkhost'
3-
s.version = '1.0.1'
3+
s.version = '1.0.2'
44
s.date = '2015-12-27'
55
s.summary = "Ruby check-host.net API"
66
s.description = "Gem to check-host.net public API"
7-
s.required_ruby_version = '>= 2.0.0'
7+
s.required_ruby_version = '>= 1.9.1'
88
s.authors = ["Marco Giosa"]
99
s.email = 'marco.giosa@me.com'
1010
s.files = ["lib/checkhost.rb"]

lib/checkhost.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
22
require 'net/http'
3+
require 'open-uri'
34
require 'json'
45

56
class CheckHost
@@ -102,13 +103,9 @@ def query(action, data) # action: newcheck, results; data(hash): newcheck:: type
102103

103104
case action
104105
when :newcheck
105-
uri = URI("http://check-host.net/check-#{data[:type]}?host=#{data[:host]}&max_nodes=#{data[:max_nodes]}")
106-
api = Net::HTTP.new(uri.host)
107-
api.get(uri, headers).body
106+
open("http://check-host.net/check-#{data[:type]}?host=#{data[:host]}&max_nodes=#{data[:max_nodes]}", headers) {|io| io.read}
108107
when :results
109-
uri = URI("http://check-host.net/check-result/#{data[:request_id]}")
110-
api = Net::HTTP.new(uri.host)
111-
api.get(uri, headers).body
108+
open("http://check-host.net/check-result/#{data[:request_id]}", headers) {|io| io.read}
112109
end
113110
end
114111

0 commit comments

Comments
 (0)