Class: Graphite::Base
- Inherits:
-
Object
- Object
- Graphite::Base
- Defined in:
- lib/graphite/base.rb
Constant Summary collapse
- @@path =
""
Class Method Summary collapse
-
.authenticate(user = @@user, password = @@password) ⇒ Object
If the operation needs authentication you have to call this first.
-
.connection ⇒ Object
connection instance (shared with every instance of the class).
-
.get(path, args) ⇒ Object
Get.
- .set_connection(endpoint, user = "", password = "") ⇒ Object
Class Method Details
.authenticate(user = @@user, password = @@password) ⇒ Object
If the operation needs authentication you have to call this first
20 21 22 23 24 25 |
# File 'lib/graphite/base.rb', line 20 def self.authenticate(user = @@user,password = @@password) url = @@path + "/account/login" url.gsub!("//","/") response = self.connection.post(url,"nextPage=/&password=#{password}&username=#{user}") @@init_header = {"Cookie" => response.get_fields('Set-Cookie').first} end |
.connection ⇒ Object
connection instance (shared with every instance of the class)
9 10 11 12 13 14 15 16 17 |
# File 'lib/graphite/base.rb', line 9 def self.connection @@path = "" @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) ⇒ Object
Get
34 35 36 37 |
# 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 = "") ⇒ Object
27 28 29 30 31 |
# File 'lib/graphite/base.rb', line 27 def self.set_connection(endpoint,user = "",password = "") @@endpoint = endpoint @@user ||= user @@password ||= password end |