next-big-sound 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
@@ -1 +1 @@
1
- base_url: "http://api.nextbigsound.com/v1_1/"
1
+ base_url: ""
@@ -1,28 +1,68 @@
1
1
  module NBS
2
2
  class Artist
3
3
 
4
- attr_accessor :artist_id, :name, :xml, :options
4
+ attr_accessor :artist_id, :name, :xml, :options, :post_params
5
5
 
6
6
  PROFILES = %w(all myspace lastfm ilike facebook twitter youtube reverbnation ourstage soundcloud purevolume bebo virb amiestreet jamlegend vimeo)
7
7
 
8
8
  def initialize(artist_id, name="",options={})
9
9
  self.artist_id=artist_id
10
10
  self.name = name
11
- self.options = {"artistID"=>self.artist_id,"apiKey"=>$nbs_api_key,"format"=>"xml"}.merge(options)
11
+ self.options = {"artistID"=>self.artist_id,"format"=>"xml"}.merge(options)
12
+ self.post_params={}
13
+ puts options.inspect
14
+ if options.has_key?("start_date") && options.has_key?("end_date")
15
+ self.post_params["data[start]"] = Time.parse(options["start_date"])
16
+ self.post_params["date[end]"] = Time.parse(options["end_date"])
17
+ end
12
18
  end
13
19
 
14
20
  def fetch_profiles
15
- self.xml=Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getProfilesForArtist?#{self.options.to_url_params}")).to_s
21
+ if self.post_params.empty?
22
+ puts "not doing expected action"
23
+ puts self.post_params
24
+ self.xml=Net::HTTP.get(URI.parse("#{$nbs_api_key}metrics/artist/#{self.artist_id}.xml")).to_s
25
+ else
26
+ puts "doing expected action"
27
+ resp = Net::HTTP.post_form(URI.parse("#{$nbs_api_key}metrics/artist/#{self.artist_id}.xml"),self.post_params)
28
+ #puts resp.body
29
+ self.xml = resp.body
30
+ end
16
31
  end
17
32
 
18
33
  # return a hash of urls keyed by the service.
19
34
  def profiles
20
35
  ####
21
- puts self.to_xml
36
+ #puts self.to_xml
37
+ #puts self.to_xml
22
38
  profs = {}
23
39
  begin
24
- self.to_hash["Profiles"][0]["Profile"].each do |item|
25
- profs[item["service"].to_s]=NBS::ArtistProfile.new(self.artist_id, item["service"] ,item["url"])
40
+ startd = NBS::Base.t_to_d(self.to_hash["data"][0]["criteria"][0]["start"][0]["content"])
41
+ endd = NBS::Base.t_to_d(self.to_hash["data"][0]["criteria"][0]["end"][0]["content"])
42
+ #puts startd.inspect
43
+ #puts endd.inspect
44
+ #puts startd.inspect
45
+ #endd =
46
+ self.to_hash["data"][0]["profiles"][0]["profile"].each do |item|
47
+ profile = NBS::ArtistProfile.new(self.artist_id, item["service"] ,item["url"])
48
+ metric_hash = {}
49
+ if defined?(item["metrics"][0]["metric"]) && item["metrics"][0]["metric"]!=nil && !item["metrics"][0]["metric"].empty?
50
+ item["metrics"][0]["metric"].each do |mdata|
51
+ #puts mdata["name"]
52
+ metric = NBS::Metric.new(self.artist_id,item["service"],mdata["name"],startd,endd)
53
+ dps = []
54
+ if defined?(mdata["value"]) && mdata["value"]!=nil
55
+ mdata["value"].each do |dp|
56
+ #puts "got here"
57
+ dps << NBS::DataPoint.new(NBS::Base.t_to_d(dp["timestamp"]),dp["content"])
58
+ end
59
+ end
60
+ metric.load_datapoints(dps)
61
+ metric_hash[mdata["name"]]=metric
62
+ end
63
+ end
64
+ profile.set_metrics(metric_hash)
65
+ profs[item["service"][0]["content"].to_s]=profile
26
66
  end
27
67
  rescue
28
68
  end
@@ -35,12 +75,12 @@ module NBS
35
75
  Hash.from_xml(self.to_xml)
36
76
  end
37
77
 
38
- def method_missing(method_name,*args)
39
- splits = method_name.to_s.split("_")
40
- prof = self.profiles[splits[0].upcase]
41
- metrics = prof.metrics(args[0],args[1])
42
- return metrics[splits[1].downcase.to_s].data_points
43
- end
78
+ #def method_missing(method_name,*args)
79
+ # splits = method_name.to_s.split("_")
80
+ # prof = self.profiles[splits[0].upcase]
81
+ # metrics = prof.metrics(args[0],args[1])
82
+ # return metrics[splits[1].downcase.to_s].data_points
83
+ #end
44
84
 
45
85
  end
46
86
  end
@@ -5,16 +5,17 @@ module NBS
5
5
 
6
6
  attr_accessor :service_type,:url, :artist_id, :options
7
7
 
8
- def initialize(artist_id,service_type, url="" ,options={})
8
+ def initialize(artist_id,service_type, url="",options={})
9
9
  self.service_type = service_type
10
10
  self.artist_id = artist_id
11
11
  self.url = url
12
12
  end
13
-
14
13
  def metrics(sdate,edate)
15
14
  @metrics ||= load_metrics(sdate,edate)
16
15
  end
17
-
16
+ def set_metrics(metrics_array={})
17
+ @metrics = metrics_array
18
+ end
18
19
  def load_metrics(sdate,edate)
19
20
  metrics ={}
20
21
  METRICS.each do |metric_string|
@@ -18,6 +18,9 @@ module NBS
18
18
  search.fetch
19
19
  return search
20
20
  end
21
+ def self.t_to_d(string_timestamp)
22
+ return Date.parse(Time.at(string_timestamp.to_i).to_s)
23
+ end
21
24
  remember :search
22
25
  end
23
26
  end
@@ -19,6 +19,9 @@ module NBS
19
19
  statsxml = Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{options.to_url_params}")).to_s
20
20
  end
21
21
  def data_points
22
+ unless @data_points.empty?
23
+ return @data_points
24
+ end
22
25
  begin
23
26
  points = to_hash["Profiles"][0]["Profile"][0]["DataPoint"]
24
27
  dps = []
@@ -30,6 +33,10 @@ module NBS
30
33
  return []
31
34
  end
32
35
  end
36
+ # this will allow me to load the data that I previously fetched.
37
+ def load_datapoints(data_points)
38
+ @data_points = data_points
39
+ end
33
40
  # delivers the datapoints as a Date keyed hash.
34
41
  #def date_points_hash
35
42
  #end
@@ -8,22 +8,23 @@ module NBS
8
8
  attr_accessor :options, :query, :api_key,:base_url, :xml
9
9
 
10
10
  def initialize(query, options={})
11
- self.options = {"query"=>query,"apiKey"=>$nbs_api_key,"format"=>"xml"}.merge(options)
11
+ self.options = {"q"=>query,"format"=>"xml"}.merge(options)
12
12
  self.query = query
13
13
  self.api_key = api_key
14
14
  self.base_url = base_url
15
15
  end
16
16
  def fetch
17
- puts "#{NBS::NBS_CONFIG["base_url"]}search?#{self.options.to_url_params}"
18
- self.xml=Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}search?#{self.options.to_url_params}")).to_s
17
+ puts "#{$nbs_api_key}artists/search?#{self.options.to_url_params}"
18
+ self.xml=Net::HTTP.get(URI.parse("#{$nbs_api_key}artists/search.#{self.options["format"]}?#{self.options.to_url_params}")).to_s
19
19
  #puts self.xml
20
20
  end
21
- def artists
21
+ def artists(options={})
22
22
  hash = Hash.from_xml(self.to_xml)
23
23
  a = []
24
+ #puts hash.inspect
24
25
  begin
25
- hash["Results"][0]["Result"].each do |item|
26
- a << NBS::Artist.new(item["NBSArtistID"][0],item["NBSArtistName"][0])
26
+ hash["data"][0]["artists"][0]["artist"].each do |item|
27
+ a << NBS::Artist.new(item["id"],item["name"][0],options)
27
28
  end
28
29
  rescue
29
30
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{next-big-sound}
8
- s.version = "0.6.1"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jeff durand"]
12
- s.date = %q{2010-04-16}
12
+ s.date = %q{2010-06-08}
13
13
  s.description = %q{A simple wrapper class for the Next Big Sound api. docs for the api can be found at api.nextbigsound.com}
14
14
  s.email = %q{jeff.durand@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -14,7 +14,7 @@ class TestNextBigSound < Test::Unit::TestCase
14
14
  @searchobj = @nbs.search("The Killers")
15
15
  end
16
16
  should "Be able to find The Killers ArtistID" do
17
- assert_match /<NBSArtistID>\d+<\/NBSArtistID>/i, @searchobj.to_xml
17
+ assert_match /<artist id=\"\d+\">/i, @searchobj.to_xml
18
18
  end
19
19
  should "have an array of results" do
20
20
  assert !@searchobj.artists.empty?
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - jeff durand
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-16 00:00:00 -04:00
17
+ date: 2010-06-08 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency