Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
View
6 lib/songkickr.rb
@@ -23,6 +23,12 @@ def to_s
end
end
+class ResouceNotFound < StandardError;
+ def to_s
+ "Resource not found"
+ end
+end
+
module Songkickr
# Returns the Songkick API key
# In order to use the Songkick API, you must have a Songkick API (their rule, not mine).
View
2  lib/songkickr/remote.rb
@@ -50,6 +50,7 @@ def events(query = {})
def event(event_id)
result = self.class.get("/events/#{event_id}.json")
# and now for some dirrty hack
+ raise ResouceNotFound if result['resultsPage']['error']
Songkickr::Event.new result["resultsPage"]["results"]["event"]
end
@@ -173,6 +174,7 @@ def location_search(query = {})
# * +venue_id+ - Songkick venue ID.
def venue(venue_id)
result = self.class.get("/venues/#{venue_id}.json")
+ raise ResouceNotFound if result['resultsPage']['error']
Songkickr::Venue.new result['resultsPage']['results']['venue']
end
View
1  test/fixtures/resource_not_found.json
@@ -0,0 +1 @@
+{"resultsPage" : {"status" : "error", "error" : {"message" : "Resource not found"}}}
View
22 test/songkickr/test_remote.rb
@@ -8,7 +8,27 @@ class TestRemote < Test::Unit::TestCase
end
end
end
-
+
+ context "Given an invalid Resource" do
+ setup do
+ FakeWeb.register_uri(:get, 'http://api.songkick.com/api/3.0/events/123.json?apikey=omgwtfbbq_fake_key', :body => fixture_file('resource_not_found.json'))
+ FakeWeb.register_uri(:get, 'http://api.songkick.com/api/3.0/venues/123.json?apikey=omgwtfbbq_fake_key', :body => fixture_file('resource_not_found.json'))
+ @remote = Songkickr::Remote.new 'omgwtfbbq_fake_key'
+ end
+
+ should "raise an ResouceNotFound exception when search a songkick event id doesn't exist" do
+ assert_raise ResouceNotFound do
+ @remote.event(123)
+ end
+ end
+
+ should "raise an ResouceNotFound exception when search a songkick venue id doesn't exist" do
+ assert_raise ResouceNotFound do
+ @remote.venue(123)
+ end
+ end
+ end
+
# TODO: Fix this later
context "Given a remote with an invalid api key" do
setup do

No commit comments for this range

Something went wrong with that request. Please try again.