Class: SlashPort::Fetcher
- Inherits:
-
Object
- Object
- SlashPort::Fetcher
- Defined in:
- lib/slashport.rb
Overview
class SlashPort::Check
Instance Method Summary collapse
-
#add_filter(key, value) ⇒ Object
def initialize.
- #fetch ⇒ Object
-
#initialize(host, port = 4000) ⇒ Fetcher
constructor
class SlashPort::Fetcher.
-
#query ⇒ Object
def fetch.
Constructor Details
#initialize(host, port = 4000) ⇒ Fetcher
class SlashPort::Fetcher
64 65 66 67 68 69 70 71 |
# File 'lib/slashport.rb', line 64 def initialize(host, port=4000) @host = host @port = port @scheme = "http" @filters = [] @checks = [] end |
Instance Method Details
#add_filter(key, value) ⇒ Object
def initialize
73 74 75 |
# File 'lib/slashport.rb', line 73 def add_filter(key, value) @filters << [key, value] end |
#fetch ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/slashport.rb', line 77 def fetch url = "#{@scheme}://#{@host}:#{@port}/var.json?#{query}" #puts "URL: #{url}" response = Net::HTTP.get_response(URI.parse(url)) if response.code.to_i != 200 raise "Non-OK http response: #{response.code}" end return JSON::parse(response.body) end |
#query ⇒ Object
def fetch
88 89 90 |
# File 'lib/slashport.rb', line 88 def query return @filters.collect { |a,b| "#{a}=#{b}" }.join("&") end |