Class: SlashPort::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/slashport.rb

Overview

class SlashPort::Check

Instance Method Summary collapse

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

#fetchObject



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

#queryObject

def fetch



88
89
90
# File 'lib/slashport.rb', line 88

def query
  return @filters.collect { |a,b| "#{a}=#{b}" }.join("&")
end