Class: NBS::Metric
- Inherits:
-
Object
- Object
- NBS::Metric
- Extended by:
- MemcachedMemoize
- Defined in:
- lib/next-big-sound/metric.rb
Instance Attribute Summary collapse
-
#artist_id ⇒ Object
Returns the value of attribute artist_id.
-
#edate ⇒ Object
Returns the value of attribute edate.
-
#metric ⇒ Object
Returns the value of attribute metric.
-
#sdate ⇒ Object
Returns the value of attribute sdate.
-
#service_type ⇒ Object
Returns the value of attribute service_type.
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
- #data_points ⇒ Object
- #fetch(myopts_test = {}) ⇒ Object
-
#initialize(artist_id, service_type, metric, sdate, edate) ⇒ Metric
constructor
A new instance of Metric.
-
#load_datapoints(data_points) ⇒ Object
this will allow me to load the data that I previously fetched.
- #to_hash ⇒ Object
-
#to_xml ⇒ Object
end.
Methods included from MemcachedMemoize
Constructor Details
#initialize(artist_id, service_type, metric, sdate, edate) ⇒ Metric
Returns a new instance of Metric.
9 10 11 12 13 14 15 |
# File 'lib/next-big-sound/metric.rb', line 9 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 |
Instance Attribute Details
#artist_id ⇒ Object
Returns the value of attribute artist_id.
6 7 8 |
# File 'lib/next-big-sound/metric.rb', line 6 def artist_id @artist_id end |
#edate ⇒ Object
Returns the value of attribute edate.
6 7 8 |
# File 'lib/next-big-sound/metric.rb', line 6 def edate @edate end |
#metric ⇒ Object
Returns the value of attribute metric.
6 7 8 |
# File 'lib/next-big-sound/metric.rb', line 6 def metric @metric end |
#sdate ⇒ Object
Returns the value of attribute sdate.
6 7 8 |
# File 'lib/next-big-sound/metric.rb', line 6 def sdate @sdate end |
#service_type ⇒ Object
Returns the value of attribute service_type.
6 7 8 |
# File 'lib/next-big-sound/metric.rb', line 6 def service_type @service_type end |
#xml ⇒ Object
Returns the value of attribute xml.
6 7 8 |
# File 'lib/next-big-sound/metric.rb', line 6 def xml @xml end |
Instance Method Details
#data_points ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/next-big-sound/metric.rb', line 21 def data_points unless @data_points.empty? return @data_points end begin points = to_hash["Profiles"][0]["Profile"][0]["DataPoint"] dps = [] points.each do |dp| dps << NBS::DataPoint.new(dp["date"],dp["value"]) end return dps rescue return [] end end |
#fetch(myopts_test = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/next-big-sound/metric.rb', line 16 def fetch(myopts_test={}) = {"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?#{.to_url_params}" statsxml = Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{.to_url_params}")).to_s end |
#load_datapoints(data_points) ⇒ Object
this will allow me to load the data that I previously fetched.
37 38 39 |
# File 'lib/next-big-sound/metric.rb', line 37 def load_datapoints(data_points) @data_points = data_points end |
#to_hash ⇒ Object
49 50 51 |
# File 'lib/next-big-sound/metric.rb', line 49 def to_hash Hash.from_xml(to_xml) end |
#to_xml ⇒ Object
end
46 47 48 |
# File 'lib/next-big-sound/metric.rb', line 46 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 |