Skip to content
Browse files

Passing features and specs. Added example script

  • Loading branch information...
1 parent c766905 commit 443354150b6cd1eabbe86139a5b80f91fc9449a6 @gingerhendrix committed Aug 2, 2009
View
13 TODO
@@ -1,8 +1,17 @@
@milestone Basic artist methods +done
@milestone Improve API, documentation and implement missing features
@iteration Fluent Api +done
- @iteration Paging
- Create a nice interface for paged results (urls, videos, blogs, audio etc).
+ @iteration Paging +done
+ Create a nice interface for paged results (urls, videos, blogs, audio etc). +done
@iteration Docs
README
Website
+@milestone improvements
+ PagedResult could be better
+ next_page should return array-alike 'Page'
+ next_page should accept arguments (pageNumber, start, pageSize)
+ PagedResult should have available method detailing available indices
+ Better error handling
+ should have custom exception types for echonest errors eg. InvalidApiKey
+@milestone remix api
+ Should support the remix api
View
33 examples/artist_audio.rb
@@ -0,0 +1,33 @@
+
+require 'rubygems'
+
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+require 'echonest'
+require 'highline'
+
+include EchoNest
+
+EchoNest.api_key = "CREDOYO7GFJ9OW3TV"
+
+HighLine.track_eof = false
+highline = HighLine.new
+
+artist_name = highline.ask "Please type an artist name? "
+artist_search = Artist.find artist_name
+search_names = artist_search.map(&:name)
+highline.say "Found #{search_names.length}"
+choice = highline.choose do |menu|
+ menu.select_by = :index
+ menu.choices(*search_names)
+end
+idx = search_names.index choice
+highline.say "Finding audio for #{artist_search[idx].name} - #{artist_search[idx].id}"
+artist = Artist.new artist_search[idx].id
+audio = artist.audio
+highline.say "Found #{audio.found}, retrieved #{audio.length}"
+highline.say highline.list( audio.map(&:title) )
+while highline.agree "Next?"
+ audio.next_page
+ highline.say highline.list( audio.map(&:title) )
+end
+
View
2 features/fluent/artist_audio.feature
@@ -10,4 +10,4 @@ Feature: Artist audio
And a result should have a release
And a result should have a title
And a later result should have a url
-
+ And a later result should not have the same url as the first url
View
2 features/fluent/artist_search.feature
@@ -4,6 +4,6 @@ Feature: Artist search
Scenario: Artist search
When I search for "Wavves"
- Then I should get some results
+ Then I should get some unpaged results
And a result should have a id
And a result should have a name
View
9 features/fluent/step_definitions/fluent_steps.rb
@@ -10,7 +10,12 @@
end
end
+
Then /^I should get some results$/ do
+ Then "I should get some paged results"
+end
+
+Then /^I should get some unpaged results$/ do
@result.should_not be_nil
@result.should be_kind_of(Array)
@result.length.should_not == 0
@@ -28,7 +33,9 @@
@later_result.send(prop.to_sym).should_not be_nil
end
-
+Then /^a later result should not have the same url as the first url$/ do
+ @later_result.url.should_not == @result[0].url
+end
Then /^I should get a numeric result$/ do
@result.should_not be_nil
View
14 lib/echonest/artist.rb
@@ -9,8 +9,10 @@ def initialize(id=nil)
def self.service(name, options = {})
- define_method "get_#{name.to_s}" do
- request = ApiRequest.new("get_#{name.to_s}", {:id => id})
+ define_method "get_#{name.to_s}" do |*args|
+ options = args[0] if args.length == 1
+ options = {:id => id}.merge(options)
+ request = ApiRequest.new("get_#{name.to_s}", options)
"Xml::#{name.to_s.titleize}Result".constantize.parse request.fetch
end
@@ -49,9 +51,11 @@ def self.service(name, options = {})
end
end
- def self.find(query)
- request = ApiRequest.new("search_artists", {:query => query})
- Xml::ArtistSearchResults.parse(request.fetch).artists
+ def self.find(query, options={})
+ options = {:query => query}.merge(options)
+ request = ApiRequest.new("search_artists", options)
+ results = Xml::ArtistSearchResults.parse(request.fetch)
+ results.artists
end
service :audio
View
7 lib/echonest/paged_result.rb
@@ -4,10 +4,11 @@
module EchoNest
class PagedResult < DelegateClass(Array)
- def initialize(results, block)
+ def initialize(results, block, options={})
@results = results
@update = block
- @available = @results.docs
+ @page_name = options[:page] || :docs
+ @available = @results.send(@page_name)
super(@available)
end
@@ -17,7 +18,7 @@ def found
def next_page
results = @update.call @available.length, 15
- @available += results.docs
+ @available += results.send(@page_name)
self.__setobj__(@available)
end
View
3 lib/echonest/xml/similar_results.rb
@@ -5,6 +5,9 @@ class SimilarResults
include HappyMapper
tag :similar
+ def found
+ -1
+ end
has_many :docs, SimilarDoc

0 comments on commit 4433541

Please sign in to comment.
Something went wrong with that request. Please try again.