class Graphite::Base

Public Class Methods

authenticate(user = @@user,password = @@password) click to toggle source

If the operation needs authentication you have to call this first

# File lib/graphite/base.rb, line 19
def self.authenticate(user = @@user,password = @@password)
  connection = self.connection
  url = @@path + "/account/login"
  url.gsub!("//","/")
  response = connection.post(url,"nextPage=/&password=#{password}&username=#{user}")
  @@init_header =  {"Cookie" => response.get_fields('Set-Cookie').first}
end
connection() click to toggle source

connection instance (shared with every instance of the class)

# File lib/graphite/base.rb, line 9
def self.connection      
  @init_header ||= {}
  @@connection ||= begin
                     endpoint_uri = URI.parse(@@endpoint)
                     @@path = endpoint_uri.path
                     Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
                   end
end
get(path,args) click to toggle source

Get

# File lib/graphite/base.rb, line 34
def self.get(path,args)      
  mpath = (@@path + path).gsub("//","/")
  self.connection.get(mpath + "?" + args.map { |i,j| i.to_s + "=" + j }.join("&"),@@init_header)
end
set_connection(endpoint,user = "",password = "") click to toggle source
# File lib/graphite/base.rb, line 27
def self.set_connection(endpoint,user = "",password = "")
  @@endpoint = endpoint
  @@user ||= user
  @@password ||= password
end