gingerhendrix-echonest 0.2.0 → 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 (68) hide show
  1. data/VERSION.yml +1 -1
  2. data/examples/artist_audio.rb +33 -0
  3. data/lib/echonest.rb +39 -29
  4. data/lib/echonest/artist.rb +57 -53
  5. data/lib/echonest/paged_result.rb +33 -0
  6. data/lib/echonest/xml/artist_doc.rb +23 -0
  7. data/lib/echonest/xml/artist_search_results.rb +14 -0
  8. data/lib/echonest/xml/audio_doc.rb +20 -0
  9. data/lib/echonest/xml/audio_result.rb +13 -0
  10. data/lib/echonest/xml/audio_results.rb +16 -0
  11. data/lib/echonest/xml/blogs_doc.rb +15 -0
  12. data/lib/echonest/xml/blogs_result.rb +14 -0
  13. data/lib/echonest/xml/blogs_results.rb +18 -0
  14. data/lib/echonest/xml/familiarity_result.rb +12 -0
  15. data/lib/echonest/xml/hotttnesss_result.rb +12 -0
  16. data/lib/echonest/xml/news_doc.rb +15 -0
  17. data/lib/echonest/xml/news_result.rb +14 -0
  18. data/lib/echonest/xml/news_results.rb +16 -0
  19. data/lib/echonest/xml/profile_result.rb +12 -0
  20. data/lib/echonest/xml/reviews_doc.rb +16 -0
  21. data/lib/echonest/xml/reviews_result.rb +15 -0
  22. data/lib/echonest/xml/reviews_results.rb +17 -0
  23. data/lib/echonest/xml/similar_doc.rb +15 -0
  24. data/lib/echonest/xml/similar_result.rb +14 -0
  25. data/lib/echonest/xml/similar_results.rb +16 -0
  26. data/lib/echonest/xml/urls_result.rb +14 -0
  27. data/lib/echonest/xml/video_doc.rb +16 -0
  28. data/lib/echonest/xml/video_result.rb +14 -0
  29. data/lib/echonest/xml/video_results.rb +17 -0
  30. data/spec/echonest/paged_result_spec.rb +66 -0
  31. data/spec/echonest/xml/artist_search_results_spec.rb +25 -0
  32. data/spec/echonest/{audio_result_spec.rb → xml/audio_result_spec.rb} +9 -9
  33. data/spec/echonest/{blog_result_spec.rb → xml/blogs_result_spec.rb} +10 -10
  34. data/spec/echonest/{familiarity_result_spec.rb → xml/familiarity_result_spec.rb} +7 -7
  35. data/spec/echonest/{hotttness_result_spec.rb → xml/hotttness_result_spec.rb} +7 -7
  36. data/spec/echonest/{news_result_spec.rb → xml/news_result_spec.rb} +9 -9
  37. data/spec/echonest/{profile_result_spec.rb → xml/profile_result_spec.rb} +5 -5
  38. data/spec/echonest/xml/refactor.rb +12 -0
  39. data/spec/echonest/{reviews_result_spec.rb → xml/reviews_result_spec.rb} +9 -9
  40. data/spec/echonest/{similar_result_spec.rb → xml/similar_result_spec.rb} +7 -7
  41. data/spec/echonest/{urls_result_spec.rb → xml/urls_result_spec.rb} +6 -6
  42. data/spec/echonest/{video_result_spec.rb → xml/video_result_spec.rb} +9 -9
  43. data/spec/spec_helper.rb +2 -0
  44. metadata +57 -48
  45. data/lib/echonest/artist_search.rb +0 -18
  46. data/lib/echonest/audio_doc.rb +0 -18
  47. data/lib/echonest/audio_result.rb +0 -12
  48. data/lib/echonest/audio_results.rb +0 -15
  49. data/lib/echonest/blog_doc.rb +0 -13
  50. data/lib/echonest/blog_result.rb +0 -12
  51. data/lib/echonest/blog_results.rb +0 -15
  52. data/lib/echonest/familiarity_result.rb +0 -11
  53. data/lib/echonest/hotttnesss_result.rb +0 -11
  54. data/lib/echonest/news_doc.rb +0 -13
  55. data/lib/echonest/news_result.rb +0 -12
  56. data/lib/echonest/news_results.rb +0 -15
  57. data/lib/echonest/profile_result.rb +0 -11
  58. data/lib/echonest/reviews_doc.rb +0 -15
  59. data/lib/echonest/reviews_result.rb +0 -12
  60. data/lib/echonest/reviews_results.rb +0 -15
  61. data/lib/echonest/similar_doc.rb +0 -13
  62. data/lib/echonest/similar_result.rb +0 -12
  63. data/lib/echonest/similar_results.rb +0 -11
  64. data/lib/echonest/urls_result.rb +0 -11
  65. data/lib/echonest/video_doc.rb +0 -14
  66. data/lib/echonest/video_result.rb +0 -12
  67. data/lib/echonest/video_results.rb +0 -15
  68. data/spec/echonest/search_spec.rb +0 -51
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class HotttnesssResult
5
+ include HappyMapper
6
+
7
+ tag :response
8
+
9
+ has_one :artist, ArtistDoc
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class NewsDoc
5
+ include HappyMapper
6
+
7
+ tag :doc
8
+
9
+ element :name, String
10
+ element :url, String
11
+ element :summary, String
12
+ element :date_found, String
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class NewsResult
5
+ include HappyMapper
6
+
7
+ tag :response
8
+
9
+ has_one :artist, ArtistDoc
10
+ has_one :results, NewsResults
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class NewsResults
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, NewsDoc
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class ProfileResult
5
+ include HappyMapper
6
+
7
+ tag :response
8
+
9
+ has_one :artist, ArtistDoc
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module EchoNest
3
+ module Xml
4
+ class ReviewsDoc
5
+ include HappyMapper
6
+
7
+ tag :doc
8
+
9
+ element :name, String
10
+ element :review_text, String
11
+ element :url, String
12
+ element :summary, String
13
+ element :date_found, String
14
+ end
15
+ end
16
+ end
@@ -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,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
@@ -1,27 +1,27 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe "Audio" do
4
4
 
5
5
  describe "#parse" do
6
6
 
7
7
  before(:each) do
8
- @xml = File.read(File.dirname(__FILE__) + "/../fixtures/audio/wavves.xml")
8
+ @xml = File.read(File.dirname(__FILE__) + "/../../fixtures/audio/wavves.xml")
9
9
  end
10
10
 
11
11
  it "should parse xml" do
12
- EchoNest::AudioResult.parse(@xml)
12
+ AudioResult.parse(@xml)
13
13
  end
14
14
 
15
15
  it "should have artist" do
16
- audio = EchoNest::AudioResult.parse(@xml)
17
- audio.artist.should be_kind_of(EchoNest::Artist)
16
+ audio = AudioResult.parse(@xml)
17
+ audio.artist.should be_kind_of(ArtistDoc)
18
18
  audio.artist.name.should == "Wavves"
19
19
  audio.artist.id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
20
20
  end
21
21
 
22
22
  it "should have results" do
23
- audio = EchoNest::AudioResult.parse(@xml)
24
- audio.results.should be_kind_of(EchoNest::AudioResults)
23
+ audio = AudioResult.parse(@xml)
24
+ audio.results.should be_kind_of(AudioResults)
25
25
  audio.results.found.should == "51"
26
26
  audio.results.shown.should == "15"
27
27
  audio.results.start.should == "0"
@@ -31,9 +31,9 @@ describe "Audio" do
31
31
 
32
32
  describe "result" do
33
33
  it "should be an AudioDoc" do
34
- audio = EchoNest::AudioResult.parse(@xml)
34
+ audio = AudioResult.parse(@xml)
35
35
  doc = audio.results.docs[0]
36
- doc.should be_kind_of(EchoNest::AudioDoc)
36
+ doc.should be_kind_of(AudioDoc)
37
37
  doc.artist_id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
38
38
  doc.artist.should == "Wavves"
39
39
  doc.release.should == "03/21/09 Austin TX"
@@ -1,27 +1,27 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
- describe "BlogResult" do
3
+ describe "BlogsResult" do
4
4
 
5
5
  describe "#parse" do
6
6
 
7
7
  before(:each) do
8
- @xml = File.read(File.dirname(__FILE__) + "/../fixtures/blog/radiohead.xml")
8
+ @xml = File.read(File.dirname(__FILE__) + "/../../fixtures/blog/radiohead.xml")
9
9
  end
10
10
 
11
11
  it "should parse xml" do
12
- EchoNest::BlogResult.parse(@xml)
12
+ BlogsResult.parse(@xml)
13
13
  end
14
14
 
15
15
  it "should have artist" do
16
- blog = EchoNest::BlogResult.parse(@xml)
17
- blog.artist.should be_kind_of(EchoNest::Artist)
16
+ blog = BlogsResult.parse(@xml)
17
+ blog.artist.should be_kind_of(ArtistDoc)
18
18
  blog.artist.name.should == "Radiohead"
19
19
  blog.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
20
20
  end
21
21
 
22
22
  it "should have results" do
23
- blog = EchoNest::BlogResult.parse(@xml)
24
- blog.results.should be_kind_of(EchoNest::BlogResults)
23
+ blog = BlogsResult.parse(@xml)
24
+ blog.results.should be_kind_of(BlogsResults)
25
25
  #TODO: Fill in these values as found in fixture
26
26
  blog.results.found.should == "131"
27
27
  blog.results.shown.should == "2"
@@ -32,9 +32,9 @@ describe "BlogResult" do
32
32
 
33
33
  describe "result" do
34
34
  it "should be an BlogDoc" do
35
- blog = EchoNest::BlogResult.parse(@xml)
35
+ blog = BlogsResult.parse(@xml)
36
36
  doc = blog.results.docs[0]
37
- doc.should be_kind_of(EchoNest::BlogDoc)
37
+ doc.should be_kind_of(BlogsDoc)
38
38
  #TODO: Create tests based on attributes in resource
39
39
  doc.name.should == "Radiohead live at Santa Barbara 28.8.08 « Misspeak Music"
40
40
  doc.url.should == "http://misspeakmusic.wordpress.com/2008/09/01/radiohead-live-at-santa-barbara-28808/"
@@ -1,27 +1,27 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe "FamiliarityResult" do
4
4
 
5
5
  describe "#parse" do
6
6
 
7
7
  before(:each) do
8
- @xml = File.read(File.dirname(__FILE__) + "/../fixtures/familiarity/radiohead.xml")
8
+ @xml = File.read(File.dirname(__FILE__) + "/../../fixtures/familiarity/radiohead.xml")
9
9
  end
10
10
 
11
11
  it "should parse xml" do
12
- EchoNest::FamiliarityResult.parse(@xml)
12
+ FamiliarityResult.parse(@xml)
13
13
  end
14
14
 
15
15
  it "should have artist" do
16
- familiarity = EchoNest::FamiliarityResult.parse(@xml)
17
- familiarity.artist.should be_kind_of(EchoNest::Artist)
16
+ familiarity = FamiliarityResult.parse(@xml)
17
+ familiarity.artist.should be_kind_of(ArtistDoc)
18
18
  familiarity.artist.name.should == "Radiohead"
19
19
  familiarity.artist.id.should == "music://id.echonest.com/~/AR/ARH6W4X1187B99274F"
20
20
  end
21
21
 
22
22
  it " artist should have familiarity" do
23
- familiarity = EchoNest::FamiliarityResult.parse(@xml)
24
- familiarity.artist.should be_kind_of(EchoNest::Artist)
23
+ familiarity = FamiliarityResult.parse(@xml)
24
+ familiarity.artist.should be_kind_of(ArtistDoc)
25
25
  familiarity.artist.familiarity.should_not be_nil
26
26
  familiarity.artist.familiarity.should == 0.96974159665
27
27
  end