googlebooks 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 399d18813263d0a61d626bed082934a9b2c0fcc6
4
+ data.tar.gz: 98fc2773a396e7495ecffab860baf58ecc4bde18
5
+ SHA512:
6
+ metadata.gz: 38f8d0ab7a550c64603f6aaec7a76d21653985816e77afd986104aedb02faa3589f70c8e81d6d8f601e364e48f9fedb27588997f049572b9bcdb7897775ff0ec
7
+ data.tar.gz: db8009bdfc1236dc3ddffa3ba8b3f6c49ba6c196d77bade56bec59b39154114aff7733128ba2edbe71f90f43616cf283fb09224bfb5d77dbf7eba0242d6c3268
data/README.md CHANGED
@@ -45,6 +45,22 @@ By default, results are returned in order of relevance. However, results also be
45
45
  GoogleBooks.search('The Great Gatsby', {:order_by => `ANYTHING ELSE`})
46
46
  #=> both return results in order of relevance
47
47
 
48
+ Geolocation
49
+ -----------
50
+
51
+ Some users may experience issues when querying the Google API from IP addresses that cannot be geolocated by Google. From [this Google forum](http://productforums.google.com/d/msg/books-api/7FQ-622q-jI/XYaWyh-Tzl4J):
52
+
53
+ > Unfortunately the Books API cannot return any results for IPs that we cannot geo-locate. This is due to both legal and contractual reasons. Google does not have the rights to display all the books in all countries. Even public domain laws vary by country.
54
+
55
+ Users experiencing issues can typically resolve this limitation by passing a valid country code to the `country` parameter in the URL query.
56
+
57
+ GoogleBooks.search('The Great Gatsby')
58
+ #=> "Cannot determine user location for geographically restricted operation."
59
+
60
+ GoogleBooks.search('The Great Gatsby', {:country => "ca"})
61
+ #=> returns the first five results
62
+
63
+
48
64
  Special Keywords
49
65
  ----------------
50
66
 
@@ -71,7 +87,9 @@ Attributes
71
87
  By default, GoogleBooks can query the following attributes (note that not all attributes are available to all books):
72
88
 
73
89
  * `title`
90
+ * `titles_array` *Returns an array of all titles, both main and alternative
74
91
  * `authors` *Returns all authors as a comma delimited string*
92
+ * `authors_array` *Returns an array of all author names
75
93
  * `publisher`
76
94
  * `published_date`
77
95
  * `description`
@@ -1,7 +1,7 @@
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, :other_identifier, :page_count, :print_type, :categories, :average_rating, :ratings_count, :language, :preview_link, :info_link, :sale_info
4
+ attr_reader :kind, :id, :title, :titles_array, :authors, :authors_array, :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
@@ -12,39 +12,41 @@ module GoogleBooks
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 = {})
15
- opts[:zoom] ||= 1
16
- opts[:curl] ||= false
17
- @volume_info['imageLinks']['thumbnail'].gsub('zoom=1', "zoom=#{opts[:zoom]}").gsub('&edge=curl', "&edge=#{opts[:curl] ? 'curl' : 'none'}") rescue nil
15
+ opts[:zoom] ||= 1
16
+ opts[:curl] ||= false
17
+ @volume_info['imageLinks']['thumbnail'].gsub('zoom=1', "zoom=#{opts[:zoom]}").gsub('&edge=curl', "&edge=#{opts[:curl] ? 'curl' : 'none'}") rescue nil
18
18
  end
19
19
 
20
20
  private
21
21
 
22
- def retrieve_attribute
23
- @kind = @item['kind']
24
- @id = @item['id']
25
- @title = build_title
26
- @authors = [@volume_info['authors']].flatten.join(', ')
27
- @publisher = @volume_info['publisher']
28
- @published_date = @volume_info['publishedDate']
29
- @description = @volume_info['description']
22
+ def retrieve_attribute
23
+ @kind = @item['kind']
24
+ @id = @item['id']
25
+ @title = build_title
26
+ @titles_array = [@volume_info['title'], @volume_info['subtitle']].compact
27
+ @authors = [@volume_info['authors']].flatten.join(', ')
28
+ @authors_array = [@volume_info['authors']].flatten
29
+ @publisher = @volume_info['publisher']
30
+ @published_date = @volume_info['publishedDate']
31
+ @description = @volume_info['description']
30
32
 
31
33
  retrieve_industry_identifiers
32
34
 
33
- @page_count = @volume_info['pageCount']
34
- @print_type = @volume_info['printType']
35
- @categories = [@volume_info['categories']].flatten.join(', ')
36
- @average_rating = @volume_info['averageRating']
37
- @ratings_count = @volume_info['ratingsCount']
38
- @language = @volume_info['language']
39
- @preview_link = @volume_info['previewLink']
40
- @info_link = @volume_info['infoLink']
35
+ @page_count = @volume_info['pageCount']
36
+ @print_type = @volume_info['printType']
37
+ @categories = [@volume_info['categories']].flatten.join(', ')
38
+ @average_rating = @volume_info['averageRating']
39
+ @ratings_count = @volume_info['ratingsCount']
40
+ @language = @volume_info['language']
41
+ @preview_link = @volume_info['previewLink']
42
+ @info_link = @volume_info['infoLink']
41
43
  @sale_info = @item['saleInfo']
42
- end
44
+ end
43
45
 
44
- def build_title
45
- title = [@volume_info['title']].flatten.join(': ')
46
- @volume_info['subtitle'].nil? ? title : title + ": " + @volume_info['subtitle']
47
- end
46
+ def build_title
47
+ title = [@volume_info['title']].flatten.join(': ')
48
+ @volume_info['subtitle'].nil? ? title : title + ": " + @volume_info['subtitle']
49
+ end
48
50
 
49
51
  def retrieve_industry_identifiers
50
52
 
@@ -36,6 +36,7 @@ module GoogleBooks
36
36
  parameters['maxResults'] = options[:count]
37
37
  parameters['key'] = options[:api_key] if options[:api_key]
38
38
  parameters['orderBy'] = 'newest' if options[:order_by].eql?('newest')
39
+ parameters['country'] = options[:country]
39
40
 
40
41
  Response.new(get(url.to_s))
41
42
  end
@@ -1,3 +1,3 @@
1
1
  module GoogleBooks
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -10,10 +10,18 @@ module GoogleBooks
10
10
  example.title.should eq "Freakonomics: A Rogue Economist Explores the Hidden Side of Everything"
11
11
  end
12
12
 
13
+ it "should return an array of all titles" do
14
+ example.titles_array.should include(*["Freakonomics", "A Rogue Economist Explores the Hidden Side of Everything"])
15
+ end
16
+
13
17
  it "should return a string authors delineated by a comma" do
14
18
  example.authors.should eq "Steven D. Levitt, Stephen J. Dubner"
15
19
  end
16
20
 
21
+ it "should return an array of author names" do
22
+ example.authors_array.should include(*["Steven D. Levitt", "Stephen J. Dubner"])
23
+ end
24
+
17
25
  it "should have an isbn that is 13 digits" do
18
26
  example.isbn.should_not eq nil
19
27
  example.isbn.should eq '9780062132345'
@@ -30,12 +30,18 @@ describe GoogleBooks do
30
30
  GoogleBooks.send(:query).should include 'maxResults=20'
31
31
  end
32
32
 
33
+ it "should set the country" do
34
+ GoogleBooks.search('the great gatsby', :country => "ca")
35
+ GoogleBooks.send(:query).should include 'country=ca'
36
+ end
37
+
33
38
  it "should join parameters" do
34
- GoogleBooks.search('the great gatsby', :count => 20, :page => 2)
39
+ GoogleBooks.search('the great gatsby', :count => 20, :page => 2, :country => "ca")
35
40
  GoogleBooks.send(:query).should include 'startIndex=2'
36
41
  GoogleBooks.send(:query).should include 'maxResults=20'
37
42
  GoogleBooks.send(:query).should include 'q=the+great+gatsby'
38
- GoogleBooks.send(:query).count('&').should eq 2
43
+ GoogleBooks.send(:query).should include 'country=ca'
44
+ GoogleBooks.send(:query).count('&').should eq 3
39
45
  end
40
46
 
41
47
  it "should return the proper number results based on the count passed in" do
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googlebooks
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.7
4
+ version: 0.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Zean Tsoi
@@ -10,15 +9,15 @@ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2013-08-19 00:00:00 Z
12
+ date: 2013-10-22 00:00:00 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: httparty
17
16
  prerelease: false
18
17
  requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ">="
19
+ - &id002
20
+ - ">="
22
21
  - !ruby/object:Gem::Version
23
22
  version: "0"
24
23
  type: :runtime
@@ -26,25 +25,19 @@ dependencies:
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: rspec
28
27
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
28
+ requirement: &id003 !ruby/object:Gem::Requirement
31
29
  requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
30
+ - *id002
35
31
  type: :development
36
- version_requirements: *id002
32
+ version_requirements: *id003
37
33
  - !ruby/object:Gem::Dependency
38
34
  name: webmock
39
35
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
36
+ requirement: &id004 !ruby/object:Gem::Requirement
42
37
  requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
38
+ - *id002
46
39
  type: :development
47
- version_requirements: *id003
40
+ version_requirements: *id004
48
41
  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
42
  email:
50
43
  - zean.tsoi@gmail.com
@@ -72,29 +65,25 @@ files:
72
65
  homepage: https://github.com/zeantsoi/googlebooks
73
66
  licenses: []
74
67
 
68
+ metadata: {}
69
+
75
70
  post_install_message:
76
71
  rdoc_options: []
77
72
 
78
73
  require_paths:
79
74
  - lib
80
75
  required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
76
  requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: "0"
77
+ - *id002
86
78
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
79
  requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: "0"
80
+ - *id002
92
81
  requirements: []
93
82
 
94
83
  rubyforge_project: googlebooks
95
- rubygems_version: 1.8.25
84
+ rubygems_version: 2.1.9
96
85
  signing_key:
97
- specification_version: 3
86
+ specification_version: 4
98
87
  summary: GoogleBooks is a lightweight Ruby wrapper that queries the Google API to search for publications in the Google Books repository.
99
88
  test_files:
100
89
  - spec/googlebooks/book/item_spec.rb