next-big-sound 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +22 -14
- data/VERSION +1 -1
- data/lib/artist.rb +9 -12
- data/lib/artist_profile.rb +26 -0
- data/lib/datapoint.rb +12 -0
- data/lib/metric.rb +37 -0
- data/lib/next-big-sound.rb +4 -0
- data/next-big-sound.gemspec +5 -2
- data/test/helper.rb +1 -1
- data/test/test_search.rb +2 -2
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -28,28 +28,36 @@ This code was written by jeff at musicxray.com if you think you can do better se
|
|
28
28
|
# get the first artist that you find and find
|
29
29
|
# all associated profiles. myspace, ilike ....
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
artist = searchobj.artists.first
|
32
|
+
|
33
|
+
artist.profiles
|
33
34
|
# get the url for a specific service
|
34
35
|
|
35
|
-
profiles["MYSPACE"]
|
36
|
-
|
36
|
+
artist.profiles["MYSPACE"]
|
37
37
|
# in addition. There is are magic method for retrieving data
|
38
38
|
# if you want myspace plays for example you would get it like this
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
# Each profile can have multiple metrics
|
41
|
+
# each metric has an array of datapoints.
|
42
|
+
# datapoints consist of a DateTime Object and a float
|
43
|
+
# example usage follows
|
44
|
+
|
45
|
+
profile = artist.profiles["MYSPACE"]
|
46
|
+
|
47
|
+
metrics = profile.metrics("4/24/2009","4/24/2010")
|
48
|
+
datapoints = metrics["plays"].data_points
|
44
49
|
|
45
|
-
#
|
46
|
-
# services.
|
47
|
-
artist.all_fans("1/1/2010","2/1/2010")
|
50
|
+
#The datapoints array can then be iterated over.
|
48
51
|
|
49
|
-
#
|
50
|
-
|
52
|
+
#shortcut methods have been provided for convenience is as follows
|
53
|
+
|
54
|
+
artist.myspace_plays_datapoints("4/24/2009","4/24/2010")
|
55
|
+
|
56
|
+
This will return the datapoints you are looking for ....
|
57
|
+
|
58
|
+
|
59
|
+
|
51
60
|
|
52
|
-
# TODO: this stuff is still be implemented.
|
53
61
|
|
54
62
|
|
55
63
|
== Note on Patches/Pull Requests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/artist.rb
CHANGED
@@ -3,13 +3,15 @@ module NBS
|
|
3
3
|
|
4
4
|
attr_accessor :artist_id, :name, :xml, :options
|
5
5
|
|
6
|
+
PROFILES = %w(all myspace lastfm ilike facebook twitter youtube reverbnation ourstage soundcloud purevolume bebo virb amiestreet jamlegend vimeo)
|
7
|
+
|
6
8
|
def initialize(artist_id, name="",options={})
|
7
9
|
self.artist_id=artist_id
|
8
10
|
self.name = name
|
9
11
|
self.options = {"artistID"=>self.artist_id,"apiKey"=>$nbs_api_key,"format"=>"xml"}.merge(options)
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
14
|
+
def fetch_profiles
|
13
15
|
self.xml=Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getProfilesForArtist?#{self.options.to_url_params}")).to_s
|
14
16
|
end
|
15
17
|
|
@@ -18,27 +20,22 @@ module NBS
|
|
18
20
|
####
|
19
21
|
profs = {}
|
20
22
|
self.to_hash["Profiles"][0]["Profile"].each do |item|
|
21
|
-
profs[item["service"]]=item["url"]
|
23
|
+
profs[item["service"].to_s]=ArtistProfile.new(self.artist_id, item["service"] ,item["url"])
|
22
24
|
end
|
23
25
|
return profs
|
24
26
|
end
|
25
|
-
|
26
27
|
def to_xml
|
27
|
-
self.xml ||=
|
28
|
+
self.xml ||= fetch_profiles
|
28
29
|
end
|
29
30
|
def to_hash
|
30
31
|
Hash.from_xml(self.to_xml)
|
31
32
|
end
|
32
33
|
|
33
34
|
def method_missing(method_name,*args)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
return Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{opts.to_url_params}")).to_s
|
39
|
-
else
|
40
|
-
raise "Sorry that method does not exist. The proper format for finding data is service_metric(start,end)"
|
41
|
-
end
|
35
|
+
splits = method_name.to_s.split("_")
|
36
|
+
prof = self.profiles[splits[0].upcase]
|
37
|
+
metrics = prof.metrics(args[0],args[1])
|
38
|
+
return metrics[splits[1].downcase.to_s].data_points
|
42
39
|
end
|
43
40
|
|
44
41
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NBS
|
2
|
+
|
3
|
+
class ArtistProfile
|
4
|
+
METRICS = %w(plays fans views comments downloads likes price)
|
5
|
+
|
6
|
+
attr_accessor :service_type,:url, :artist_id, :options
|
7
|
+
|
8
|
+
def initialize(artist_id,service_type, url="" ,options={})
|
9
|
+
self.service_type = service_type
|
10
|
+
self.artist_id = artist_id
|
11
|
+
self.url = url
|
12
|
+
end
|
13
|
+
|
14
|
+
def metrics(sdate,edate)
|
15
|
+
@metrics ||= load_metrics(sdate,edate)
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_metrics(sdate,edate)
|
19
|
+
metrics ={}
|
20
|
+
METRICS.each do |metric_string|
|
21
|
+
metrics[metric_string.to_s] = Metric.new(self.artist_id,self.service_type,metric_string.to_s,sdate,edate)
|
22
|
+
end
|
23
|
+
return metrics
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/datapoint.rb
ADDED
data/lib/metric.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module NBS
|
2
|
+
|
3
|
+
class Metric
|
4
|
+
|
5
|
+
attr_accessor :artist_id,:service_type,:metric,:sdate,:edate, :xml
|
6
|
+
def initialize(artist_id,service_type,metric,sdate,edate)
|
7
|
+
self.artist_id = artist_id
|
8
|
+
self.service_type = service_type
|
9
|
+
self.metric = metric
|
10
|
+
self.sdate = Date.parse(sdate.to_s)
|
11
|
+
self.edate = Date.parse(edate.to_s)
|
12
|
+
end
|
13
|
+
def fetch
|
14
|
+
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"}
|
15
|
+
puts "#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{options.to_url_params}"
|
16
|
+
statsxml = Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{options.to_url_params}")).to_s
|
17
|
+
end
|
18
|
+
def data_points
|
19
|
+
begin
|
20
|
+
points = to_hash["Profiles"][0]["Profile"][0]["DataPoint"]
|
21
|
+
dps = []
|
22
|
+
points.each do |dp|
|
23
|
+
dps << DataPoint.new(dp["date"],dp["value"])
|
24
|
+
end
|
25
|
+
return dps
|
26
|
+
rescue
|
27
|
+
return []
|
28
|
+
end
|
29
|
+
end
|
30
|
+
def to_xml
|
31
|
+
self.xml ||= fetch
|
32
|
+
end
|
33
|
+
def to_hash
|
34
|
+
Hash.from_xml(to_xml)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/next-big-sound.rb
CHANGED
data/next-big-sound.gemspec
CHANGED
@@ -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.
|
8
|
+
s.version = "0.2.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-03-
|
12
|
+
s.date = %q{2010-03-29}
|
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 = [
|
@@ -25,7 +25,10 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"config.yml",
|
27
27
|
"lib/artist.rb",
|
28
|
+
"lib/artist_profile.rb",
|
29
|
+
"lib/datapoint.rb",
|
28
30
|
"lib/hash_extension.rb",
|
31
|
+
"lib/metric.rb",
|
29
32
|
"lib/next-big-sound.rb",
|
30
33
|
"lib/search.rb",
|
31
34
|
"next-big-sound.gemspec",
|
data/test/helper.rb
CHANGED
data/test/test_search.rb
CHANGED
@@ -22,8 +22,8 @@ class TestNextBigSound < Test::Unit::TestCase
|
|
22
22
|
should "have first result with artist name of The Killers" do
|
23
23
|
assert_equal "The Killers", @searchobj.artists.first.name
|
24
24
|
end
|
25
|
-
should "
|
26
|
-
assert @searchobj.artists.first.
|
25
|
+
should "metrics for profile" do
|
26
|
+
assert @searchobj.artists.first.profiles.first.is_a?(Profile)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
#should "have many re"
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 1
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.2.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-03-
|
17
|
+
date: 2010-03-29 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -47,7 +47,10 @@ files:
|
|
47
47
|
- VERSION
|
48
48
|
- config.yml
|
49
49
|
- lib/artist.rb
|
50
|
+
- lib/artist_profile.rb
|
51
|
+
- lib/datapoint.rb
|
50
52
|
- lib/hash_extension.rb
|
53
|
+
- lib/metric.rb
|
51
54
|
- lib/next-big-sound.rb
|
52
55
|
- lib/search.rb
|
53
56
|
- next-big-sound.gemspec
|