booksr 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/Gemfile +1 -1
- data/README.md +52 -52
- data/Rakefile +8 -8
- data/booksr.gemspec +18 -17
- data/lib/booksr.rb +30 -30
- data/lib/booksr/api_handler.rb +37 -37
- data/lib/booksr/book.rb +16 -16
- data/lib/booksr/parser.rb +32 -32
- data/test/tc_search_isbn.rb +58 -58
- data/test/tc_search_title.rb +14 -14
- data/test/ts_google_api.rb +6 -6
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDliN2MxNDE1YjZlMjkxZWMyYTgxMTA5NTAyYjAyNjc1YjhiYTJmMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWIzMDMzMzY5ZTQ2OTFhYTFjOGVhZTQ1OGI3Mzk3N2IzMzdhMzcxNA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NTA1YWVhZWI4OTcxYTY4OTk1MWUxMTRkNDdlY2EwZDE3ZjAyZmZkMmFhZmUy
|
10
|
+
ODEwNjVmZWRjODc2YTRhNzgxYWNmNzVmMzZmZjNjMTc2Yzg2NmNkNWFkYTM1
|
11
|
+
ODM1OTA2NTA5MGIyNWU3NjU5YzE3NDFjZGY1ZjY3OGEyNzRkOTc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGZkYmRhZGQ0ZWU4NDRjODZhODMxZGEyYTdiNzRjNGRlZGIxOTg0NWI3MTc3
|
14
|
+
NzRkZjZhYmU2YmQ0YmQxOTk0MDJmODJmZWIwOGVjZWM1NzYwZGFjOGM2NmJm
|
15
|
+
YzdjZWQ1NjExYTI2ZmUzMDU4ZDVhYWU3NGFjZjM4MTgzZWNjZmQ=
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source 'http://rubygems.org'
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
gemspec
|
data/README.md
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
# Booksr #
|
2
|
-
|
3
|
-
A simple book searcher in Ruby.
|
4
|
-
|
5
|
-
|
6
|
-
## Installation ##
|
7
|
-
|
8
|
-
`gem install booksr`
|
9
|
-
|
10
|
-
|
11
|
-
## Usage ##
|
12
|
-
|
13
|
-
`books = Booksr.search(query_string, query_type)`
|
14
|
-
|
15
|
-
`query_type` can be:
|
16
|
-
|
17
|
-
* `:title`
|
18
|
-
* `:author`
|
19
|
-
* `:isbn`
|
20
|
-
* `:keyword`
|
21
|
-
|
22
|
-
default is `:keyword`.
|
23
|
-
|
24
|
-
`query_string` of `:isbn` can be ISBN10 or ISBN13.
|
25
|
-
|
26
|
-
Return value is array of `Book` which can retrieve book information.
|
27
|
-
|
28
|
-
Attributes of class `Book`:
|
29
|
-
|
30
|
-
* title
|
31
|
-
* subtitle
|
32
|
-
* authors: array
|
33
|
-
* publisher
|
34
|
-
* published_date
|
35
|
-
* description
|
36
|
-
* isbn10
|
37
|
-
* isbn13
|
38
|
-
* page_count
|
39
|
-
* lang
|
40
|
-
|
41
|
-
|
42
|
-
## Example ##
|
43
|
-
|
44
|
-
```ruby
|
45
|
-
require 'booksr'
|
46
|
-
|
47
|
-
books = Booksr.search('Ruby on Rails', :title)
|
48
|
-
book = books[0]
|
49
|
-
|
50
|
-
puts book.title
|
51
|
-
puts book.authors # authors is a array
|
52
|
-
puts book.subtitle
|
1
|
+
# Booksr #
|
2
|
+
|
3
|
+
A simple book searcher in Ruby.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation ##
|
7
|
+
|
8
|
+
`gem install booksr`
|
9
|
+
|
10
|
+
|
11
|
+
## Usage ##
|
12
|
+
|
13
|
+
`books = Booksr.search(query_string, query_type)`
|
14
|
+
|
15
|
+
`query_type` can be:
|
16
|
+
|
17
|
+
* `:title`
|
18
|
+
* `:author`
|
19
|
+
* `:isbn`
|
20
|
+
* `:keyword`
|
21
|
+
|
22
|
+
default is `:keyword`.
|
23
|
+
|
24
|
+
`query_string` of `:isbn` can be ISBN10 or ISBN13.
|
25
|
+
|
26
|
+
Return value is array of `Book` which can retrieve book information.
|
27
|
+
|
28
|
+
Attributes of class `Book`:
|
29
|
+
|
30
|
+
* title
|
31
|
+
* subtitle
|
32
|
+
* authors: array
|
33
|
+
* publisher
|
34
|
+
* published_date
|
35
|
+
* description
|
36
|
+
* isbn10
|
37
|
+
* isbn13
|
38
|
+
* page_count
|
39
|
+
* lang
|
40
|
+
|
41
|
+
|
42
|
+
## Example ##
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require 'booksr'
|
46
|
+
|
47
|
+
books = Booksr.search('Ruby on Rails', :title)
|
48
|
+
book = books[0]
|
49
|
+
|
50
|
+
puts book.title
|
51
|
+
puts book.authors # authors is a array
|
52
|
+
puts book.subtitle
|
53
53
|
```
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
|
3
|
-
Rake::TestTask.new do |t|
|
4
|
-
t.test_files = FileList["test/ts_*.rb"]
|
5
|
-
t.verbose = true
|
6
|
-
end
|
7
|
-
|
8
|
-
desc "Run tests"
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
Rake::TestTask.new do |t|
|
4
|
+
t.test_files = FileList["test/ts_*.rb"]
|
5
|
+
t.verbose = true
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Run tests"
|
9
9
|
task :default => :test
|
data/booksr.gemspec
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = 'booksr'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '2015-01-25'
|
5
|
-
s.summary = 'A simple book searcher'
|
6
|
-
s.description = 'Search book with title, author, isbn or keyword by Google Book API.'
|
7
|
-
s.authors = ['cjwind']
|
8
|
-
s.email = 'cwentsai@gmail.com'
|
9
|
-
s.files = Dir['lib/*.rb', 'lib/booksr/*.rb', 'Gemfile', 'README.md', 'Rakefile', '*.gemspec', 'test/*.rb']
|
10
|
-
s.homepage = 'https://github.com/cjwind/booksr'
|
11
|
-
s.license = 'MIT'
|
12
|
-
|
13
|
-
s.add_runtime_dependency 'bundler'
|
14
|
-
s.add_runtime_dependency 'rest-client'
|
15
|
-
|
16
|
-
s.add_development_dependency '
|
17
|
-
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'booksr'
|
3
|
+
s.version = '0.1.2'
|
4
|
+
s.date = '2015-01-25'
|
5
|
+
s.summary = 'A simple book searcher'
|
6
|
+
s.description = 'Search book with title, author, isbn or keyword by Google Book API.'
|
7
|
+
s.authors = ['cjwind']
|
8
|
+
s.email = 'cwentsai@gmail.com'
|
9
|
+
s.files = Dir['lib/*.rb', 'lib/booksr/*.rb', 'Gemfile', 'README.md', 'Rakefile', '*.gemspec', 'test/*.rb']
|
10
|
+
s.homepage = 'https://github.com/cjwind/booksr'
|
11
|
+
s.license = 'MIT'
|
12
|
+
|
13
|
+
s.add_runtime_dependency 'bundler'
|
14
|
+
s.add_runtime_dependency 'rest-client'
|
15
|
+
|
16
|
+
s.add_development_dependency 'rake'
|
17
|
+
s.add_development_dependency 'test-unit'
|
18
|
+
end
|
data/lib/booksr.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'rest-client'
|
3
|
-
|
4
|
-
require 'booksr/api_handler'
|
5
|
-
require 'booksr/parser'
|
6
|
-
require 'booksr/book'
|
7
|
-
|
8
|
-
class Booksr
|
9
|
-
def self.search(query_string, query_type = :keyword)
|
10
|
-
accepted_type = [:title, :author, :isbn, :keyword]
|
11
|
-
if !accepted_type.include?(query_type)
|
12
|
-
return nil
|
13
|
-
end
|
14
|
-
|
15
|
-
api = ApiHandler.new
|
16
|
-
parser = Parser.new
|
17
|
-
books = Array.new
|
18
|
-
|
19
|
-
responses = api.search_by_google(query_string, query_type)
|
20
|
-
responses.each do |response|
|
21
|
-
volumes = parser.parse_json(response)
|
22
|
-
|
23
|
-
volumes.each do |volume|
|
24
|
-
volume_info = volume["volumeInfo"]
|
25
|
-
books.push(Book.new(parser.parse_info_from_google(volume_info)))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
return books
|
30
|
-
end
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'booksr/api_handler'
|
5
|
+
require 'booksr/parser'
|
6
|
+
require 'booksr/book'
|
7
|
+
|
8
|
+
class Booksr
|
9
|
+
def self.search(query_string, query_type = :keyword)
|
10
|
+
accepted_type = [:title, :author, :isbn, :keyword]
|
11
|
+
if !accepted_type.include?(query_type)
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
|
15
|
+
api = ApiHandler.new
|
16
|
+
parser = Parser.new
|
17
|
+
books = Array.new
|
18
|
+
|
19
|
+
responses = api.search_by_google(query_string, query_type)
|
20
|
+
responses.each do |response|
|
21
|
+
volumes = parser.parse_json(response)
|
22
|
+
|
23
|
+
volumes.each do |volume|
|
24
|
+
volume_info = volume["volumeInfo"]
|
25
|
+
books.push(Book.new(parser.parse_info_from_google(volume_info)))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
return books
|
30
|
+
end
|
31
31
|
end
|
data/lib/booksr/api_handler.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
|
-
class ApiHandler
|
4
|
-
GOOGLE_MAX_RESULTS = 40 # const
|
5
|
-
|
6
|
-
def search_by_google(query_string, query_type)
|
7
|
-
responses = Array.new
|
8
|
-
parser = Parser.new
|
9
|
-
|
10
|
-
# https://www.googleapis.com/books/v1/volumes?q=field:qeury_string&startIndex=#{start_index}&maxResults=#{GOOGLE_MAX_RESULTS}
|
11
|
-
query_string = URI::escape(query_string)
|
12
|
-
api_uri = "https://www.googleapis.com/books/v1/volumes"
|
13
|
-
query = "?q="
|
14
|
-
|
15
|
-
if query_type == :title
|
16
|
-
query += "intitle:"
|
17
|
-
elsif query_type == :author
|
18
|
-
query += "inauthor:"
|
19
|
-
elsif query_type == :isbn
|
20
|
-
query += "isbn:"
|
21
|
-
end
|
22
|
-
|
23
|
-
query += query_string
|
24
|
-
|
25
|
-
start_index = 0
|
26
|
-
begin
|
27
|
-
subquery = "&startIndex=#{start_index}&maxResults=#{GOOGLE_MAX_RESULTS}"
|
28
|
-
|
29
|
-
response = RestClient.get api_uri + query + subquery
|
30
|
-
responses.push(response)
|
31
|
-
|
32
|
-
data = parser.parse_json(response)
|
33
|
-
start_index += GOOGLE_MAX_RESULTS
|
34
|
-
end while data.size == GOOGLE_MAX_RESULTS
|
35
|
-
|
36
|
-
return responses
|
37
|
-
end
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
class ApiHandler
|
4
|
+
GOOGLE_MAX_RESULTS = 40 # const
|
5
|
+
|
6
|
+
def search_by_google(query_string, query_type)
|
7
|
+
responses = Array.new
|
8
|
+
parser = Parser.new
|
9
|
+
|
10
|
+
# https://www.googleapis.com/books/v1/volumes?q=field:qeury_string&startIndex=#{start_index}&maxResults=#{GOOGLE_MAX_RESULTS}
|
11
|
+
query_string = URI::escape(query_string)
|
12
|
+
api_uri = "https://www.googleapis.com/books/v1/volumes"
|
13
|
+
query = "?q="
|
14
|
+
|
15
|
+
if query_type == :title
|
16
|
+
query += "intitle:"
|
17
|
+
elsif query_type == :author
|
18
|
+
query += "inauthor:"
|
19
|
+
elsif query_type == :isbn
|
20
|
+
query += "isbn:"
|
21
|
+
end
|
22
|
+
|
23
|
+
query += query_string
|
24
|
+
|
25
|
+
start_index = 0
|
26
|
+
begin
|
27
|
+
subquery = "&startIndex=#{start_index}&maxResults=#{GOOGLE_MAX_RESULTS}"
|
28
|
+
|
29
|
+
response = RestClient.get api_uri + query + subquery
|
30
|
+
responses.push(response)
|
31
|
+
|
32
|
+
data = parser.parse_json(response)
|
33
|
+
start_index += GOOGLE_MAX_RESULTS
|
34
|
+
end while data.size == GOOGLE_MAX_RESULTS
|
35
|
+
|
36
|
+
return responses
|
37
|
+
end
|
38
38
|
end
|
data/lib/booksr/book.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
class Book
|
2
|
-
attr_reader :title, :subtitle, :authors, :publisher, :published_date, :description
|
3
|
-
attr_reader :isbn10, :isbn13, :page_count, :lang
|
4
|
-
|
5
|
-
def initialize(info)
|
6
|
-
@title = info[:title]
|
7
|
-
@subtitle = info[:subtitle]
|
8
|
-
@authors = info[:authors]
|
9
|
-
@published_date = info[:published_date]
|
10
|
-
@publisher = info[:publisher]
|
11
|
-
@description = info[:description]
|
12
|
-
@page_count = info[:page_count]
|
13
|
-
@lang = info[:lang]
|
14
|
-
@isbn13 = info[:isbn13]
|
15
|
-
@isbn10 = info[:isbn10]
|
16
|
-
end
|
1
|
+
class Book
|
2
|
+
attr_reader :title, :subtitle, :authors, :publisher, :published_date, :description
|
3
|
+
attr_reader :isbn10, :isbn13, :page_count, :lang
|
4
|
+
|
5
|
+
def initialize(info)
|
6
|
+
@title = info[:title]
|
7
|
+
@subtitle = info[:subtitle]
|
8
|
+
@authors = info[:authors]
|
9
|
+
@published_date = info[:published_date]
|
10
|
+
@publisher = info[:publisher]
|
11
|
+
@description = info[:description]
|
12
|
+
@page_count = info[:page_count]
|
13
|
+
@lang = info[:lang]
|
14
|
+
@isbn13 = info[:isbn13]
|
15
|
+
@isbn10 = info[:isbn10]
|
16
|
+
end
|
17
17
|
end
|
data/lib/booksr/parser.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
class Parser
|
2
|
-
def parse_json(json)
|
3
|
-
data = JSON.parse(json)
|
4
|
-
volumes = data["items"]
|
5
|
-
return volumes
|
6
|
-
end
|
7
|
-
|
8
|
-
def parse_info_from_google(volume_info)
|
9
|
-
info = Hash.new
|
10
|
-
|
11
|
-
info[:title] = volume_info["title"]
|
12
|
-
info[:subtitle] = volume_info["subtitle"]
|
13
|
-
info[:authors] = volume_info["authors"]
|
14
|
-
info[:published_date] = volume_info["publishedDate"]
|
15
|
-
info[:publisher] = volume_info["publisher"]
|
16
|
-
info[:description] = volume_info["description"]
|
17
|
-
info[:page_count] = volume_info["pageCount"]
|
18
|
-
info[:lang] = volume_info["language"]
|
19
|
-
|
20
|
-
isbns = volume_info["industryIdentifiers"]
|
21
|
-
if !isbns.nil?
|
22
|
-
isbns.each do |isbn|
|
23
|
-
if isbn["type"] == "ISBN_13"
|
24
|
-
info[:isbn13] = isbn["identifier"]
|
25
|
-
elsif isbn["type"] == "ISBN_10"
|
26
|
-
info[:isbn10] = isbn["identifier"]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
return info
|
32
|
-
end
|
1
|
+
class Parser
|
2
|
+
def parse_json(json)
|
3
|
+
data = JSON.parse(json)
|
4
|
+
volumes = data["items"]
|
5
|
+
return volumes
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse_info_from_google(volume_info)
|
9
|
+
info = Hash.new
|
10
|
+
|
11
|
+
info[:title] = volume_info["title"]
|
12
|
+
info[:subtitle] = volume_info["subtitle"]
|
13
|
+
info[:authors] = volume_info["authors"]
|
14
|
+
info[:published_date] = volume_info["publishedDate"]
|
15
|
+
info[:publisher] = volume_info["publisher"]
|
16
|
+
info[:description] = volume_info["description"]
|
17
|
+
info[:page_count] = volume_info["pageCount"]
|
18
|
+
info[:lang] = volume_info["language"]
|
19
|
+
|
20
|
+
isbns = volume_info["industryIdentifiers"]
|
21
|
+
if !isbns.nil?
|
22
|
+
isbns.each do |isbn|
|
23
|
+
if isbn["type"] == "ISBN_13"
|
24
|
+
info[:isbn13] = isbn["identifier"]
|
25
|
+
elsif isbn["type"] == "ISBN_10"
|
26
|
+
info[:isbn10] = isbn["identifier"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
return info
|
32
|
+
end
|
33
33
|
end
|
data/test/tc_search_isbn.rb
CHANGED
@@ -1,59 +1,59 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'booksr'
|
5
|
-
|
6
|
-
class TestSearchIsbnByGoogleApi1 < Test::Unit::TestCase
|
7
|
-
def setup # will be called before run each member function
|
8
|
-
@books = Booksr.search("0131230522", :isbn)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_result
|
12
|
-
assert_equal(1, @books.size)
|
13
|
-
|
14
|
-
@book = @books[0]
|
15
|
-
|
16
|
-
assert_equal("Unix Network Programming Volume 1: the Sockets Networking API", @book.title)
|
17
|
-
assert_equal("International Edition", @book.subtitle)
|
18
|
-
|
19
|
-
assert_equal(4, @book.authors.size)
|
20
|
-
assert(@book.authors.include?("Stevens Richard"))
|
21
|
-
assert(@book.authors.include?("W. Richard Stevens"))
|
22
|
-
assert(@book.authors.include?("Bill Fenner"))
|
23
|
-
assert(@book.authors.include?("Andrew M. Rudoff"))
|
24
|
-
|
25
|
-
assert_equal(nil, @book.publisher)
|
26
|
-
assert_equal("2004", @book.published_date)
|
27
|
-
assert_equal(nil, @book.description)
|
28
|
-
assert_equal("0131230522", @book.isbn10)
|
29
|
-
assert_equal("9780131230521", @book.isbn13)
|
30
|
-
assert_equal(991, @book.page_count)
|
31
|
-
assert_equal("en", @book.lang)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class TestSearchIsbnByGoogleApi2 < Test::Unit::TestCase
|
36
|
-
def setup # will be called before run each member function
|
37
|
-
@books = Booksr.search("9789866841590", :isbn)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_result
|
41
|
-
assert_equal(1, @books.size)
|
42
|
-
|
43
|
-
@book = @books[0]
|
44
|
-
|
45
|
-
assert_equal("你的孩子不是你的孩子", @book.title)
|
46
|
-
assert_equal("被考試綁架的家庭故事──一位家教老師的見證", @book.subtitle)
|
47
|
-
|
48
|
-
assert_equal(1, @book.authors.size)
|
49
|
-
assert_equal("吳曉樂", @book.authors[0])
|
50
|
-
|
51
|
-
assert_equal("英屬蓋曼群島商網路與書出版股份有限公司臺灣分公司", @book.publisher)
|
52
|
-
assert_equal("2014-11-01", @book.published_date)
|
53
|
-
assert_equal("沒有一篇是普羅大眾樂見的教育神話。 沒有一篇看了會感到喜悅。 沒有一篇看了心中不會亂糟糟的,甚至覺得煩。 然而,這些事情確實發生過。 不僅確實發生過,極可能仍在發生⋯⋯ 說故事的人,是個證人。她花了七年時間,打開一扇又一扇的大門,走進不同的家庭。在門的背後,她見證了各色光怪陸離的景象:一個每日給兒子準備雞精、維他命的母親,在收到兒子成績單的當下,卻也毫不猶豫地甩出一記耳光;為了安撫雙親,躲在衣櫃裡欺騙別人也傷害自己的兒子;也或許,她看見一種用鈔票堆疊起來的親情⋯⋯她以為她是家教,只需帶給學生知識,沒想到學生及他們的家庭帶給她更多的衝擊。 什麼是教育的本質?愛是有條件的嗎? 本書沒有給家長教條式的叮嚀與建議,只有一個個震撼人心的故事。這些故事之所以存在,是期待我們去凝視一個初衷,靜下來,好好想想,把小孩帶到這世界上的初衷。 ■ 被考試綁架的家庭故事——《你的孩子不是你的孩子》新書座談會 講者:吳曉樂(本書作者) 時間:2014年11月29日(六)11:00~12:00 地點:水牛書店 ■ 每個孩子都是獨立的個體——《你的孩子不是你的孩子》新書座談會 講者:吳曉樂(本書作者)、唐光華(樂觀書院創辦人) 時間:2014年12月4日(四)19:30~21:00 地點:誠品信義店3F Mini-Forum", @book.description)
|
54
|
-
assert_equal("9866841596", @book.isbn10)
|
55
|
-
assert_equal("9789866841590", @book.isbn13)
|
56
|
-
assert_equal(328, @book.page_count)
|
57
|
-
assert_equal("zh-TW", @book.lang)
|
58
|
-
end
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'booksr'
|
5
|
+
|
6
|
+
class TestSearchIsbnByGoogleApi1 < Test::Unit::TestCase
|
7
|
+
def setup # will be called before run each member function
|
8
|
+
@books = Booksr.search("0131230522", :isbn)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_result
|
12
|
+
assert_equal(1, @books.size)
|
13
|
+
|
14
|
+
@book = @books[0]
|
15
|
+
|
16
|
+
assert_equal("Unix Network Programming Volume 1: the Sockets Networking API", @book.title)
|
17
|
+
assert_equal("International Edition", @book.subtitle)
|
18
|
+
|
19
|
+
assert_equal(4, @book.authors.size)
|
20
|
+
assert(@book.authors.include?("Stevens Richard"))
|
21
|
+
assert(@book.authors.include?("W. Richard Stevens"))
|
22
|
+
assert(@book.authors.include?("Bill Fenner"))
|
23
|
+
assert(@book.authors.include?("Andrew M. Rudoff"))
|
24
|
+
|
25
|
+
assert_equal(nil, @book.publisher)
|
26
|
+
assert_equal("2004", @book.published_date)
|
27
|
+
assert_equal(nil, @book.description)
|
28
|
+
assert_equal("0131230522", @book.isbn10)
|
29
|
+
assert_equal("9780131230521", @book.isbn13)
|
30
|
+
assert_equal(991, @book.page_count)
|
31
|
+
assert_equal("en", @book.lang)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class TestSearchIsbnByGoogleApi2 < Test::Unit::TestCase
|
36
|
+
def setup # will be called before run each member function
|
37
|
+
@books = Booksr.search("9789866841590", :isbn)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_result
|
41
|
+
assert_equal(1, @books.size)
|
42
|
+
|
43
|
+
@book = @books[0]
|
44
|
+
|
45
|
+
assert_equal("你的孩子不是你的孩子", @book.title)
|
46
|
+
assert_equal("被考試綁架的家庭故事──一位家教老師的見證", @book.subtitle)
|
47
|
+
|
48
|
+
assert_equal(1, @book.authors.size)
|
49
|
+
assert_equal("吳曉樂", @book.authors[0])
|
50
|
+
|
51
|
+
assert_equal("英屬蓋曼群島商網路與書出版股份有限公司臺灣分公司", @book.publisher)
|
52
|
+
assert_equal("2014-11-01", @book.published_date)
|
53
|
+
assert_equal("沒有一篇是普羅大眾樂見的教育神話。 沒有一篇看了會感到喜悅。 沒有一篇看了心中不會亂糟糟的,甚至覺得煩。 然而,這些事情確實發生過。 不僅確實發生過,極可能仍在發生⋯⋯ 說故事的人,是個證人。她花了七年時間,打開一扇又一扇的大門,走進不同的家庭。在門的背後,她見證了各色光怪陸離的景象:一個每日給兒子準備雞精、維他命的母親,在收到兒子成績單的當下,卻也毫不猶豫地甩出一記耳光;為了安撫雙親,躲在衣櫃裡欺騙別人也傷害自己的兒子;也或許,她看見一種用鈔票堆疊起來的親情⋯⋯她以為她是家教,只需帶給學生知識,沒想到學生及他們的家庭帶給她更多的衝擊。 什麼是教育的本質?愛是有條件的嗎? 本書沒有給家長教條式的叮嚀與建議,只有一個個震撼人心的故事。這些故事之所以存在,是期待我們去凝視一個初衷,靜下來,好好想想,把小孩帶到這世界上的初衷。 ■ 被考試綁架的家庭故事——《你的孩子不是你的孩子》新書座談會 講者:吳曉樂(本書作者) 時間:2014年11月29日(六)11:00~12:00 地點:水牛書店 ■ 每個孩子都是獨立的個體——《你的孩子不是你的孩子》新書座談會 講者:吳曉樂(本書作者)、唐光華(樂觀書院創辦人) 時間:2014年12月4日(四)19:30~21:00 地點:誠品信義店3F Mini-Forum", @book.description)
|
54
|
+
assert_equal("9866841596", @book.isbn10)
|
55
|
+
assert_equal("9789866841590", @book.isbn13)
|
56
|
+
assert_equal(328, @book.page_count)
|
57
|
+
assert_equal("zh-TW", @book.lang)
|
58
|
+
end
|
59
59
|
end
|
data/test/tc_search_title.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'booksr'
|
5
|
-
|
6
|
-
class TestSearchTitleByGoogleApi < Test::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
@title = "Ruby on Rails"
|
9
|
-
@books = Booksr.search(@title, :title)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_result_count_over_40
|
13
|
-
assert_operator(40, :<=, @books.size)
|
14
|
-
end
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'booksr'
|
5
|
+
|
6
|
+
class TestSearchTitleByGoogleApi < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@title = "Ruby on Rails"
|
9
|
+
@books = Booksr.search(@title, :title)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_result_count_over_40
|
13
|
+
assert_operator(40, :<=, @books.size)
|
14
|
+
end
|
15
15
|
end
|
data/test/ts_google_api.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# Search by Google Book API test suite
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'test/unit/testsuite'
|
6
|
-
require './test/tc_search_isbn'
|
1
|
+
# Search by Google Book API test suite
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'test/unit/testsuite'
|
6
|
+
require './test/tc_search_isbn'
|
7
7
|
require './test/tc_search_title'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booksr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cjwind
|
@@ -14,42 +14,56 @@ dependencies:
|
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: test-unit
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - ! '>='
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - ! '>='
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
description: Search book with title, author, isbn or keyword by Google Book API.
|
@@ -79,17 +93,17 @@ require_paths:
|
|
79
93
|
- lib
|
80
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
95
|
requirements:
|
82
|
-
- -
|
96
|
+
- - ! '>='
|
83
97
|
- !ruby/object:Gem::Version
|
84
98
|
version: '0'
|
85
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- -
|
101
|
+
- - ! '>='
|
88
102
|
- !ruby/object:Gem::Version
|
89
103
|
version: '0'
|
90
104
|
requirements: []
|
91
105
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.2.2
|
93
107
|
signing_key:
|
94
108
|
specification_version: 4
|
95
109
|
summary: A simple book searcher
|