From 6248963662e938fb9274ecaec7a11ff97eed2ce7 Mon Sep 17 00:00:00 2001 From: Seth Faxon Date: Mon, 22 Aug 2011 11:58:08 -0700 Subject: [PATCH] adding error classes for better error messages --- lib/remote_book/amazon.rb | 6 ++++++ lib/remote_book/barnes_and_noble.rb | 3 +++ lib/remote_book/base.rb | 2 ++ 3 files changed, 11 insertions(+) diff --git a/lib/remote_book/amazon.rb b/lib/remote_book/amazon.rb index a65989a..f3aa3c4 100644 --- a/lib/remote_book/amazon.rb +++ b/lib/remote_book/amazon.rb @@ -1,4 +1,7 @@ module RemoteBook + class AmazonError < RemoteBook::RemoteBookError #:nodoc: + end + class Amazon < RemoteBook::Base # FIXME: failed digest support should raise exception. # mac os 10.5 does not ship with SHA256 support built into ruby, 10.6 does. @@ -8,6 +11,9 @@ class Amazon < RemoteBook::Base attr_accessor :large_image, :medium_image, :small_image, :authors, :title def self.find(options) + raise AmazonError.new("RemoteBook::Amazon.associate_keys requires :key_id") unless associate_keys.has_key?(:key_id) + raise AmazonError.new("RemoteBook::Amazon.associate_keys requires :associates_id") unless associate_keys.has_key?(:associates_id) + raise AmazonError.new("RemoteBook::Amazon.associate_keys requires :secret_key") unless associate_keys.has_key?(:secret_key) a = new # unless DIGEST_SUPPORT raise "no digest sup" if options[:isbn] diff --git a/lib/remote_book/barnes_and_noble.rb b/lib/remote_book/barnes_and_noble.rb index 129dece..4b21354 100644 --- a/lib/remote_book/barnes_and_noble.rb +++ b/lib/remote_book/barnes_and_noble.rb @@ -1,4 +1,7 @@ module RemoteBook + class BarnesAndNobleError < RemoteBook::RemoteBookError #:nodoc: + end + class BarnesAndNoble < RemoteBook::Base ISBN_SEARCH_BASE_URI = "http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?ISBSRC=Y&ISBN=" LINK_SHARE_DEEP_LINK_BASE = "http://getdeeplink.linksynergy.com/createcustomlink.shtml" diff --git a/lib/remote_book/base.rb b/lib/remote_book/base.rb index 1cf2b1b..9447e74 100644 --- a/lib/remote_book/base.rb +++ b/lib/remote_book/base.rb @@ -28,4 +28,6 @@ def find(options) end end end + class RemoteBookError < StandardError #:nodoc: + end end