next-big-sound 0.3.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
22
  test/credentials.yml
23
+ playing.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.4.0
data/lib/artist.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module NBS
2
2
  class Artist
3
-
3
+
4
4
  attr_accessor :artist_id, :name, :xml, :options
5
5
 
6
6
  PROFILES = %w(all myspace lastfm ilike facebook twitter youtube reverbnation ourstage soundcloud purevolume bebo virb amiestreet jamlegend vimeo)
@@ -37,6 +37,6 @@ module NBS
37
37
  metrics = prof.metrics(args[0],args[1])
38
38
  return metrics[splits[1].downcase.to_s].data_points
39
39
  end
40
-
40
+
41
41
  end
42
42
  end
data/lib/memoize.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'memcache'
2
+ module NBS
3
+ module MemcachedMemoize
4
+ def remember(name)
5
+
6
+ original_method = instance_method(name)
7
+ define_method(name) do |*args|
8
+
9
+ if defined?(KEYSTORE)
10
+ key = args.collect {|c| c.to_s }.join("_").gsub(" ","_")
11
+ key+=name.to_s
12
+ puts key
13
+ if KEYSTORE.get(key)!=nil
14
+ puts "it was memorized"
15
+ Marshal.restore(KEYSTORE.get(key))
16
+ else
17
+ puts "it had to be memorized"
18
+ bound_method = original_method.bind(self)
19
+ #puts Marshal.dump(bound_method.call(*args))
20
+ KEYSTORE.set(key,Marshal.dump(bound_method.call(*args)))
21
+ return Marshal.restore(KEYSTORE.get(key))
22
+ end
23
+ else
24
+ bound_method = original_method.bind(self)
25
+ bound_method.call(*args)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/metric.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  module NBS
2
2
 
3
3
  class Metric
4
-
4
+ extend NBS::MemcachedMemoize
5
+
5
6
  attr_accessor :artist_id,:service_type,:metric,:sdate,:edate, :xml
7
+
8
+
6
9
  def initialize(artist_id,service_type,metric,sdate,edate)
7
10
  self.artist_id = artist_id
8
11
  self.service_type = service_type
@@ -10,7 +13,7 @@ module NBS
10
13
  self.sdate = Date.parse(sdate.to_s)
11
14
  self.edate = Date.parse(edate.to_s)
12
15
  end
13
- def fetch
16
+ def fetch(myopts_test={})
14
17
  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
18
  puts "#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{options.to_url_params}"
16
19
  statsxml = Net::HTTP.get(URI.parse("#{NBS::NBS_CONFIG["base_url"]}getDataForArtist?#{options.to_url_params}")).to_s
@@ -27,14 +30,18 @@ module NBS
27
30
  return []
28
31
  end
29
32
  end
33
+ # delivers the datapoints as a Date keyed hash.
34
+ #def date_points_hash
35
+ #end
30
36
  #def xml_data_points
31
37
  #to_hash["Profiles"][0]["Profile"][0]["DataPoint"].to_xml
32
38
  #end
33
39
  def to_xml
34
- self.xml ||= fetch
40
+ 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"})
35
41
  end
36
42
  def to_hash
37
43
  Hash.from_xml(to_xml)
38
44
  end
45
+ remember :fetch
39
46
  end
40
47
  end
@@ -2,7 +2,8 @@ module NBS
2
2
 
3
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib','config'))
4
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
-
5
+ require 'rubygems'
6
+ require 'memoize'
6
7
  require 'yaml'
7
8
  require 'hash_extension'
8
9
  require 'search'
@@ -11,13 +12,22 @@ module NBS
11
12
  require 'metric'
12
13
  require 'datapoint'
13
14
 
15
+
16
+
14
17
  #puts "#{File.dirname(__FILE__)}/config.yml"
15
18
  NBS_CONFIG = YAML.load_file("#{File.dirname(__FILE__)}/config.yml")
16
19
 
20
+ #CACHE_ENABLED
21
+ #KEYSTORE = nil
22
+
23
+
17
24
  class Base
18
-
25
+
26
+ extend NBS::MemcachedMemoize
27
+
19
28
  def initialize(api_key)
20
29
  $nbs_api_key = api_key
30
+ #puts CACHE_ENABLED
21
31
  end
22
32
  # return a search object that you can manipulate
23
33
  # if you prefer to just use the xml simply type to_xml
@@ -27,5 +37,6 @@ module NBS
27
37
  search.fetch
28
38
  return search
29
39
  end
40
+ remember :search
30
41
  end
31
42
  end
data/lib/search.rb CHANGED
@@ -4,7 +4,10 @@ module NBS
4
4
  require 'uri'
5
5
 
6
6
  class Search
7
-
7
+
8
+ #extend NBS::MemcachedMemoize
9
+
10
+
8
11
  attr_accessor :options, :query, :api_key,:base_url, :xml
9
12
 
10
13
  def initialize(query, options={})
@@ -27,5 +30,7 @@ module NBS
27
30
  def to_xml
28
31
  self.xml ||=fetch
29
32
  end
33
+
34
+ #remember :fetch
30
35
  end
31
36
  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.3.5"
8
+ s.version = "0.4.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-29}
12
+ s.date = %q{2010-04-05}
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 = [
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/config.yml",
29
29
  "lib/datapoint.rb",
30
30
  "lib/hash_extension.rb",
31
+ "lib/memoize.rb",
31
32
  "lib/metric.rb",
32
33
  "lib/next-big-sound.rb",
33
34
  "lib/search.rb",
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 5
9
- version: 0.3.5
7
+ - 4
8
+ - 0
9
+ version: 0.4.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-29 00:00:00 -04:00
17
+ date: 2010-04-05 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,7 @@ files:
50
50
  - lib/config.yml
51
51
  - lib/datapoint.rb
52
52
  - lib/hash_extension.rb
53
+ - lib/memoize.rb
53
54
  - lib/metric.rb
54
55
  - lib/next-big-sound.rb
55
56
  - lib/search.rb