gingerhendrix-echonest 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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.
data/README.rdoc ADDED
@@ -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.
data/Rakefile ADDED
@@ -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
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 0
@@ -0,0 +1,26 @@
1
+
2
+ module EchoNest
3
+ class ApiRequest
4
+
5
+ def initialize(resource, options)
6
+ @options = {:version =>3, :api_key => EchoNest.api_key}.merge(options)
7
+ @resource = resource
8
+ end
9
+
10
+ def uri
11
+ "http://developer.echonest.com/api/#{@resource}?#{query_string(@options)}"
12
+ end
13
+
14
+ def fetch
15
+ open(uri).read
16
+ end
17
+
18
+ private
19
+
20
+ def query_string(options)
21
+ options.keys.map { |key| "#{key.to_s}=#{options[key]}" }.join('&')
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,19 @@
1
+
2
+ module EchoNest
3
+ class Artist
4
+ include HappyMapper
5
+
6
+ def initialize(id=nil)
7
+ @id = id if id
8
+ end
9
+
10
+ element :name, String
11
+ element :id, String
12
+
13
+ def get_audio
14
+ request = ApiRequest.new("get_audio", {:id => id})
15
+ Audio.parse request.fetch
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+
2
+ module EchoNest
3
+ class ArtistSearch
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ # has_one :status, RequestStatus
9
+ # has_one :query, RequestQuery
10
+ has_many :artists, Artist
11
+
12
+ def self.search(query)
13
+ request = ApiRequest.new("search_artists", {:query => query})
14
+ parse(request.fetch)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module EchoNest
3
+ class Audio
4
+ include HappyMapper
5
+
6
+ tag :response
7
+
8
+ has_one :artist, Artist
9
+ has_one :results, AudioResults
10
+
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+
2
+ module EchoNest
3
+ class AudioDoc
4
+ include HappyMapper
5
+
6
+ tag :doc
7
+
8
+ element :artist_id, String
9
+ element :foreign_artist_id, String
10
+ element :artist, String
11
+ element :release, String
12
+ element :title, String
13
+ element :url, String
14
+ element :link, String
15
+ element :date, String
16
+ element :length, String
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module EchoNest
3
+ class AudioResults
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, AudioDoc
13
+
14
+ end
15
+ end
data/lib/echonest.rb ADDED
@@ -0,0 +1,22 @@
1
+
2
+ require 'happymapper'
3
+ require 'open-uri'
4
+
5
+ module EchoNest
6
+ def self.api_key=(api_key)
7
+ @api_key = api_key
8
+ end
9
+
10
+ def self.api_key
11
+ @api_key
12
+ end
13
+
14
+ end
15
+
16
+ require "echonest/api_request.rb"
17
+ require "echonest/artist.rb"
18
+ require "echonest/artist_search.rb"
19
+ require "echonest/audio_doc.rb"
20
+ require "echonest/audio_results.rb"
21
+ require "echonest/audio.rb"
22
+
@@ -0,0 +1,10 @@
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
+ it { EchoNest::ApiRequest.new("artist_search", :query => "Wavves").uri.should == "http://developer.echonest.com/api/artist_search?query=Wavves&api_key=API_KEY&version=3" }
9
+
10
+ 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
+ EchoNest::Audio.parse(@xml)
13
+ end
14
+
15
+ it "should have artist" do
16
+ audio = EchoNest::Audio.parse(@xml)
17
+ audio.artist.should be_kind_of(EchoNest::Artist)
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 = EchoNest::Audio.parse(@xml)
24
+ audio.results.should be_kind_of(EchoNest::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 = EchoNest::Audio.parse(@xml)
35
+ doc = audio.results.docs[0]
36
+ doc.should be_kind_of(EchoNest::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,51 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "ArtistSearch" do
4
+
5
+ describe "#search" do
6
+ before(:each) do
7
+ @mock_request = mock "Request"
8
+ @mock_request.stub!(:fetch)
9
+ EchoNest::ApiRequest.stub!(:new).and_return(@mock_request)
10
+ EchoNest::ArtistSearch.stub!(:parse)
11
+ end
12
+
13
+ it "should create a new ApiRequest with resource 'search_artists' and :query => query" do
14
+ EchoNest::ApiRequest.should_receive(:new).with('search_artists', :query=> "QUERY").and_return(@mock_request)
15
+ EchoNest::ArtistSearch.search("QUERY")
16
+ end
17
+
18
+ it "should call fetch on the api request" do
19
+ @mock_request.should_receive(:fetch)
20
+ EchoNest::ArtistSearch.search("QUERY")
21
+ end
22
+
23
+ it "should call parse on the results of fetch" do
24
+ @mock_request.stub!(:fetch).and_return("RESULT")
25
+ EchoNest::ArtistSearch.should_receive(:parse).with("RESULT").and_return("search_result")
26
+ EchoNest::ArtistSearch.search("QUERY").should == "search_result"
27
+ end
28
+
29
+ end
30
+
31
+ describe "#parse" do
32
+
33
+ before(:each) do
34
+ @xml = File.read(File.dirname(__FILE__) + "/../fixtures/search_artists/wavves.xml")
35
+ end
36
+
37
+ it "should parse xml" do
38
+ EchoNest::ArtistSearch.parse(@xml)
39
+ end
40
+
41
+ it "should have list of artists" do
42
+ search = EchoNest::ArtistSearch.parse(@xml)
43
+ search.artists.should be_kind_of(Array)
44
+ search.artists[0].should be_kind_of(EchoNest::Artist)
45
+ search.artists[0].name.should == "Wavves"
46
+ search.artists[0].id.should == "music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB"
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <response version="3"><status><code>0</code><message>Success</message></status><query><parameter name="api_key">CREDOYO7GFJ9OW3TV</parameter><parameter name="id">music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</parameter><parameter name="start">0</parameter><parameter name="rows">15</parameter><parameter name="format">xml</parameter></query><artist><name>Wavves</name><id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</id></artist><results found="51" shown="15" start="0"><doc id="67ae7bcb306c04dc933c158517366efc" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>03/21/09 Austin TX</release><title>So Bored (LIVE SXSW 2009)</title><url>http://www.2groundcontrol.com/IMAGENS/songs/03%20So%20Bored%20%28LIVE%20SXSW%202009%29.mp3</url><link>http://2groundcontrol.blogspot.com</link><length>265.0</length></doc><doc id="fcd91b8da229449ea4fa6931788b94e9" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>Wavvves</release><title>So Bored</title><url>http://www.minneapolisfuckingrocks.com/mp3/wavves_sobored1.mp3</url><link>http://minneapolisfuckingrocks.blogspot.com</link><length>193.0</length></doc><doc id="d69d000d7bd6adb494dbc4fb2ef29088" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>Wavvves</release><title>So Bored</title><url>http://www.yooglimusic.com/blog/wp-content/uploads/2009/04/06-so-bored.mp3</url><link>http://www.yooglimusic.com/blog/</link><length>193.0</length></doc><doc id="8930d130dc079588a728b1788ccad9ed" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>Wavves</release><title>So Bored</title><url>http://www.catbirdseat.org/catbirdseat/wavves-sobored.mp3</url><link>http://stereopaste.blogspot.com/2009/02/wavves.html</link><length>193.0</length></doc><doc id="31fa8b7067b241dd055b21c59b7ac3f9" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>Wavves</release><title>Teenage Super Party</title><url>http://livingears.com/music/Wavves/Teenage%20Super%20Party.mp3</url><link>http://livingears.blogspot.com/2009/02/wavves.html</link><length>101.0</length></doc><doc id="28348f549b4e712ead63703241293003" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>Wavvves</release><title>Surf Goth</title><url>http://prettygoeswithpretty.typepad.com/files/09-surf-goth.mp3</url><link>http://prettygoeswithpretty.typepad.com/pgwp/</link><length>126.0</length></doc><doc id="5f991a5090c0a215b7a3ffcd26437cdd" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>Wavvves</release><title>So Bored</title><url>http://www.thankscaptainobvious-mp3.net/06%20So%20Bored.mp3</url><link>http://www.thankscaptainobvious.net</link><length>193.0</length></doc><doc id="75ff3d8cf10786cf2a3e0ecca73b5e62" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>Wavvves</release><title>So Bored (new)</title><url>http://auralstates.com/Music/wavvessobored.mp3</url><link>http://auralstates.com/</link><length>193.0</length></doc><doc id="e9982eda02973eeccc14be3817c6d65b" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>SXSW 2009</release><title>So Bored</title><url>http://www.acertainromance.com/files/sxsw2009/Wavves_SoBored.mp3</url><link>http://www.acertainromance.com</link><length>193.0</length></doc><doc id="992030536bab5402bd3c92bf5ecc344b" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>03/21/09 Austin TX</release><title>Wavves</title><url>http://lullabyes.net/mp3/090320%20Wavves%20Austin%20TX%2005%20Wavves.mp3</url><link>http://www.lullabyes.net/blog/</link><length>198.0</length></doc><doc id="3c7e8a47725fc42abf79e6a54207c3eb" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>03/21/09 Austin TX</release><title>Satan Tried to Stop Me</title><url>http://lullabyes.net/mp3/090320%20Wavves%20Austin%20TX%2004%20Satan%20Tried%20to%20Stop%20Me.mp3</url><link>http://www.lullabyes.net/blog/</link><length>216.0</length></doc><doc id="9041a46be397081955e61b94cf67340e" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>03/21/09 Austin TX</release><title>To The Dregs</title><url>http://lullabyes.net/mp3/090320%20Wavves%20Austin%20TX%2002%20To%20The%20Dregs.mp3</url><link>http://www.lullabyes.net/blog/</link><length>220.0</length></doc><doc id="45c83c8dfd36a8de4bf70b5b3d45e507" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>03/21/09 Austin TX</release><title>So Bored</title><url>http://lullabyes.net/mp3/090320%20Wavves%20Austin%20TX%2003%20So%20Bored.mp3</url><link>http://www.lullabyes.net/blog/</link><length>265.0</length></doc><doc id="28a8ebed7733eab36bb5eaaed4433592" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>Wavves</artist><release>03/21/09 Austin TX</release><title>Intro</title><url>http://lullabyes.net/mp3/090320%20Wavves%20Austin%20TX%2001%20Intro.mp3</url><link>http://www.lullabyes.net/blog/</link><length>27.0</length></doc><doc id="bf11fe9e6c862060d41f4f41f70d06ac" type="audio"><artist_id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</artist_id><artist>WAVVES</artist><release>WAVVVES (ALBUM)</release><title>So Bored</title><url>http://fakepennycomics.com/blog/WAVV_SoBored.mp3</url><link>http://pastaprima.net</link><length>193.0</length></doc></results></response>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <response version="3"><status><code>0</code><message>Success</message></status><query><parameter name="api_key">CREDOYO7GFJ9OW3TV</parameter><parameter name="query">wavves</parameter><parameter name="sounds_like">Y</parameter><parameter name="exact">N</parameter></query><artists><artist><id>music://id.echonest.com/~/AR/ARVVZQP11E2835DBCB</id><name>Wavves</name></artist></artists></response>
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'echonest'
7
+ #require 'fakeweb'
8
+
9
+ #FakeWeb.allow_net_connect = false
10
+
11
+ Spec::Runner.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gingerhendrix-echonest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gareth Andrew
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-22 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: gingerhendrix@hotmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION.yml
30
+ - lib/echonest.rb
31
+ - lib/echonest/api_request.rb
32
+ - lib/echonest/artist.rb
33
+ - lib/echonest/artist_search.rb
34
+ - lib/echonest/audio.rb
35
+ - lib/echonest/audio_doc.rb
36
+ - lib/echonest/audio_results.rb
37
+ - spec/echonest/api_request_test.rb
38
+ - spec/echonest/audio_test.rb
39
+ - spec/echonest/search_test.rb
40
+ - spec/fixtures/audio/wavves.xml
41
+ - spec/fixtures/search_artists/wavves.xml
42
+ - spec/spec_helper.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/gingerhendrix/echonest
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: A ruby ribrary for accessing the echonest api
69
+ test_files:
70
+ - spec/spec_helper.rb
71
+ - spec/echonest/search_test.rb
72
+ - spec/echonest/api_request_test.rb
73
+ - spec/echonest/audio_test.rb