Class: NBS::Artist
- Inherits:
-
Object
- Object
- NBS::Artist
- Extended by:
- MemcachedMemoize
- Defined in:
- lib/next-big-sound/artist.rb
Constant Summary collapse
- PROFILES =
%w(all myspace lastfm ilike facebook twitter youtube reverbnation ourstage soundcloud purevolume bebo virb amiestreet jamlegend vimeo)
Instance Attribute Summary collapse
-
#artist_id ⇒ Object
Returns the value of attribute artist_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#post_params ⇒ Object
Returns the value of attribute post_params.
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
- #fetch_profiles(artist, sdate, edate) ⇒ Object
- #genres ⇒ Object
-
#initialize(artist_id, name = "", options = {}) ⇒ Artist
constructor
A new instance of Artist.
- #long_function ⇒ Object
-
#profiles ⇒ Object
return a hash of urls keyed by the service.
- #to_hash ⇒ Object
- #to_xml ⇒ Object
- #youtube_videos ⇒ Object
Methods included from MemcachedMemoize
Constructor Details
#initialize(artist_id, name = "", options = {}) ⇒ Artist
Returns a new instance of Artist.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/next-big-sound/artist.rb', line 8 def initialize(artist_id, name="",={}) self.artist_id=artist_id self.name = name self. = {"artistID"=>self.artist_id,"format"=>"xml"}.merge() self.post_params={} puts .inspect if .has_key?("start_date") && .has_key?("end_date") self.post_params["data[start]"] = Time.parse(["start_date"]) self.post_params["date[end]"] = Time.parse(["end_date"]) end end |
Instance Attribute Details
#artist_id ⇒ Object
Returns the value of attribute artist_id.
4 5 6 |
# File 'lib/next-big-sound/artist.rb', line 4 def artist_id @artist_id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/next-big-sound/artist.rb', line 4 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/next-big-sound/artist.rb', line 4 def @options end |
#post_params ⇒ Object
Returns the value of attribute post_params.
4 5 6 |
# File 'lib/next-big-sound/artist.rb', line 4 def post_params @post_params end |
#xml ⇒ Object
Returns the value of attribute xml.
4 5 6 |
# File 'lib/next-big-sound/artist.rb', line 4 def xml @xml end |
Instance Method Details
#fetch_profiles(artist, sdate, edate) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/next-big-sound/artist.rb', line 20 def fetch_profiles(artist,sdate,edate) if self.post_params.empty? puts "not doing expected action" puts self.post_params self.xml=Net::HTTP.get(URI.parse("#{$nbs_api_key}metrics/artist/#{self.artist_id}.xml")).to_s else puts "doing expected action" resp = Net::HTTP.post_form(URI.parse("#{$nbs_api_key}metrics/artist/#{self.artist_id}.xml"),self.post_params) #puts resp.body self.xml = resp.body end end |
#genres ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/next-big-sound/artist.rb', line 94 def genres @genre_fetch ||= Net::HTTP.get(URI.parse("#{$nbs_api_key}genres/artist/#{self.artist_id}.xml")).to_s h = Hash.from_xml(@genre_fetch) arr =[] begin h["data"][0]["genres"][0]["genre"].each do |g| arr << g["name"].to_s end rescue end return arr end |
#long_function ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/next-big-sound/artist.rb', line 41 def long_function profs={} begin startd = NBS::Base.t_to_d(self.to_hash["data"][0]["criteria"][0]["start"][0]["content"]) endd = NBS::Base.t_to_d(self.to_hash["data"][0]["criteria"][0]["end"][0]["content"]) #puts startd.inspect #puts endd.inspect #puts startd.inspect #endd = self.to_hash["data"][0]["profiles"][0]["profile"].each do |item| profile = NBS::ArtistProfile.new(self.artist_id, item["service"] ,item["url"]) metric_hash = {} if defined?(item["metrics"][0]["metric"]) && item["metrics"][0]["metric"]!=nil && !item["metrics"][0]["metric"].empty? item["metrics"][0]["metric"].each do |mdata| #puts mdata["name"] metric = NBS::Metric.new(self.artist_id,item["service"],mdata["name"],startd,endd) dps = [] if defined?(mdata["value"]) && mdata["value"]!=nil mdata["value"].each do |dp| #puts "got here" dps << NBS::DataPoint.new(NBS::Base.t_to_d(dp["timestamp"]),dp["content"]) end end metric.load_datapoints(dps) metric_hash[mdata["name"]]=metric end end profile.set_metrics(metric_hash) profs[item["service"][0]["content"].to_s]=profile end rescue end return profs end |
#profiles ⇒ Object
return a hash of urls keyed by the service.
34 35 36 37 38 39 40 |
# File 'lib/next-big-sound/artist.rb', line 34 def profiles #### #puts self.to_xml #puts self.to_xml @profs ||= long_function return @profs end |
#to_hash ⇒ Object
78 79 80 |
# File 'lib/next-big-sound/artist.rb', line 78 def to_hash Hash.from_xml(self.to_xml) end |
#to_xml ⇒ Object
75 76 77 |
# File 'lib/next-big-sound/artist.rb', line 75 def to_xml self.xml ||= fetch_profiles(self.artist_id,self.["start_date"], self.["end_date"]) end |
#youtube_videos ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/next-big-sound/artist.rb', line 81 def youtube_videos @youtube_fetch ||= Net::HTTP.get(URI.parse("#{$nbs_api_key}youtube/artist/#{self.artist_id}.xml")).to_s h = Hash.from_xml(@youtube_fetch) arr =[] begin h["data"][0]["youtubes"][0]["youtube"].each do |g| arr << g["url"].to_s end rescue end return arr end |