Class: Pachube

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/pachuber.rb

Defined Under Namespace

Classes: PachubeError

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Pachube

Returns a new instance of Pachube.



16
17
18
# File 'lib/pachuber.rb', line 16

def initialize(key)
  @key = key
end

Instance Method Details

#get_eeml(feed_url) ⇒ Object

Fetches the Pachube feed Returns the latest datastream entry as EEML::Environment object



29
30
31
32
# File 'lib/pachuber.rb', line 29

def get_eeml(feed_url)
  xml = self.get_xml(feed_url)
  eeml = EEML::Environment.from_eeml(xml)
end

#get_xml(feed_url) ⇒ Object

Fetches the Pachube feed Returns the latest datastream entry as XML



22
23
24
25
# File 'lib/pachuber.rb', line 22

def get_xml(feed_url)
  options = { :format => "xml", :headers => {"X-PachubeApiKey" => @key} }
  self.class.get(feed_url, options)
end

#update(feed_url, eeml) ⇒ Object

Posts an update to a specified Pachube feed



35
36
37
38
39
40
# File 'lib/pachuber.rb', line 35

def update(feed_url, eeml)
  options = { :headers => {"X-PachubeApiKey" => @key},
              :body => eeml 
            }
  self.class.put(feed_url, options)
end