remote_book 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
data/lib/remote_book.rb CHANGED
@@ -9,8 +9,6 @@ require "remote_book/amazon"
9
9
  require "remote_book/barnes_and_noble"
10
10
 
11
11
  module RemoteBook
12
- VERSION = File.read(File.dirname(__FILE__) + "/../VERSION").chomp
13
-
14
12
  def self.get_url(url, options = {:read_timeout => 2, :open_timeout => 2})
15
13
  uri = URI.parse(url)
16
14
 
@@ -1,22 +1,28 @@
1
1
  module RemoteBook
2
+ class AmazonError < RemoteBook::RemoteBookError #:nodoc:
3
+ end
4
+
2
5
  class Amazon < RemoteBook::Base
3
6
  # FIXME: failed digest support should raise exception.
4
7
  # mac os 10.5 does not ship with SHA256 support built into ruby, 10.6 does.
5
8
  DIGEST_SUPPORT = ::OpenSSL::Digest.constants.include?('SHA256') || ::OpenSSL::Digest.constants.include?(:SHA256)
6
9
  DIGEST = ::OpenSSL::Digest::Digest.new('sha256') if DIGEST_SUPPORT
7
10
 
8
- attr_accessor :large_image, :medium_image, :small_image, :authors, :title
11
+ attr_accessor :large_image, :medium_image, :small_image, :authors, :title, :raw_response
9
12
 
10
13
  def self.find(options)
14
+ raise AmazonError.new("RemoteBook::Amazon.associate_keys requires :key_id") unless associate_keys.has_key?(:key_id)
15
+ raise AmazonError.new("RemoteBook::Amazon.associate_keys requires :associates_id") unless associate_keys.has_key?(:associates_id)
16
+ raise AmazonError.new("RemoteBook::Amazon.associate_keys requires :secret_key") unless associate_keys.has_key?(:secret_key)
11
17
  a = new
12
18
  # unless DIGEST_SUPPORT raise "no digest sup"
13
19
  if options[:isbn]
14
20
  req = build_isbn_lookup_query(options[:isbn])
15
- response = RemoteBook.get_url(req)
21
+ a.raw_response = RemoteBook.get_url(req)
16
22
 
17
- if response.respond_to?(:code) && "200" == response.code
18
- xml_doc = Nokogiri.XML(response.body)
19
- else
23
+ if a.raw_response.respond_to?(:code) && "200" == a.raw_response.code
24
+ xml_doc = Nokogiri.XML(a.raw_response.body)
25
+ else
20
26
  return false
21
27
  end
22
28
 
@@ -28,7 +34,7 @@ module RemoteBook
28
34
  a.medium_image = xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:MediumImage/xmlns:URL").inner_text
29
35
  end
30
36
  if xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:SmallImage/xmlns:URL")
31
- a.small_image = xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:SmallImage/xmlns:URL")
37
+ a.small_image = xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:SmallImage/xmlns:URL").inner_text
32
38
  end
33
39
  a.title = xml_doc.xpath("//xmlns:Items/xmlns:Item/xmlns:ItemAttributes/xmlns:Title").inner_text
34
40
  a.authors = []
@@ -1,4 +1,7 @@
1
1
  module RemoteBook
2
+ class BarnesAndNobleError < RemoteBook::RemoteBookError #:nodoc:
3
+ end
4
+
2
5
  class BarnesAndNoble < RemoteBook::Base
3
6
  ISBN_SEARCH_BASE_URI = "http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?ISBSRC=Y&ISBN="
4
7
  LINK_SHARE_DEEP_LINK_BASE = "http://getdeeplink.linksynergy.com/createcustomlink.shtml"
@@ -28,4 +28,6 @@ module RemoteBook
28
28
  end
29
29
  end
30
30
  end
31
+ class RemoteBookError < StandardError #:nodoc:
32
+ end
31
33
  end
@@ -0,0 +1,3 @@
1
+ module RemoteBook
2
+ VERSION = File.read(File.dirname(__FILE__) + "/../../VERSION").chomp
3
+ end
data/remote_book.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "remote_book"
3
+ require "remote_book/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "remote_book"
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "https://github.com/sfaxon/remote_book"
11
11
  s.summary = %q{Pull book affiliate links and images from Amazon, Barns & Noble}
12
12
  s.description = %q{Pull book affiliate links and images from Amazon, Barns & Noble}
13
- s.date = %q{2011-08-21}
13
+ s.date = %q{2011-08-22}
14
14
 
15
15
  s.rubyforge_project = "remote_book"
16
16
 
@@ -10,6 +10,7 @@ describe RemoteBook::Amazon do
10
10
  FakeWeb.register_uri(:get, %r|http://ecs\.amazonaws\.com/(.*)|, :body => load_file("amazon_1433506254.xml"))
11
11
  a = RemoteBook::Amazon.find_by_isbn("1433506254")
12
12
  a.large_image.should == "http://ecx.images-amazon.com/images/I/41xMfBAsMnL.jpg"
13
+ a.medium_image.should == "http://ecx.images-amazon.com/images/I/41xMfBAsMnL._SL160_.jpg"
13
14
  end
14
15
 
15
16
  it "find_by_isbn should return false when error code returned by web service" do
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # in spec/support/ and its subdirectories.
3
3
  # Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
4
4
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
5
-
5
+ require 'remote_book'
6
6
  require 'fakeweb'
7
7
 
8
8
  RSpec.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_book
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-21 00:00:00.000000000Z
12
+ date: 2011-08-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70193812741460 !ruby/object:Gem::Requirement
16
+ requirement: &70156304442700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70193812741460
24
+ version_requirements: *70156304442700
25
25
  description: Pull book affiliate links and images from Amazon, Barns & Noble
26
26
  email:
27
27
  - seth.faxon@gmail.com
@@ -39,6 +39,7 @@ files:
39
39
  - lib/remote_book/amazon.rb
40
40
  - lib/remote_book/barnes_and_noble.rb
41
41
  - lib/remote_book/base.rb
42
+ - lib/remote_book/version.rb
42
43
  - remote_book.gemspec
43
44
  - spec/fixtures/amazon_1433506254.xml
44
45
  - spec/lib/amazon_spec.rb