echonest 0.3.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.
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
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class ReviewsResult
5
+ include HappyMapper
6
+
7
+ tag :response
8
+
9
+ has_one :artist, ArtistDoc
10
+ has_one :results, ReviewsResults
11
+
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,17 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class ReviewsResults
5
+ include HappyMapper
6
+
7
+ tag :results
8
+
9
+ attribute :found, String
10
+ attribute :shown, String
11
+ attribute :start, String
12
+
13
+ has_many :docs, ReviewsDoc
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class SimilarDoc
5
+ include HappyMapper
6
+
7
+ tag :artist
8
+
9
+ #TODO: Add document elements
10
+ element :name, String
11
+ element :id, String
12
+ element :rank, Integer
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class SimilarResult
5
+ include HappyMapper
6
+
7
+ tag :response
8
+
9
+ has_one :artist, ArtistDoc
10
+ has_one :results, SimilarResults
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class SimilarResults
5
+ include HappyMapper
6
+
7
+ tag :similar
8
+ def found
9
+ -1
10
+ end
11
+
12
+ has_many :docs, SimilarDoc
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+
5
+ class UrlsResult
6
+ include HappyMapper
7
+
8
+ tag :response
9
+
10
+ has_one :artist, ArtistDoc
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class VideoDoc
5
+ include HappyMapper
6
+
7
+ tag :doc
8
+
9
+ #TODO: Add document elements
10
+ element :site, String
11
+ element :title, String
12
+ element :url, String
13
+ element :date_found, String
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class VideoResult
5
+ include HappyMapper
6
+
7
+ tag :response
8
+
9
+ has_one :artist, ArtistDoc
10
+ has_one :results, VideoResults
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class VideoResults
5
+ include HappyMapper
6
+
7
+ tag :results
8
+
9
+ attribute :found, String
10
+ attribute :shown, String
11
+ attribute :start, String
12
+
13
+ has_many :docs, VideoDoc
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "ApiRequest" do
4
+ before(:all) do
5
+ EchoNest.api_key = "API_KEY"
6
+ end
7
+
8
+ describe "uri" do
9
+ before(:each) do
10
+ @uri = EchoNest::ApiRequest.new("artist_search", :query => "Wavves").uri
11
+ end
12
+
13
+ it "should have the right resource" do
14
+ @uri.should be_starts_with("http://developer.echonest.com/api/artist_search?")
15
+ end
16
+
17
+ it "should contain query=Wavves" do
18
+ @uri.should be_include("query=Wavves") #There must be a nicer way to write this
19
+ end
20
+
21
+ it "should contain version=3" do
22
+ @uri.should be_include("version=3")
23
+ end
24
+
25
+ it "should contain api_key=API_KEY" do
26
+ @uri.should be_include("api_key=API_KEY")
27
+ end
28
+
29
+ end
30
+
31
+ describe "uri " do
32
+ it "should encode spaces" do
33
+ @uri = EchoNest::ApiRequest.new("artist_search", :query => "Built to Spill").uri
34
+ @uri.should be_include("query=Built%20to%20Spill");
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
2
+
3
+ include EchoNest
4
+
5
+ describe "PagedResult" do
6
+ before :each do
7
+ @docs = mock("docs", :length => 2)
8
+ @results = mock("results", :docs => @docs)
9
+ @block_body = mock("block body")
10
+ @block = Proc.new { |*args| @block_body.called(*args) }
11
+ @page = PagedResult.new @results, &@block
12
+
13
+ @docs2 = mock("docs2", :length => 2)
14
+ @page2 = mock("page2", :docs => @docs2)
15
+ @block_body.stub!(:called).and_return(@page2)
16
+
17
+ end
18
+
19
+ describe "each" do
20
+ it "should iterate over items in results" do
21
+ @docs.should_receive(:each)
22
+ @page.each
23
+ end
24
+ end
25
+
26
+ describe "[]" do
27
+ it "should return the nth doc" do
28
+ @docs.should_receive('[]').twice().with(1).and_return(:doc)
29
+ @page[1].should == :doc
30
+ end
31
+
32
+ it "should get the next page if index is out of range" do
33
+ @docs.should_receive('[]').at_least(1).and_return(nil)
34
+ @page.should_receive(:next_page)
35
+ @page[2]
36
+ end
37
+
38
+ end
39
+
40
+ describe "next_page" do
41
+
42
+ before(:each) do
43
+ @merged_docs = mock("Merged Docs", :length => 4)
44
+ @docs.stub!('+').and_return(@merged_docs)
45
+ end
46
+
47
+ it "should fetch the next page" do
48
+ @block_body.should_receive(:called).with(2, 15).and_return(@page2)
49
+ @page.next_page
50
+ end
51
+
52
+ it "should update the delegate" do
53
+ @docs.should_receive('+').with(@docs2).and_return(@merged_docs)
54
+ @page.next_page
55
+ @page.length.should == 4
56
+ end
57
+
58
+
59
+ end
60
+
61
+ describe "length" do
62
+
63
+ end
64
+
65
+
66
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "ArtistSearchResuls" do
4
+
5
+ describe "#parse" do
6
+
7
+ before(:each) do
8
+ @xml = File.read(File.dirname(__FILE__) + "/../../fixtures/search_artists/wavves.xml")
9
+ end
10
+
11
+ it "should parse xml" do
12
+ ArtistSearchResults.parse(@xml)
13
+ end
14
+
15
+ it "should have list of artists" do
16
+ search = ArtistSearchResults.parse(@xml)
17
+ search.artists.should be_kind_of(Array)
18
+ search.artists[0].should be_kind_of(ArtistDoc)
19
+ search.artists[0].name.should == "Wavves"
20
+ search.artists[0].id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "Audio" do
4
+
5
+ describe "#parse" do
6
+
7
+ before(:each) do
8
+ @xml = File.read(File.dirname(__FILE__) + "/../../fixtures/audio/wavves.xml")
9
+ end
10
+
11
+ it "should parse xml" do
12
+ AudioResult.parse(@xml)
13
+ end
14
+
15
+ it "should have artist" do
16
+ audio = AudioResult.parse(@xml)
17
+ audio.artist.should be_kind_of(ArtistDoc)
18
+ audio.artist.name.should == "Wavves"
19
+ audio.artist.id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
20
+ end
21
+
22
+ it "should have results" do
23
+ audio = AudioResult.parse(@xml)
24
+ audio.results.should be_kind_of(AudioResults)
25
+ audio.results.found.should == "51"
26
+ audio.results.shown.should == "15"
27
+ audio.results.start.should == "0"
28
+ audio.results.docs.should be_kind_of(Array)
29
+ audio.results.docs.length.should == 15
30
+ end
31
+
32
+ describe "result" do
33
+ it "should be an AudioDoc" do
34
+ audio = AudioResult.parse(@xml)
35
+ doc = audio.results.docs[0]
36
+ doc.should be_kind_of(AudioDoc)
37
+ doc.artist_id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
38
+ doc.artist.should == "Wavves"
39
+ doc.release.should == "03/21/09 Austin TX"
40
+ doc.title.should == "So Bored (LIVE SXSW 2009)"
41
+ doc.url.should == "http://www.2groundcontrol.com/IMAGENS/songs/03%20So%20Bored%20%28LIVE%20SXSW%202009%29.mp3"
42
+ doc.link.should == "http://2groundcontrol.blogspot.com"
43
+ doc.length.should == "265.0"
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "BlogsResult" do
4
+
5
+ describe "#parse" do
6
+
7
+ before(:each) do
8
+ @xml = File.read(File.dirname(__FILE__) + "/../../fixtures/blog/radiohead.xml")
9
+ end
10
+
11
+ it "should parse xml" do
12
+ BlogsResult.parse(@xml)
13
+ end
14
+
15
+ it "should have artist" do
16
+ blog = BlogsResult.parse(@xml)
17
+ blog.artist.should be_kind_of(ArtistDoc)
18
+ blog.artist.name.should == "Radiohead"
19
+ blog.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
20
+ end
21
+
22
+ it "should have results" do
23
+ blog = BlogsResult.parse(@xml)
24
+ blog.results.should be_kind_of(BlogsResults)
25
+ #TODO: Fill in these values as found in fixture
26
+ blog.results.found.should == "131"
27
+ blog.results.shown.should == "2"
28
+ blog.results.start.should == "0"
29
+ blog.results.docs.should be_kind_of(Array)
30
+ blog.results.docs.length.should == 2
31
+ end
32
+
33
+ describe "result" do
34
+ it "should be an BlogDoc" do
35
+ blog = BlogsResult.parse(@xml)
36
+ doc = blog.results.docs[0]
37
+ doc.should be_kind_of(BlogsDoc)
38
+ #TODO: Create tests based on attributes in resource
39
+ doc.name.should == "Radiohead live at Santa Barbara 28.8.08 « Misspeak Music"
40
+ doc.url.should == "http://misspeakmusic.wordpress.com/2008/09/01/radiohead-live-at-santa-barbara-28808/"
41
+ doc.summary.should == "[blog text removed]"
42
+ doc.date_found.should == "2008-10-14 16:38:15.582000"
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "FamiliarityResult" do
4
+
5
+ describe "#parse" do
6
+
7
+ before(:each) do
8
+ @xml = File.read(File.dirname(__FILE__) + "/../../fixtures/familiarity/radiohead.xml")
9
+ end
10
+
11
+ it "should parse xml" do
12
+ FamiliarityResult.parse(@xml)
13
+ end
14
+
15
+ it "should have artist" do
16
+ familiarity = FamiliarityResult.parse(@xml)
17
+ familiarity.artist.should be_kind_of(ArtistDoc)
18
+ familiarity.artist.name.should == "Radiohead"
19
+ familiarity.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
20
+ end
21
+
22
+ it " artist should have familiarity" do
23
+ familiarity = FamiliarityResult.parse(@xml)
24
+ familiarity.artist.should be_kind_of(ArtistDoc)
25
+ familiarity.artist.familiarity.should_not be_nil
26
+ familiarity.artist.familiarity.should == 0.96974159665
27
+ end
28
+
29
+
30
+ end
31
+
32
+
33
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "HotttnessResult" do
4
+
5
+ describe "#parse" do
6
+
7
+ before(:each) do
8
+ @xml = File.read(File.dirname(__FILE__) + "/../../fixtures/hotttnesss/radiohead.xml")
9
+ end
10
+
11
+ it "should parse xml" do
12
+ HotttnesssResult.parse(@xml)
13
+ end
14
+
15
+ it "should have artist" do
16
+ hottnesss = HotttnesssResult.parse(@xml)
17
+ hottnesss.artist.should be_kind_of(ArtistDoc)
18
+ hottnesss.artist.name.should == "Radiohead"
19
+ hottnesss.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
20
+ end
21
+
22
+ it "artist should have hottnesss" do
23
+ hottnesss = HotttnesssResult.parse(@xml)
24
+ hottnesss.artist.should be_kind_of(ArtistDoc)
25
+ hottnesss.artist.hotttnesss.should_not be_nil
26
+ hottnesss.artist.hotttnesss.should == 0.96974159665
27
+ end
28
+ end
29
+
30
+
31
+ end