Sha256: 8e3b364700eb88187363cd03b3c9d1a7277a7f47964785228ed238fd1edc4392
Contents?: true
Size: 1.55 KB
Versions: 5
Compression:
Stored size: 1.55 KB
Contents
module NBS class Metric extend NBS::MemcachedMemoize attr_accessor :artist_id,:service_type,:metric,:sdate,:edate, :xml def initialize(artist_id,service_type,metric,sdate,edate) self.artist_id = artist_id self.service_type = service_type self.metric = metric self.sdate = Date.parse(sdate.to_s) self.edate = Date.parse(edate.to_s) end def fetch(myopts_test={}) options = {"service"=>self.service_type,"metric"=>self.metric,"start"=>self.sdate.to_s,"end"=>self.edate.to_s,"artistID"=>self.artist_id,"apiKey"=>$nbs_api_key,"format"=>"xml"} puts "#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{options.to_url_params}" statsxml = Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{options.to_url_params}")).to_s end def data_points begin points = to_hash["Profiles"][0]["Profile"][0]["DataPoint"] dps = [] points.each do |dp| dps << DataPoint.new(dp["date"],dp["value"]) end return dps rescue return [] end end # delivers the datapoints as a Date keyed hash. #def date_points_hash #end #def xml_data_points #to_hash["Profiles"][0]["Profile"][0]["DataPoint"].to_xml #end def to_xml self.xml ||= fetch({"service"=>self.service_type,"metric"=>self.metric,"start"=>self.sdate.to_s,"end"=>self.edate.to_s,"artistID"=>self.artist_id,"apiKey"=>$nbs_api_key,"format"=>"xml"}) end def to_hash Hash.from_xml(to_xml) end remember :fetch end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
next-big-sound-0.4.4 | lib/metric.rb |
next-big-sound-0.4.3 | lib/metric.rb |
next-big-sound-0.4.2 | lib/metric.rb |
next-big-sound-0.4.1 | lib/metric.rb |
next-big-sound-0.4.0 | lib/metric.rb |