Skip to content

Commit

Permalink
iTunes lookup API can return Array
Browse files Browse the repository at this point in the history
  • Loading branch information
bugcloud committed Jun 24, 2013
1 parent ad6358e commit 2be930f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/itunes-search-api.rb
Expand Up @@ -11,9 +11,7 @@ def search(query={})
end

def lookup(query={})
if results = get("/lookup", :query => query)["results"]
results[0]
end
get("/lookup", :query => query)["results"]
end
end
end
5 changes: 3 additions & 2 deletions spec/itunes-search-api_spec.rb
Expand Up @@ -37,13 +37,14 @@

it "should return nil if the lookup returns no results" do
stub_request(:get, LOOKUP_URL).with(:query => {:id => "284910350"}).to_return(:body => fixture("lookup-no-results.json"))
ITunesSearchAPI.lookup(:id => "284910350").should be_nil
ITunesSearchAPI.lookup(:id => "284910350").should be_empty
end

it "should return the result if the lookup returns a result" do
stub_request(:get, LOOKUP_URL).with(:query => {:id => "284910350"}).to_return(:body => fixture("lookup-result.json"))
result = ITunesSearchAPI.lookup(:id => "284910350")
result["artistName"].should == "Jack Johnson"
result.class.should eq(Array)
result.first["artistName"].should == "Jack Johnson"
end
end
end

0 comments on commit 2be930f

Please sign in to comment.