googlebooks 0.0.6 → 0.0.7

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/README.md CHANGED
@@ -13,7 +13,7 @@ Using GoogleBooks is simple. There's just one class, `GoogleBooks`, and one meth
13
13
  require 'googlebooks' # unless you're using Bundler
14
14
 
15
15
  books = GoogleBooks.search('The Great Gatsby')
16
- first_book = book.first
16
+ first_book = books.first
17
17
 
18
18
  first_book.author #=> 'F. Scott Fitzgerald'
19
19
  first_book.isbn #=> '9781443411080'
@@ -1,14 +1,14 @@
1
1
  module GoogleBooks
2
2
 
3
3
  class Item
4
- attr_reader :kind, :id, :title, :authors, :publisher, :published_date, :description, :isbn, :isbn_10, :isbn_13, :page_count, :print_type, :categories, :average_rating, :ratings_count, :language, :preview_link, :info_link, :sale_info
4
+ attr_reader :kind, :id, :title, :authors, :publisher, :published_date, :description, :isbn, :isbn_10, :isbn_13, :other_identifier, :page_count, :print_type, :categories, :average_rating, :ratings_count, :language, :preview_link, :info_link, :sale_info
5
5
 
6
6
  def initialize(item)
7
7
  @item = item
8
8
  @volume_info = @item['volumeInfo']
9
9
  retrieve_attribute
10
10
  end
11
-
11
+
12
12
  # Enables image_link attribute to be customized via passing
13
13
  # optional zoom and edge arguments as a hash
14
14
  def image_link(opts = {})
@@ -18,7 +18,7 @@ module GoogleBooks
18
18
  end
19
19
 
20
20
  private
21
-
21
+
22
22
  def retrieve_attribute
23
23
  @kind = @item['kind']
24
24
  @id = @item['id']
@@ -27,9 +27,9 @@ module GoogleBooks
27
27
  @publisher = @volume_info['publisher']
28
28
  @published_date = @volume_info['publishedDate']
29
29
  @description = @volume_info['description']
30
- @isbn = @volume_info['industryIdentifiers'][1]['identifier'] rescue nil
31
- @isbn_10 = @volume_info['industryIdentifiers'][0]['identifier'] rescue nil
32
- @isbn_13 = @isbn
30
+
31
+ retrieve_industry_identifiers
32
+
33
33
  @page_count = @volume_info['pageCount']
34
34
  @print_type = @volume_info['printType']
35
35
  @categories = [@volume_info['categories']].flatten.join(', ')
@@ -40,11 +40,30 @@ module GoogleBooks
40
40
  @info_link = @volume_info['infoLink']
41
41
  @sale_info = @item['saleInfo']
42
42
  end
43
-
43
+
44
44
  def build_title
45
45
  title = [@volume_info['title']].flatten.join(': ')
46
46
  @volume_info['subtitle'].nil? ? title : title + ": " + @volume_info['subtitle']
47
47
  end
48
+
49
+ def retrieve_industry_identifiers
50
+
51
+ return unless @volume_info['industryIdentifiers']
52
+
53
+ @volume_info['industryIdentifiers'].each do |identifier_hash|
54
+ identifier = identifier_hash["identifier"]
55
+
56
+ case identifier_hash['type']
57
+ when "ISBN_13"
58
+ @isbn = @isbn_13 = identifier
59
+ when "ISBN_10"
60
+ @isbn_10 = identifier
61
+ when "OTHER"
62
+ @other_identifier = identifier
63
+ end
64
+ end
65
+
66
+ end
48
67
  end
49
68
 
50
69
  end
@@ -1,3 +1,3 @@
1
1
  module GoogleBooks
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -3,32 +3,32 @@ require 'spec_helper'
3
3
  module GoogleBooks
4
4
  class Item
5
5
  describe Item do
6
-
6
+
7
7
  example = GoogleBooks.search('isbn:9780062132345').first
8
-
8
+
9
9
  it "should append a subtitle to the title if it exists" do
10
10
  example.title.should eq "Freakonomics: A Rogue Economist Explores the Hidden Side of Everything"
11
11
  end
12
-
12
+
13
13
  it "should return a string authors delineated by a comma" do
14
14
  example.authors.should eq "Steven D. Levitt, Stephen J. Dubner"
15
15
  end
16
-
16
+
17
17
  it "should have an isbn that is 13 digits" do
18
18
  example.isbn.should_not eq nil
19
19
  example.isbn.should eq '9780062132345'
20
20
  example.isbn.to_s.length.should eq 13
21
21
  end
22
-
22
+
23
23
  it "should convert to a 10 digit isbn" do
24
24
  example.isbn_10.should eq '0062132342'
25
25
  end
26
-
26
+
27
27
  it "should make a 13 digit isbn duplicated from the default isbn" do
28
28
  example.isbn_13.should eq '9780062132345'
29
29
  example.isbn_13.should eq example.isbn
30
30
  end
31
-
31
+
32
32
  describe "image_link" do
33
33
  it "should have all zoom varieties and show 1 as a default" do
34
34
  example.image_link.should include "zoom=1"
@@ -39,13 +39,34 @@ module GoogleBooks
39
39
  example.image_link(:zoom => 6).should include "zoom=6"
40
40
  example.image_link(:zoom => 7).should include "zoom=7"
41
41
  end
42
-
42
+
43
43
  it "should default to 'edge=none' and curl when dictated" do
44
44
  example.image_link.should include "edge=none"
45
45
  example.image_link(:curl => true).should include "edge=curl"
46
46
  end
47
+
48
+ context "when google_book_item has no isbn_10 but one OTHER industry identifiers" do
49
+
50
+ let(:google_book_item) {
51
+ {
52
+ "volumeInfo" => {
53
+ "industryIdentifiers" => [
54
+ {
55
+ "type" => "OTHER",
56
+ "identifier" => "GENT:900000054512"
57
+ }
58
+ ]
59
+ }
60
+ }
61
+ }
62
+ let(:item) { Item.new google_book_item }
63
+ subject { item }
64
+
65
+ its(:isbn_10) { should be_nil }
66
+ its(:other_identifier) { should == "GENT:900000054512" }
67
+ end
47
68
  end
48
-
69
+
49
70
  end
50
71
  end
51
72
  end
metadata CHANGED
@@ -1,59 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: googlebooks
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.6
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.0.7
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Zean Tsoi
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-20 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2013-08-19 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: httparty
16
- requirement: &83731200 !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
17
19
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
22
24
  type: :runtime
23
- prerelease: false
24
- version_requirements: *83731200
25
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
26
27
  name: rspec
27
- requirement: &83730990 !ruby/object:Gem::Requirement
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
28
30
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
33
35
  type: :development
34
- prerelease: false
35
- version_requirements: *83730990
36
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
37
38
  name: webmock
38
- requirement: &83730780 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
39
41
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
44
46
  type: :development
45
- prerelease: false
46
- version_requirements: *83730780
47
- description: GoogleBooks is a lightweight Ruby wrapper that queries the Google API
48
- to search for publications in the Google Books repository. It is inspired by the
49
- google-book gem which relies on the deprecated Google GData Books API, but is updated
50
- to hook into the current Google API.
51
- email:
47
+ version_requirements: *id003
48
+ description: GoogleBooks is a lightweight Ruby wrapper that queries the Google API to search for publications in the Google Books repository. It is inspired by the google-book gem which relies on the deprecated Google GData Books API, but is updated to hook into the current Google API.
49
+ email:
52
50
  - zean.tsoi@gmail.com
53
51
  executables: []
52
+
54
53
  extensions: []
54
+
55
55
  extra_rdoc_files: []
56
- files:
56
+
57
+ files:
57
58
  - .gitignore
58
59
  - Gemfile
59
60
  - LICENSE
@@ -70,27 +71,33 @@ files:
70
71
  - spec/spec_helper.rb
71
72
  homepage: https://github.com/zeantsoi/googlebooks
72
73
  licenses: []
74
+
73
75
  post_install_message:
74
76
  rdoc_options: []
75
- require_paths:
77
+
78
+ require_paths:
76
79
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
80
+ required_ruby_version: !ruby/object:Gem::Requirement
78
81
  none: false
79
- requirements:
80
- - - ! '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
87
  none: false
85
- requirements:
86
- - - ! '>='
87
- - !ruby/object:Gem::Version
88
- version: '0'
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
89
92
  requirements: []
93
+
90
94
  rubyforge_project: googlebooks
91
- rubygems_version: 1.8.17
95
+ rubygems_version: 1.8.25
92
96
  signing_key:
93
97
  specification_version: 3
94
- summary: GoogleBooks is a lightweight Ruby wrapper that queries the Google API to
95
- search for publications in the Google Books repository.
96
- test_files: []
98
+ summary: GoogleBooks is a lightweight Ruby wrapper that queries the Google API to search for publications in the Google Books repository.
99
+ test_files:
100
+ - spec/googlebooks/book/item_spec.rb
101
+ - spec/googlebooks/book/response_spec.rb
102
+ - spec/googlebooks/googlebooks_spec.rb
103
+ - spec/spec_helper.rb