echonest 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +7 -0
  3. data/Rakefile +56 -0
  4. data/VERSION.yml +4 -0
  5. data/examples/artist_audio.rb +33 -0
  6. data/generators/echonest_acceptance_test/USAGE +5 -0
  7. data/generators/echonest_acceptance_test/echonest_acceptance_test_generator.rb +50 -0
  8. data/generators/echonest_acceptance_test/templates/feature.erb +8 -0
  9. data/generators/echonest_model/USAGE +5 -0
  10. data/generators/echonest_model/echonest_model_generator.rb +52 -0
  11. data/generators/echonest_model/templates/doc.rb.erb +12 -0
  12. data/generators/echonest_model/templates/result.rb.erb +12 -0
  13. data/generators/echonest_model/templates/results.rb.erb +15 -0
  14. data/generators/echonest_resource/USAGE +5 -0
  15. data/generators/echonest_resource/echonest_resource_generator.rb +50 -0
  16. data/generators/echonest_unit_test/USAGE +5 -0
  17. data/generators/echonest_unit_test/echonest_unit_test_generator.rb +50 -0
  18. data/generators/echonest_unit_test/templates/unit_test.rb.erb +44 -0
  19. data/lib/echonest.rb +56 -0
  20. data/lib/echonest/api_request.rb +26 -0
  21. data/lib/echonest/artist.rb +74 -0
  22. data/lib/echonest/paged_result.rb +33 -0
  23. data/lib/echonest/xml/artist_doc.rb +23 -0
  24. data/lib/echonest/xml/artist_search_results.rb +14 -0
  25. data/lib/echonest/xml/audio_doc.rb +20 -0
  26. data/lib/echonest/xml/audio_result.rb +13 -0
  27. data/lib/echonest/xml/audio_results.rb +16 -0
  28. data/lib/echonest/xml/blogs_doc.rb +15 -0
  29. data/lib/echonest/xml/blogs_result.rb +14 -0
  30. data/lib/echonest/xml/blogs_results.rb +18 -0
  31. data/lib/echonest/xml/familiarity_result.rb +12 -0
  32. data/lib/echonest/xml/hotttnesss_result.rb +12 -0
  33. data/lib/echonest/xml/news_doc.rb +15 -0
  34. data/lib/echonest/xml/news_result.rb +14 -0
  35. data/lib/echonest/xml/news_results.rb +16 -0
  36. data/lib/echonest/xml/profile_result.rb +12 -0
  37. data/lib/echonest/xml/reviews_doc.rb +16 -0
  38. data/lib/echonest/xml/reviews_result.rb +15 -0
  39. data/lib/echonest/xml/reviews_results.rb +17 -0
  40. data/lib/echonest/xml/similar_doc.rb +15 -0
  41. data/lib/echonest/xml/similar_result.rb +14 -0
  42. data/lib/echonest/xml/similar_results.rb +16 -0
  43. data/lib/echonest/xml/urls_result.rb +14 -0
  44. data/lib/echonest/xml/video_doc.rb +16 -0
  45. data/lib/echonest/xml/video_result.rb +14 -0
  46. data/lib/echonest/xml/video_results.rb +17 -0
  47. data/spec/echonest/api_request_spec.rb +38 -0
  48. data/spec/echonest/paged_result_spec.rb +66 -0
  49. data/spec/echonest/xml/artist_search_results_spec.rb +25 -0
  50. data/spec/echonest/xml/audio_result_spec.rb +49 -0
  51. data/spec/echonest/xml/blogs_result_spec.rb +48 -0
  52. data/spec/echonest/xml/familiarity_result_spec.rb +33 -0
  53. data/spec/echonest/xml/hotttness_result_spec.rb +31 -0
  54. data/spec/echonest/xml/news_result_spec.rb +49 -0
  55. data/spec/echonest/xml/profile_result_spec.rb +26 -0
  56. data/spec/echonest/xml/refactor.rb +12 -0
  57. data/spec/echonest/xml/reviews_result_spec.rb +49 -0
  58. data/spec/echonest/xml/similar_result_spec.rb +35 -0
  59. data/spec/echonest/xml/urls_result_spec.rb +38 -0
  60. data/spec/echonest/xml/video_result_spec.rb +48 -0
  61. data/spec/fixtures/audio/wavves.xml +2 -0
  62. data/spec/fixtures/blog/radiohead.xml +32 -0
  63. data/spec/fixtures/familiarity/radiohead.xml +17 -0
  64. data/spec/fixtures/hotttnesss/radiohead.xml +17 -0
  65. data/spec/fixtures/news/radiohead.xml +32 -0
  66. data/spec/fixtures/profile/radiohead.xml +16 -0
  67. data/spec/fixtures/reviews/radiohead.xml +40 -0
  68. data/spec/fixtures/search_artists/wavves.xml +2 -0
  69. data/spec/fixtures/similar/radiohead.xml +31 -0
  70. data/spec/fixtures/urls/radiohead.xml +21 -0
  71. data/spec/fixtures/video/radiohead.xml +32 -0
  72. data/spec/spec_helper.rb +15 -0
  73. data/test/test_echonest_acceptance_test_generator.rb +52 -0
  74. data/test/test_echonest_model_generator.rb +47 -0
  75. data/test/test_echonest_resource_generator.rb +45 -0
  76. data/test/test_echonest_unit_test_generator.rb +35 -0
  77. data/test/test_generator_helper.rb +29 -0
  78. metadata +164 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Gareth Andrew
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ = echonest
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Gareth Andrew. See LICENSE for details.
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "echonest"
8
+ gem.summary = "A ruby ribrary for accessing the echonest api"
9
+ gem.email = "gingerhendrix@hotmail.com"
10
+ gem.homepage = "http://github.com/gingerhendrix/echonest"
11
+ gem.authors = ["Gareth Andrew"]
12
+
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+ begin
32
+ require 'cucumber/rake/task'
33
+ Cucumber::Rake::Task.new(:features)
34
+ rescue LoadError
35
+ task :features do
36
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
37
+ end
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "echonest #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 3
4
+ :patch: 0
@@ -0,0 +1,33 @@
1
+
2
+ require 'rubygems'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'echonest'
6
+ require 'highline'
7
+
8
+ include EchoNest
9
+
10
+ EchoNest.api_key = "CREDOYO7GFJ9OW3TV"
11
+
12
+ HighLine.track_eof = false
13
+ highline = HighLine.new
14
+
15
+ artist_name = highline.ask "Please type an artist name? "
16
+ artist_search = Artist.find artist_name
17
+ search_names = artist_search.map(&:name)
18
+ highline.say "Found #{search_names.length}"
19
+ choice = highline.choose do |menu|
20
+ menu.select_by = :index
21
+ menu.choices(*search_names)
22
+ end
23
+ idx = search_names.index choice
24
+ highline.say "Finding audio for #{artist_search[idx].name} - #{artist_search[idx].id}"
25
+ artist = Artist.new artist_search[idx].id
26
+ audio = artist.audio
27
+ highline.say "Found #{audio.found}, retrieved #{audio.length}"
28
+ highline.say highline.list( audio.map(&:title) )
29
+ while highline.agree "Next?"
30
+ audio.next_page
31
+ highline.say highline.list( audio.map(&:title) )
32
+ end
33
+
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,50 @@
1
+ class EchonestAcceptanceTestGenerator < RubiGen::Base
2
+
3
+ default_options :author => nil
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ usage if args.empty?
10
+ @name = args.shift
11
+ extract_options
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ # Ensure appropriate folder(s) exists
17
+ m.directory 'features'
18
+
19
+ # Create stubs
20
+ m.template "feature.erb", "features/artist_#{@name}.feature"
21
+ end
22
+ end
23
+
24
+ protected
25
+ def banner
26
+ <<-EOS
27
+ Creates a ...
28
+
29
+ USAGE: #{$0} #{spec.name} name
30
+ EOS
31
+ end
32
+
33
+ def add_options!(opts)
34
+ # opts.separator ''
35
+ # opts.separator 'Options:'
36
+ # For each option below, place the default
37
+ # at the top of the file next to "default_options"
38
+ # opts.on("-a", "--author=\"Your Name\"", String,
39
+ # "Some comment about this option",
40
+ # "Default: none") { |o| options[:author] = o }
41
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
42
+ end
43
+
44
+ def extract_options
45
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
46
+ # Templates can access these value via the attr_reader-generated methods, but not the
47
+ # raw instance variable value.
48
+ # @author = options[:author]
49
+ end
50
+ end
@@ -0,0 +1,8 @@
1
+ Feature: Artist <%= name %>
2
+ In order to find <%= name %> about an an artist
3
+ A user should be able to retrieve <%= name %> for an artist
4
+
5
+ Scenario: Artist <%= name %>
6
+ When I retrieve the <%= name %> for "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
7
+ Then I should get some <%= name %> results
8
+
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,52 @@
1
+ class EchonestModelGenerator < RubiGen::Base
2
+
3
+ default_options :author => nil
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ usage if args.empty?
10
+ @name = args.shift
11
+ extract_options
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ # Ensure appropriate folder(s) exists
17
+ m.directory 'lib/echonest'
18
+
19
+ m.template "result.rb.erb", "lib/echonest/#{name}_result.rb"
20
+ m.template "results.rb.erb", "lib/echonest/#{name}_results.rb"
21
+ m.template "doc.rb.erb", "lib/echonest/#{name}_doc.rb"
22
+
23
+ end
24
+ end
25
+
26
+ protected
27
+ def banner
28
+ <<-EOS
29
+ Creates a ...
30
+
31
+ USAGE: #{$0} #{spec.name} name
32
+ EOS
33
+ end
34
+
35
+ def add_options!(opts)
36
+ # opts.separator ''
37
+ # opts.separator 'Options:'
38
+ # For each option below, place the default
39
+ # at the top of the file next to "default_options"
40
+ # opts.on("-a", "--author=\"Your Name\"", String,
41
+ # "Some comment about this option",
42
+ # "Default: none") { |o| options[:author] = o }
43
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
44
+ end
45
+
46
+ def extract_options
47
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
48
+ # Templates can access these value via the attr_reader-generated methods, but not the
49
+ # raw instance variable value.
50
+ # @author = options[:author]
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ class <%=name.capitalize%>Doc
4
+ include HappyMapper
5
+
6
+ tag :doc
7
+
8
+ #TODO: Add document elements
9
+ # element :name, String
10
+ # element :url, String
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ class <%=name.capitalize%>Result
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+ has_one :results, <%=name.capitalize%>Results
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ class <%=name.capitalize%>Results
4
+ include HappyMapper
5
+
6
+ tag :results
7
+
8
+ attribute :found, String
9
+ attribute :shown, String
10
+ attribute :start, String
11
+
12
+ has_many :docs, <%=name.capitalize%>Doc
13
+
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,50 @@
1
+ class EchonestResourceGenerator < RubiGen::Base
2
+
3
+ default_options :author => nil
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ usage if args.empty?
10
+ @name = args.shift
11
+ extract_options
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ # Ensure appropriate folder(s) exists
17
+ m.dependency "echonest_acceptance_test", [name]
18
+ m.dependency "echonest_unit_test", [name]
19
+ m.dependency "echonest_model", [name]
20
+ end
21
+ end
22
+
23
+ protected
24
+ def banner
25
+ <<-EOS
26
+ Creates a ...
27
+
28
+ USAGE: #{$0} #{spec.name} name
29
+ EOS
30
+ end
31
+
32
+ def add_options!(opts)
33
+ # opts.separator ''
34
+ # opts.separator 'Options:'
35
+ # For each option below, place the default
36
+ # at the top of the file next to "default_options"
37
+ # opts.on("-a", "--author=\"Your Name\"", String,
38
+ # "Some comment about this option",
39
+ # "Default: none") { |o| options[:author] = o }
40
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
41
+ end
42
+
43
+ def extract_options
44
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
45
+ # Templates can access these value via the attr_reader-generated methods, but not the
46
+ # raw instance variable value.
47
+ # @author = options[:author]
48
+ end
49
+ end
50
+
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,50 @@
1
+ class EchonestUnitTestGenerator < RubiGen::Base
2
+
3
+ default_options :author => nil
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ usage if args.empty?
10
+ @name = args.shift
11
+ extract_options
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ # Ensure appropriate folder(s) exists
17
+ m.directory 'spec/echonest'
18
+
19
+ # Create stubs
20
+ m.template "unit_test.rb.erb", "spec/echonest/#{name}_result_spec.rb"
21
+ end
22
+ end
23
+
24
+ protected
25
+ def banner
26
+ <<-EOS
27
+ Creates a ...
28
+
29
+ USAGE: #{$0} #{spec.name} name
30
+ EOS
31
+ end
32
+
33
+ def add_options!(opts)
34
+ # opts.separator ''
35
+ # opts.separator 'Options:'
36
+ # For each option below, place the default
37
+ # at the top of the file next to "default_options"
38
+ # opts.on("-a", "--author=\"Your Name\"", String,
39
+ # "Some comment about this option",
40
+ # "Default: none") { |o| options[:author] = o }
41
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
42
+ end
43
+
44
+ def extract_options
45
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
46
+ # Templates can access these value via the attr_reader-generated methods, but not the
47
+ # raw instance variable value.
48
+ # @author = options[:author]
49
+ end
50
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "<%=name.capitalize%>Result" do
4
+
5
+ describe "#parse" do
6
+
7
+ before(:each) do
8
+ @xml = File.read(File.dirname(__FILE__) + "/../fixtures/<%=name%>/radiohead.xml")
9
+ end
10
+
11
+ it "should parse xml" do
12
+ EchoNest::<%=name.capitalize%>Result.parse(@xml)
13
+ end
14
+
15
+ it "should have artist" do
16
+ <%=name%> = EchoNest::<%=name.capitalize%>Result.parse(@xml)
17
+ <%=name%>.artist.should be_kind_of(EchoNest::Artist)
18
+ <%=name%>.artist.name.should == "Radiohead"
19
+ <%=name%>.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
20
+ end
21
+
22
+ it "should have results" do
23
+ <%=name%> = EchoNest::<%=name.capitalize%>Result.parse(@xml)
24
+ <%=name%>.results.should be_kind_of(EchoNest::<%=name.capitalize%>Results)
25
+ #TODO: Fill in these values as found in fixture
26
+ <%=name%>.results.found.should == "51"
27
+ <%=name%>.results.shown.should == "15"
28
+ <%=name%>.results.start.should == "0"
29
+ <%=name%>.results.docs.should be_kind_of(Array)
30
+ <%=name%>.results.docs.length.should == 15
31
+ end
32
+
33
+ describe "result" do
34
+ it "should be an <%=name.capitalize%>Doc" do
35
+ <%=name%> = EchoNest::<%=name.capitalize%>Result.parse(@xml)
36
+ doc = <%=name%>.results.docs[0]
37
+ doc.should be_kind_of(EchoNest::<%=name.capitalize%>Doc)
38
+ #TODO: Create tests based on attributes in resource
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ end