gingerhendrix-echonest 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/VERSION.yml +2 -2
  2. data/generators/echonest_acceptance_test/USAGE +5 -0
  3. data/generators/echonest_acceptance_test/echonest_acceptance_test_generator.rb +50 -0
  4. data/generators/echonest_acceptance_test/templates/feature.erb +8 -0
  5. data/generators/echonest_model/USAGE +5 -0
  6. data/generators/echonest_model/echonest_model_generator.rb +52 -0
  7. data/generators/echonest_model/templates/doc.rb.erb +12 -0
  8. data/generators/echonest_model/templates/result.rb.erb +12 -0
  9. data/generators/echonest_model/templates/results.rb.erb +15 -0
  10. data/generators/echonest_resource/USAGE +5 -0
  11. data/generators/echonest_resource/echonest_resource_generator.rb +50 -0
  12. data/generators/echonest_unit_test/USAGE +5 -0
  13. data/generators/echonest_unit_test/echonest_unit_test_generator.rb +50 -0
  14. data/generators/echonest_unit_test/templates/unit_test.rb.erb +44 -0
  15. data/lib/echonest/api_request.rb +1 -1
  16. data/lib/echonest/artist.rb +52 -1
  17. data/lib/echonest/{audio.rb → audio_result.rb} +1 -1
  18. data/lib/echonest/blog_doc.rb +13 -0
  19. data/lib/echonest/blog_result.rb +12 -0
  20. data/lib/echonest/blog_results.rb +15 -0
  21. data/lib/echonest/familiarity_result.rb +11 -0
  22. data/lib/echonest/hotttnesss_result.rb +11 -0
  23. data/lib/echonest/news_doc.rb +13 -0
  24. data/lib/echonest/news_result.rb +12 -0
  25. data/lib/echonest/news_results.rb +15 -0
  26. data/lib/echonest/profile_result.rb +11 -0
  27. data/lib/echonest/reviews_doc.rb +15 -0
  28. data/lib/echonest/reviews_result.rb +12 -0
  29. data/lib/echonest/reviews_results.rb +15 -0
  30. data/lib/echonest/similar_doc.rb +13 -0
  31. data/lib/echonest/similar_result.rb +12 -0
  32. data/lib/echonest/similar_results.rb +11 -0
  33. data/lib/echonest/urls_result.rb +11 -0
  34. data/lib/echonest/video_doc.rb +14 -0
  35. data/lib/echonest/video_result.rb +12 -0
  36. data/lib/echonest/video_results.rb +15 -0
  37. data/lib/echonest.rb +25 -1
  38. data/spec/echonest/api_request_spec.rb +7 -0
  39. data/spec/echonest/{audio_spec.rb → audio_result_spec.rb} +4 -4
  40. data/spec/echonest/blog_result_spec.rb +48 -0
  41. data/spec/echonest/familiarity_result_spec.rb +33 -0
  42. data/spec/echonest/hotttness_result_spec.rb +31 -0
  43. data/spec/echonest/news_result_spec.rb +49 -0
  44. data/spec/echonest/profile_result_spec.rb +26 -0
  45. data/spec/echonest/reviews_result_spec.rb +49 -0
  46. data/spec/echonest/similar_result_spec.rb +35 -0
  47. data/spec/echonest/urls_result_spec.rb +38 -0
  48. data/spec/echonest/video_result_spec.rb +48 -0
  49. data/spec/fixtures/blog/radiohead.xml +32 -0
  50. data/spec/fixtures/familiarity/radiohead.xml +17 -0
  51. data/spec/fixtures/hotttnesss/radiohead.xml +17 -0
  52. data/spec/fixtures/news/radiohead.xml +32 -0
  53. data/spec/fixtures/profile/radiohead.xml +16 -0
  54. data/spec/fixtures/reviews/radiohead.xml +40 -0
  55. data/spec/fixtures/similar/radiohead.xml +31 -0
  56. data/spec/fixtures/urls/radiohead.xml +21 -0
  57. data/spec/fixtures/video/radiohead.xml +32 -0
  58. data/test/test_echonest_acceptance_test_generator.rb +52 -0
  59. data/test/test_echonest_model_generator.rb +47 -0
  60. data/test/test_echonest_resource_generator.rb +45 -0
  61. data/test/test_echonest_unit_test_generator.rb +35 -0
  62. data/test/test_generator_helper.rb +29 -0
  63. metadata +76 -7
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
4
- :patch: 1
3
+ :minor: 2
4
+ :patch: 0
@@ -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
@@ -18,7 +18,7 @@ module EchoNest
18
18
  private
19
19
 
20
20
  def query_string(options)
21
- options.keys.map { |key| "#{key.to_s}=#{options[key]}" }.join('&')
21
+ options.keys.map { |key| "#{key.to_s}=#{URI.encode(options[key].to_s)}" }.join('&')
22
22
  end
23
23
 
24
24
  end
@@ -9,11 +9,62 @@ module EchoNest
9
9
 
10
10
  element :name, String
11
11
  element :id, String
12
+ element :familiarity, Float
13
+ element :hotttnesss, Float
14
+ element :foreign_id, String
12
15
 
16
+ element :mb_url, String
17
+ element :official_url, String
18
+ element :myspace_url, String
19
+ element :wikipedia_url, String
20
+ element :amazon_url, String
21
+ element :itunes_url, String
22
+
23
+
13
24
  def get_audio
14
25
  request = ApiRequest.new("get_audio", {:id => id})
15
- Audio.parse request.fetch
26
+ AudioResult.parse request.fetch
27
+ end
28
+
29
+ def get_blogs
30
+ request = ApiRequest.new("get_audio", {:id => id})
31
+ BlogResult.parse request.fetch
32
+ end
33
+
34
+ def get_familiarity
35
+ request = ApiRequest.new("get_familiarity", {:id => id})
36
+ FamiliarityResult.parse request.fetch
37
+ end
38
+
39
+ def get_hotttnesss
40
+ request = ApiRequest.new("get_hotttnesss", {:id => id})
41
+ HotttnesssResult.parse request.fetch
42
+ end
43
+
44
+ def get_news
45
+ request = ApiRequest.new("get_news", {:id => id})
46
+ NewsResult.parse request.fetch
47
+ end
48
+
49
+ def get_profile
50
+ request = ApiRequest.new("get_profile", {:id => id})
51
+ ProfileResult.parse request.fetch
52
+ end
53
+
54
+ def get_similar
55
+ request = ApiRequest.new("get_similar", {:id => id})
56
+ SimilarResult.parse request.fetch
16
57
  end
17
58
 
59
+ def get_urls
60
+ request = ApiRequest.new("get_urls", {:id => id})
61
+ UrlsResult.parse request.fetch
62
+ end
63
+
64
+ def get_video
65
+ request = ApiRequest.new("get_video", {:id => id})
66
+ VideoResult.parse request.fetch
67
+ end
68
+
18
69
  end
19
70
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module EchoNest
3
- class Audio
3
+ class AudioResult
4
4
  include HappyMapper
5
5
 
6
6
  tag :response
@@ -0,0 +1,13 @@
1
+
2
+ module EchoNest
3
+ class BlogDoc
4
+ include HappyMapper
5
+
6
+ tag :doc
7
+
8
+ element :name, String
9
+ element :url, String
10
+ element :summary, String
11
+ element :date_found, String
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ class BlogResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+ has_one :results, BlogResults
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ class BlogResults
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, BlogDoc
13
+
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module EchoNest
3
+ class FamiliarityResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module EchoNest
3
+ class HotttnesssResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module EchoNest
3
+ class NewsDoc
4
+ include HappyMapper
5
+
6
+ tag :doc
7
+
8
+ element :name, String
9
+ element :url, String
10
+ element :summary, String
11
+ element :date_found, String
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ class NewsResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+ has_one :results, NewsResults
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ class NewsResults
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, NewsDoc
13
+
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module EchoNest
3
+ class ProfileResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ class ReviewsDoc
4
+ include HappyMapper
5
+
6
+ tag :doc
7
+
8
+ #TODO: Add document elements
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
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ class ReviewsResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+ has_one :results, ReviewsResults
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ class ReviewsResults
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, ReviewsDoc
13
+
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module EchoNest
3
+ class SimilarDoc
4
+ include HappyMapper
5
+
6
+ tag :artist
7
+
8
+ #TODO: Add document elements
9
+ element :name, String
10
+ element :id, String
11
+ element :rank, Integer
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ class SimilarResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+ has_one :results, SimilarResults
10
+
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module EchoNest
3
+ class SimilarResults
4
+ include HappyMapper
5
+
6
+ tag :similar
7
+
8
+ has_many :docs, SimilarDoc
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module EchoNest
3
+ class UrlsResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module EchoNest
3
+ class VideoDoc
4
+ include HappyMapper
5
+
6
+ tag :doc
7
+
8
+ #TODO: Add document elements
9
+ element :site, String
10
+ element :title, String
11
+ element :url, String
12
+ element :date_found, String
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ class VideoResult
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+ has_one :results, VideoResults
10
+
11
+ end
12
+ end