Class: RemoteBook::Amazon
Constant Summary collapse
- DIGEST_SUPPORT =
FIXME: failed digest support should raise exception. mac os 10.5 does not ship with SHA256 support built into ruby, 10.6 does.
::OpenSSL::Digest.constants.include?('SHA256') || ::OpenSSL::Digest.constants.include?(:SHA256)
- DIGEST =
::OpenSSL::Digest::Digest.new('sha256')
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#large_image ⇒ Object
Returns the value of attribute large_image.
-
#medium_image ⇒ Object
Returns the value of attribute medium_image.
-
#raw_response ⇒ Object
Returns the value of attribute raw_response.
-
#small_image ⇒ Object
Returns the value of attribute small_image.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from Base
Class Method Summary collapse
Methods inherited from Base
associate_keys, associate_keys=, #author, find_by_isbn, setup
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
11 12 13 |
# File 'lib/remote_book/amazon.rb', line 11 def @authors end |
#large_image ⇒ Object
Returns the value of attribute large_image.
11 12 13 |
# File 'lib/remote_book/amazon.rb', line 11 def large_image @large_image end |
#medium_image ⇒ Object
Returns the value of attribute medium_image.
11 12 13 |
# File 'lib/remote_book/amazon.rb', line 11 def medium_image @medium_image end |
#raw_response ⇒ Object
Returns the value of attribute raw_response.
11 12 13 |
# File 'lib/remote_book/amazon.rb', line 11 def raw_response @raw_response end |
#small_image ⇒ Object
Returns the value of attribute small_image.
11 12 13 |
# File 'lib/remote_book/amazon.rb', line 11 def small_image @small_image end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/remote_book/amazon.rb', line 11 def title @title end |
Class Method Details
.find(options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/remote_book/amazon.rb', line 13 def self.find() 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 [:isbn] req = build_isbn_lookup_query([:isbn]) a.raw_response = RemoteBook.get_url(req) if a.raw_response.respond_to?(:code) && "200" == a.raw_response.code xml_doc = Nokogiri.XML(a.raw_response.body) else return false end if 1 == xml_doc.xpath("//xmlns:Items").size if xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:LargeImage/xmlns:URL") a.large_image = xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:LargeImage/xmlns:URL").inner_text end if xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:MediumImage/xmlns:URL") a.medium_image = xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:MediumImage/xmlns:URL").inner_text end if xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:SmallImage/xmlns:URL") a.small_image = xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:SmallImage/xmlns:URL").inner_text end a.title = xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:ItemAttributes/xmlns:Title").inner_text a. = [] xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:ItemAttributes/xmlns:Author").each do || a. << .inner_text end # ewww if xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:ItemLinks/xmlns:ItemLink/xmlns:Description='Technical Details'") xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:ItemLinks/xmlns:ItemLink").each do |item_link| if "Technical Details" == item_link.xpath("xmlns:Description").inner_text a.link = item_link.xpath("xmlns:URL").inner_text end end end end end return a end |