googlebook 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in googlebooks.gemspec
1
+ source 'http://rubygems.org'
4
2
  gemspec
@@ -1,37 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- googlebook (0.0.1)
5
- httparty (~> 0.6.1)
4
+ googlebook (0.1.0)
5
+ httparty (~> 0.7.4)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- addressable (2.2.2)
10
+ addressable (2.2.4)
11
11
  crack (0.1.8)
12
12
  diff-lcs (1.1.2)
13
- httparty (0.6.1)
13
+ httparty (0.7.4)
14
14
  crack (= 0.1.8)
15
- json (1.4.6)
16
- rdiscount (1.6.5)
17
- rdoc (2.4.3)
18
- rspec (2.0.1)
19
- rspec-core (~> 2.0.1)
20
- rspec-expectations (~> 2.0.1)
21
- rspec-mocks (~> 2.0.1)
22
- rspec-core (2.0.1)
23
- rspec-expectations (2.0.1)
24
- diff-lcs (>= 1.1.2)
25
- rspec-mocks (2.0.1)
26
- rspec-core (~> 2.0.1)
27
- rspec-expectations (~> 2.0.1)
28
- sdoc (0.2.20)
29
- json (>= 1.1.3)
30
- rdoc (= 2.4.3)
31
- sdoc-helpers (0.1.4)
32
- sdoc (~> 0.2)
33
- vcr (1.2.0)
34
- webmock (1.4.0)
15
+ rspec (2.5.0)
16
+ rspec-core (~> 2.5.0)
17
+ rspec-expectations (~> 2.5.0)
18
+ rspec-mocks (~> 2.5.0)
19
+ rspec-core (2.5.1)
20
+ rspec-expectations (2.5.0)
21
+ diff-lcs (~> 1.1.2)
22
+ rspec-mocks (2.5.0)
23
+ vcr (1.7.0)
24
+ webmock (1.6.2)
35
25
  addressable (>= 2.2.2)
36
26
  crack (>= 0.1.7)
37
27
 
@@ -40,9 +30,6 @@ PLATFORMS
40
30
 
41
31
  DEPENDENCIES
42
32
  googlebook!
43
- httparty (~> 0.6.1)
44
- rdiscount (~> 1.6.5)
45
- rspec (~> 2.0.1)
46
- sdoc-helpers (~> 0.1.4)
47
- vcr (~> 1.2.0)
48
- webmock (~> 1.4.0)
33
+ rspec (~> 2.5.0)
34
+ vcr (~> 1.7.0)
35
+ webmock (~> 1.6.2)
data/LICENSE CHANGED
@@ -1,22 +1,13 @@
1
- (The MIT License)
2
-
3
- Copyright (c) 2010 Paper Cavalier
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- 'Software'), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/README.md CHANGED
@@ -1,16 +1,4 @@
1
1
  Google Book
2
2
  ===========
3
3
 
4
- Google Book is a work-in-progress Ruby class in tight embrace with the [Google Book Search Data API](http://code.google.com/apis/books/docs/gdata/developers_guide_protocol.html).
5
-
6
- books = GoogleBook.find('deleuze')
7
-
8
- book = books.first
9
- book.title
10
- => "Foucault"
11
- book.isbn
12
- => "9780826490780"
13
-
14
- Paginate through the result set, sort of.
15
-
16
- GoogleBook.find('deleuze', :page => 2, :count => 20)
4
+ Google Book is a Ruby wrapper to the [Google Book Search Data API](http://code.google.com/apis/books/docs/gdata/developers_guide_protocol.html).
data/Rakefile CHANGED
@@ -1,12 +1,11 @@
1
- require "bundler"
2
- require "rspec/core/rake_task"
3
- require "sdoc_helpers"
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
4
3
 
5
4
  Bundler::GemHelper.install_tasks
6
5
 
7
- desc "Run all specs in spec directory"
6
+ desc 'Run all specs in spec directory'
8
7
  RSpec::Core::RakeTask.new(:spec) do |spec|
9
- spec.pattern = "spec/**/*_spec.rb"
8
+ spec.pattern = 'spec/**/*_spec.rb'
10
9
  end
11
10
 
12
11
  task :default => :spec
@@ -1,28 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "googlebook/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'googlebook/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "googlebook"
6
+ s.name = 'googlebook'
7
7
  s.version = GoogleBook::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Hakan Ensari"]
10
- s.email = ["hakan.ensari@papercavalier.com"]
11
- s.homepage = "http://gloss.papercavalier.com/googlebook"
12
- s.summary = %q{A Ruby class in tight embrace with the Google Book Search Data API}
13
- s.description = %q{Google Book is a Ruby class in tight embrace with the Google Book Search Data API.}
9
+ s.authors = ['Paper Cavalier']
10
+ s.email = ['code@papercavalier.com']
11
+ s.homepage = 'http://rubygems.com/gems/googlebook'
12
+ s.summary = %q{A Ruby wrapper to the Google Book Search Data API}
13
+ s.description = %q{Google Book is a Ruby wrapper to the Google Book Search Data API.}
14
14
 
15
- s.rubyforge_project = "googlebook"
15
+ s.rubyforge_project = 'googlebook'
16
16
 
17
- s.add_dependency("httparty", ["~> 0.6.1"])
18
- s.add_development_dependency("rdiscount", "~> 1.6.5")
19
- s.add_development_dependency("rspec", ["~> 2.0.1"])
20
- s.add_development_dependency("sdoc-helpers", "~> 0.1.4")
21
- s.add_development_dependency("vcr", "~> 1.2.0")
22
- s.add_development_dependency("webmock", "~> 1.4.0")
17
+ s.add_dependency('httparty', ['~> 0.7.4'])
18
+ s.add_development_dependency('rspec', ['~> 2.5.0'])
19
+ s.add_development_dependency('vcr', '~> 1.7.0')
20
+ s.add_development_dependency('webmock', '~> 1.6.2')
23
21
 
24
22
  s.files = `git ls-files`.split("\n")
25
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
- s.require_paths = ["lib"]
25
+ s.require_paths = ['lib']
28
26
  end
@@ -1,24 +1,3 @@
1
- require File.dirname(__FILE__) + '/googlebook/finder'
2
-
3
- # A Ruby class in tight embrace with the Google Book Search Data API
4
- class GoogleBook
5
- attr_accessor :thumbnail,
6
- :info,
7
- :preview,
8
- :creator,
9
- :date,
10
- :description,
11
- :format,
12
- :identifier,
13
- :publisher,
14
- :subject,
15
- :title
16
-
17
- def initialize(args={})
18
- args.each { |k, v| self.send "#{k}=", v }
19
- end
20
-
21
- def isbn
22
- identifier.detect { |i| i.match(/ISBN:([0-9]{13})/) }; $1
23
- end
24
- end
1
+ require 'googlebook/book'
2
+ require 'googlebook/finder'
3
+ require 'googlebook/images'
@@ -0,0 +1,29 @@
1
+ module GoogleBook
2
+ class Book < Struct.new :images,
3
+ :info,
4
+ :preview,
5
+ :creator,
6
+ :date,
7
+ :description,
8
+ :format,
9
+ :identifier,
10
+ :publisher,
11
+ :subject,
12
+ :title
13
+
14
+ def initialize(args={})
15
+ args.each { |k, v| self.send "#{k}=", v }
16
+ end
17
+
18
+ def isbn
19
+ @isbn ||= find_isbn
20
+ end
21
+
22
+ private
23
+
24
+ def find_isbn
25
+ identifier.detect { |i| i.match(/ISBN:([0-9]{13})/) }
26
+ $1
27
+ end
28
+ end
29
+ end
@@ -2,26 +2,30 @@ require 'cgi'
2
2
  require 'httparty'
3
3
 
4
4
  # A classy finder
5
- class GoogleBook
5
+ module GoogleBook
6
6
  include HTTParty
7
7
  format :xml
8
8
 
9
9
  class << self
10
+
10
11
  # Query parameters passed on to Google
11
12
  attr_accessor :parameters
12
13
 
13
- # Total results for last query
14
+ # Total results for query
14
15
  attr_accessor :total_results
15
16
 
16
- # Queries the Google Book Search Data API
17
+ # The query response
18
+ attr_accessor :response
19
+
20
+ # Queries the Google Book Search Data API.
17
21
  #
18
- # Optionally, specify a page and count to (sort-of) paginate through
22
+ # Optionally, specify a page and count to paginate through
19
23
  # the result set.
20
24
  #
21
25
  # GoogleBook.find('deleuze', :page => 2, :count => 20)
22
26
  #
23
27
  def find(query, opts={})
24
- self.parameters = { 'q' => query }
28
+ self.parameters = { 'q' => query }
25
29
 
26
30
  if opts[:page] && opts[:page].to_i > 0
27
31
  parameters['start-index'] = opts[:page]
@@ -31,20 +35,23 @@ class GoogleBook
31
35
  parameters['max-results'] = opts[:count]
32
36
  end
33
37
 
34
- response = self.get(uri.to_s)
38
+ self.response = self.get(uri.to_s)
39
+
35
40
  self.total_results = response['feed']['openSearch:totalResults'].to_i
41
+
36
42
  response['feed']['entry'].map do |book|
37
- new :thumbnail => book['link'][0]['href'],
38
- :info => book['link'][1]['href'],
39
- :preview => book['link'][2]['href'],
40
- :creator => book['dc:creator'],
41
- :date => book['dc:date'],
42
- :description => book['dc:description'],
43
- :format => book['dc:format'],
44
- :identifier => book['dc:identifier'],
45
- :publisher => book['dc:publisher'],
46
- :subject => book['dc:subject'],
47
- :title => book['dc:title']
43
+ Book.new(
44
+ :images => Images.new(book['link'][0]['href']),
45
+ :info => book['link'][1]['href'],
46
+ :preview => book['link'][2]['href'],
47
+ :creator => book['dc:creator'],
48
+ :date => book['dc:date'],
49
+ :description => book['dc:description'],
50
+ :format => book['dc:format'],
51
+ :identifier => book['dc:identifier'],
52
+ :publisher => book['dc:publisher'],
53
+ :subject => book['dc:subject'],
54
+ :title => book['dc:title'])
48
55
  end
49
56
  end
50
57
 
@@ -0,0 +1,30 @@
1
+ module GoogleBook
2
+ class Images
3
+ attr_accessor :url
4
+ def initialize(url)
5
+ self.url = url
6
+ end
7
+
8
+ def thumbnail
9
+ url
10
+ end
11
+
12
+ def small
13
+ zoom(1)
14
+ end
15
+
16
+ def medium
17
+ zoom(2)
18
+ end
19
+
20
+ def large
21
+ zoom(3)
22
+ end
23
+
24
+ private
25
+
26
+ def zoom(level)
27
+ url.gsub('zoom=5', "zoom=#{level}")
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
- class GoogleBook
2
- VERSION = "0.0.1"
1
+ module GoogleBook
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module GoogleBook
4
+ describe Book do
5
+ use_vcr_cassette 'googlebook'
6
+
7
+ subject { GoogleBook.find('deleuze').first }
8
+
9
+ %w{images info preview creator date description format
10
+ identifier isbn publisher subject title}.each do |attribute|
11
+ its(attribute) { should_not be_nil }
12
+ end
13
+
14
+ context "images" do
15
+ subject { GoogleBook.find('deleuze').first.images }
16
+
17
+ %w{thumbnail small medium large}.each do |attribute|
18
+ its(attribute) { should_not be_nil }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe GoogleBook do
4
- use_vcr_cassette 'googlebook', :record => :new_episodes
3
+ module GoogleBook
4
+ describe "Finder module" do
5
+ use_vcr_cassette 'googlebook'
5
6
 
6
- context "Finder" do
7
7
  it "should escape parameters" do
8
8
  GoogleBook.find('foo bar')
9
9
  GoogleBook.send(:query).should include 'foo+bar'
@@ -19,14 +19,14 @@ describe GoogleBook do
19
19
  GoogleBook.send(:query).should include 'max-results=20'
20
20
  end
21
21
 
22
- it "should validate page" do
22
+ it "should filter out invalid pages" do
23
23
  %w{-1 0 foo}.each do |page|
24
24
  GoogleBook.find('foo bar', :page => page)
25
25
  GoogleBook.send(:query).should_not include 'start-index'
26
26
  end
27
27
  end
28
28
 
29
- it "should validate results per page" do
29
+ it "should filter out invalid counts" do
30
30
  %w{9 21 foo}.each do |count|
31
31
  GoogleBook.find('foo bar', :count => count)
32
32
  GoogleBook.send(:query).should_not include 'max-results'
@@ -39,7 +39,7 @@ describe GoogleBook do
39
39
  end
40
40
 
41
41
  it "should return books" do
42
- GoogleBook.find('deleuze').first.should be_an_instance_of GoogleBook
42
+ GoogleBook.find('deleuze').first.should be_an_instance_of Book
43
43
  end
44
44
  end
45
45
  end
@@ -1,9 +1,9 @@
1
1
  require 'vcr'
2
2
 
3
3
  VCR.config do |c|
4
- c.cassette_library_dir = File.dirname(__FILE__) + '/../fixtures/cassette_library'
5
- c.http_stubbing_library = :webmock
4
+ c.cassette_library_dir = File.dirname(__FILE__) + '/../fixtures/cassette_library'
6
5
  c.default_cassette_options = { :record => :new_episodes }
6
+ c.stub_with :webmock
7
7
  end
8
8
 
9
9
  RSpec.configure do |config|
metadata CHANGED
@@ -1,20 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googlebook
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
4
+ prerelease:
5
+ version: 0.1.0
10
6
  platform: ruby
11
7
  authors:
12
- - Hakan Ensari
8
+ - Paper Cavalier
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-10-26 00:00:00 +01:00
13
+ date: 2011-03-04 00:00:00 +00:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,91 +21,45 @@ dependencies:
25
21
  requirements:
26
22
  - - ~>
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 6
31
- - 1
32
- version: 0.6.1
24
+ version: 0.7.4
33
25
  type: :runtime
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
36
- name: rdiscount
28
+ name: rspec
37
29
  prerelease: false
38
30
  requirement: &id002 !ruby/object:Gem::Requirement
39
31
  none: false
40
32
  requirements:
41
33
  - - ~>
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 1
45
- - 6
46
- - 5
47
- version: 1.6.5
35
+ version: 2.5.0
48
36
  type: :development
49
37
  version_requirements: *id002
50
38
  - !ruby/object:Gem::Dependency
51
- name: rspec
39
+ name: vcr
52
40
  prerelease: false
53
41
  requirement: &id003 !ruby/object:Gem::Requirement
54
42
  none: false
55
43
  requirements:
56
44
  - - ~>
57
45
  - !ruby/object:Gem::Version
58
- segments:
59
- - 2
60
- - 0
61
- - 1
62
- version: 2.0.1
46
+ version: 1.7.0
63
47
  type: :development
64
48
  version_requirements: *id003
65
49
  - !ruby/object:Gem::Dependency
66
- name: sdoc-helpers
50
+ name: webmock
67
51
  prerelease: false
68
52
  requirement: &id004 !ruby/object:Gem::Requirement
69
53
  none: false
70
54
  requirements:
71
55
  - - ~>
72
56
  - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
- - 1
76
- - 4
77
- version: 0.1.4
57
+ version: 1.6.2
78
58
  type: :development
79
59
  version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: vcr
82
- prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ~>
87
- - !ruby/object:Gem::Version
88
- segments:
89
- - 1
90
- - 2
91
- - 0
92
- version: 1.2.0
93
- type: :development
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
96
- name: webmock
97
- prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
99
- none: false
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- segments:
104
- - 1
105
- - 4
106
- - 0
107
- version: 1.4.0
108
- type: :development
109
- version_requirements: *id006
110
- description: Google Book is a Ruby class in tight embrace with the Google Book Search Data API.
60
+ description: Google Book is a Ruby wrapper to the Google Book Search Data API.
111
61
  email:
112
- - hakan.ensari@papercavalier.com
62
+ - code@papercavalier.com
113
63
  executables: []
114
64
 
115
65
  extensions: []
@@ -119,7 +69,6 @@ extra_rdoc_files: []
119
69
  files:
120
70
  - .gitignore
121
71
  - .rspec
122
- - CHANGELOG.md
123
72
  - Gemfile
124
73
  - Gemfile.lock
125
74
  - LICENSE
@@ -127,14 +76,16 @@ files:
127
76
  - Rakefile
128
77
  - googlebook.gemspec
129
78
  - lib/googlebook.rb
79
+ - lib/googlebook/book.rb
130
80
  - lib/googlebook/finder.rb
81
+ - lib/googlebook/images.rb
131
82
  - lib/googlebook/version.rb
83
+ - spec/googlebook/book_spec.rb
132
84
  - spec/googlebook/finder_spec.rb
133
- - spec/googlebook_spec.rb
134
85
  - spec/spec_helper.rb
135
86
  - spec/support/vcr.rb
136
87
  has_rdoc: true
137
- homepage: http://gloss.papercavalier.com/googlebook
88
+ homepage: http://rubygems.com/gems/googlebook
138
89
  licenses: []
139
90
 
140
91
  post_install_message:
@@ -147,26 +98,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
98
  requirements:
148
99
  - - ">="
149
100
  - !ruby/object:Gem::Version
150
- segments:
151
- - 0
152
101
  version: "0"
153
102
  required_rubygems_version: !ruby/object:Gem::Requirement
154
103
  none: false
155
104
  requirements:
156
105
  - - ">="
157
106
  - !ruby/object:Gem::Version
158
- segments:
159
- - 0
160
107
  version: "0"
161
108
  requirements: []
162
109
 
163
110
  rubyforge_project: googlebook
164
- rubygems_version: 1.3.7
111
+ rubygems_version: 1.5.2
165
112
  signing_key:
166
113
  specification_version: 3
167
- summary: A Ruby class in tight embrace with the Google Book Search Data API
114
+ summary: A Ruby wrapper to the Google Book Search Data API
168
115
  test_files:
116
+ - spec/googlebook/book_spec.rb
169
117
  - spec/googlebook/finder_spec.rb
170
- - spec/googlebook_spec.rb
171
118
  - spec/spec_helper.rb
172
119
  - spec/support/vcr.rb
File without changes
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoogleBook do
4
- use_vcr_cassette 'googlebook', :record => :new_episodes
5
-
6
- subject { GoogleBook.find('deleuze').first }
7
-
8
- %w{thumbnail info preview creator date description format
9
- identifier isbn publisher subject title}.each do |attribute|
10
- its(attribute) { should_not be_nil }
11
- end
12
- end