google_books 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
- v0.0.1
4
+ v0.1.0
5
5
  ------
6
6
  This is the initial version of google_books
7
7
 
@@ -30,3 +30,10 @@ This is the initial version of google_books
30
30
  * `:extra_large`
31
31
  * `preview_link` - *String*
32
32
  * `info_link` - *String*
33
+
34
+ v0.2.0
35
+ ------
36
+ * New Features
37
+ * Standardized publisher names in a similar fashion to the [google-book gem](https://rubygems.org/gems/google-book)
38
+ * Bug Fixes
39
+ * The publishedDate field in the Google Books API are strings in the format of YYYY-MM-DD. Sometimes it's just YYYY and other times it's YYYY-MM. Previously the `published_date` attribute was a Date type, now it is a string and you can convert the date however you want in your applications.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_books (0.1)
4
+ google_books (0.2.0)
5
5
  hashie
6
6
  httparty
7
7
 
data/README.md CHANGED
@@ -57,7 +57,10 @@ Book Attributes
57
57
 
58
58
  * `authors`: *Array*
59
59
  * `publisher`: *String*
60
- * `published_date`: *Date*
60
+ * `published_date`: *String*
61
+
62
+ The `published_date` is represented by the format YYYY-MM-DD with MM and DD being optional
63
+
61
64
  * `isbn`: *String*
62
65
  * `isbn_10`: *String*
63
66
  * `page_count`: *FixNum*
@@ -12,18 +12,16 @@ module GoogleBooks
12
12
  end
13
13
 
14
14
  private
15
-
15
+
16
16
  def parse_item(item)
17
17
  volume_info = item['volumeInfo']
18
18
  @book = Hashie::Mash.new volume_info
19
- if @book.subtitle.nil?
20
- @title = @book.title
21
- else
22
- @title = "#{@book.title}: #{titlize(@book.subtitle)}"
23
- end
19
+ @title = build_title(@book)
24
20
  @authors = @book.authors || []
25
- @publisher = @book.publisher
26
- @published_date = @book.publishedDate
21
+ @publisher = normalize_publisher(@book.publisher)
22
+
23
+ @published_date = @book.publishedDate.to_s
24
+
27
25
  @description = @book.description
28
26
  @isbn = get_isbn_for_book
29
27
  @isbn_10 = get_isbn_for_book(10)
@@ -35,7 +33,27 @@ module GoogleBooks
35
33
  @preview_link = @book.previewLink
36
34
  @info_link = @book.infoLink
37
35
  end
36
+
37
+ def build_title(book)
38
+ return book.title if book.subtitle.nil?
39
+ "#{book.title}: #{titlize(book.subtitle)}"
40
+ end
38
41
 
42
+ def normalize_publisher(name)
43
+ return name if name.blank?
44
+
45
+ name.
46
+ gsub(/[ ,]+Inc.?$/i, ' Inc.').
47
+ gsub(/[ ,]+Llc.?$/i, ' LLC.').
48
+ gsub(/[ ,]+Ltd.?$/i, ' Ltd.').
49
+ gsub(/Intl( |$)/i) { "International#{$1}" }.
50
+ gsub(/Pr( |$)/i) { "Press#{$1}" }.
51
+ gsub(/Pub Group( |$)/i) { "Publishing Group#{$1}" }.
52
+ gsub(/Pub( |$)/i) { "Publishers#{$1}" }.
53
+ gsub(/Pubns( |$)/i) { "Publications#{$1}" }.
54
+ gsub(/Univ( |$)/i) { "University#{$1}" }
55
+ end
56
+
39
57
  def get_isbn_for_book(type=13)
40
58
  return nil if @book.industryIdentifiers.nil?
41
59
  isbn = @book.industryIdentifiers.find { |id| id.type == "ISBN_#{type}" }
@@ -1,3 +1,3 @@
1
1
  module GoogleBooks
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -7,6 +7,10 @@ module GoogleBooks
7
7
 
8
8
  subject { API.search('isbn:9781935182320').first }
9
9
 
10
+ let(:item) do
11
+ item = { 'volumeInfo' => {} }
12
+ end
13
+
10
14
  it "should be able to handle a nil object passed" do
11
15
  lambda { Book.new(nil) }.should_not raise_error
12
16
  end
@@ -26,14 +30,81 @@ module GoogleBooks
26
30
  subject.authors[1].should eq "Yehuda Katz"
27
31
  end
28
32
 
29
- it "should have a publisher" do
30
- subject.publisher.should_not be_nil
31
- subject.publisher.should include "Manning"
32
- end
33
-
34
- it "should have a published date in date format" do
35
- subject.published_date.should be_a Date
36
- subject.published_date.should eq Date.new(2010, 6, 30)
33
+ describe "publisher" do
34
+ it "should have a publisher" do
35
+ subject.publisher.should_not be_nil
36
+ subject.publisher.should include "Manning"
37
+ end
38
+
39
+ it "should standardize an Inc to Inc." do
40
+ item['volumeInfo']['publisher'] = "Publisher Inc"
41
+ book = Book.new(item)
42
+ book.publisher.should eq "Publisher Inc."
43
+ end
44
+
45
+ it "should standardize an Llc to LLC." do
46
+ item['volumeInfo']['publisher'] = "Publisher Llc"
47
+ book = Book.new(item)
48
+ book.publisher.should eq "Publisher LLC."
49
+ end
50
+
51
+ it "should standardize an Ltd to Ltd." do
52
+ item['volumeInfo']['publisher'] = "Publisher Ltd"
53
+ book = Book.new(item)
54
+ book.publisher.should eq "Publisher Ltd."
55
+ end
56
+
57
+ it "should replace Intl with International anywhere in the name" do
58
+ item['volumeInfo']['publisher'] = "Publisher Intl Clearing House"
59
+ book = Book.new(item)
60
+ book.publisher.should eq "Publisher International Clearing House"
61
+ end
62
+
63
+ it "should replace Pr with Press anywhere in the name" do
64
+ item['volumeInfo']['publisher'] = "Publisher Pr House"
65
+ book = Book.new(item)
66
+ book.publisher.should eq "Publisher Press House"
67
+ end
68
+
69
+ it "should replace Pub with Publishers anywhere in the name" do
70
+ item['volumeInfo']['publisher'] = "Publisher Pub, Inc"
71
+ book = Book.new(item)
72
+ book.publisher.should eq "Publisher Publishers Inc."
73
+ end
74
+
75
+ it "should replace Pubns with Publications anywhere in the name" do
76
+ item['volumeInfo']['publisher'] = "Publisher Pubns Inc"
77
+ book = Book.new(item)
78
+ book.publisher.should eq "Publisher Publications Inc."
79
+ end
80
+
81
+ it "should replace Pub Group with Publishing Group anywhere in the name" do
82
+ item['volumeInfo']['publisher'] = "Publisher Pub Group Inc"
83
+ book = Book.new(item)
84
+ book.publisher.should eq "Publisher Publishing Group Inc."
85
+ end
86
+
87
+ it "should replace Univ with University anywhere in the name" do
88
+ item['volumeInfo']['publisher'] = "Publisher Univ Pr"
89
+ book = Book.new(item)
90
+ book.publisher.should eq "Publisher University Press"
91
+ end
92
+ end
93
+
94
+ describe "published_date" do
95
+ it "should have a published date in sting format" do
96
+ subject.published_date.should eq "2010-06-30"
97
+ end
98
+
99
+ it "should handle a published date that is only a year" do
100
+ book = API.search('isbn:9781934356166').first
101
+ book.published_date.should eq "2009"
102
+ end
103
+
104
+ it "should handle a published date that is only a month and a year" do
105
+ book = API.search('isbn:9780954344405').first
106
+ book.published_date.should eq "2003-01"
107
+ end
37
108
  end
38
109
 
39
110
  it "should have description (which may be blank)" do
@@ -66,29 +137,31 @@ module GoogleBooks
66
137
  subject.ratings_count.should be_a Fixnum
67
138
  end
68
139
 
69
- it "should contain a covers hash" do
70
- subject.covers.should be_a Hash
71
- subject.covers.keys.should include :thumbnail
72
- subject.covers.keys.should include :small
73
- subject.covers.keys.should include :medium
74
- subject.covers.keys.should include :large
75
- subject.covers.keys.should include :extra_large
76
- end
77
-
78
- it "should not have curls on the cover urls" do
79
- subject.covers[:thumbnail].should_not include 'edge=curl'
80
- subject.covers[:small].should_not include 'edge=curl'
81
- subject.covers[:medium].should_not include 'edge=curl'
82
- subject.covers[:large].should_not include 'edge=curl'
83
- subject.covers[:extra_large].should_not include 'edge=curl'
84
- end
85
-
86
- it "should have the cover url zoom level" do
87
- subject.covers[:thumbnail].should include 'zoom=5'
88
- subject.covers[:small].should include 'zoom=1'
89
- subject.covers[:medium].should include 'zoom=2'
90
- subject.covers[:large].should include 'zoom=3'
91
- subject.covers[:extra_large].should include 'zoom=6'
140
+ describe "covers" do
141
+ it "should contain a covers hash" do
142
+ subject.covers.should be_a Hash
143
+ subject.covers.keys.should include :thumbnail
144
+ subject.covers.keys.should include :small
145
+ subject.covers.keys.should include :medium
146
+ subject.covers.keys.should include :large
147
+ subject.covers.keys.should include :extra_large
148
+ end
149
+
150
+ it "should not have curls on the cover urls" do
151
+ subject.covers[:thumbnail].should_not include 'edge=curl'
152
+ subject.covers[:small].should_not include 'edge=curl'
153
+ subject.covers[:medium].should_not include 'edge=curl'
154
+ subject.covers[:large].should_not include 'edge=curl'
155
+ subject.covers[:extra_large].should_not include 'edge=curl'
156
+ end
157
+
158
+ it "should have the cover url zoom level" do
159
+ subject.covers[:thumbnail].should include 'zoom=5'
160
+ subject.covers[:small].should include 'zoom=1'
161
+ subject.covers[:medium].should include 'zoom=2'
162
+ subject.covers[:large].should include 'zoom=3'
163
+ subject.covers[:extra_large].should include 'zoom=6'
164
+ end
92
165
  end
93
166
 
94
167
  it "should contains a preview link" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_books
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
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-07 00:00:00.000000000Z
12
+ date: 2011-08-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70123559467780 !ruby/object:Gem::Requirement
16
+ requirement: &70187585301000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70123559467780
24
+ version_requirements: *70187585301000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hashie
27
- requirement: &70123559467360 !ruby/object:Gem::Requirement
27
+ requirement: &70187585300580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70123559467360
35
+ version_requirements: *70187585300580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: autotest
38
- requirement: &70123559466940 !ruby/object:Gem::Requirement
38
+ requirement: &70187585300160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70123559466940
46
+ version_requirements: *70187585300160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70123559466520 !ruby/object:Gem::Requirement
49
+ requirement: &70187585299740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70123559466520
57
+ version_requirements: *70187585299740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &70123559466100 !ruby/object:Gem::Requirement
60
+ requirement: &70187585299320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70123559466100
68
+ version_requirements: *70187585299320
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
- requirement: &70123559465680 !ruby/object:Gem::Requirement
71
+ requirement: &70187585298900 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70123559465680
79
+ version_requirements: *70187585298900
80
80
  description: A Ruby wrapper that allows you to query the Google Books API. This project
81
81
  was inspired by google-book, see the README for more information
82
82
  email: