bookle 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bookle.rb CHANGED
@@ -1,8 +1,13 @@
1
1
  require 'bookle/google_books_api'
2
2
 
3
+ # Enables Ruby code interact with the Google Books API.
3
4
  class Bookle
4
- # def self.api(google_books_api_key=nil)
5
- def self.api(google_books_api_key='AIzaSyAUJ0psGl0udam2kFzT29L2YWAhCF748ik')
5
+
6
+ # Returns an instance of the class that interacts with the Google Books API.
7
+ #
8
+ # @return [Google::Books::API] -- An instance of the class that interacts with the Google Books API.
9
+ def self.api(google_books_api_key)
6
10
  Google::Books::API.new(google_books_api_key)
7
11
  end
12
+
8
13
  end
@@ -8,19 +8,17 @@ module Google
8
8
  :access_view_status
9
9
 
10
10
  def initialize(access_info)
11
- if access_info
12
- @access_country = access_info["country"]
13
- @viewability = access_info["viewability"]
14
- @embeddable = access_info["embeddable"]
15
- @public_domain = access_info["publicDomain"]
16
- @text_to_speech_permission = access_info["textToSpeechPermission"]
17
- @epub = Google::Books::Epub.new(access_info["epub"])
18
- @pdf = Google::Books::Pdf.new(access_info["pdf"])
19
- @web_reader_link = access_info["webReaderLink"]
20
- @access_view_status = access_info["accessViewStatus"]
21
- end
11
+ access_info = {} unless access_info
12
+ @access_country = access_info["country"]
13
+ @viewability = access_info["viewability"]
14
+ @embeddable = access_info["embeddable"]
15
+ @public_domain = access_info["publicDomain"]
16
+ @text_to_speech_permission = access_info["textToSpeechPermission"]
17
+ @epub = Google::Books::Epub.new(access_info["epub"])
18
+ @pdf = Google::Books::Pdf.new(access_info["pdf"])
19
+ @web_reader_link = access_info["webReaderLink"]
20
+ @access_view_status = access_info["accessViewStatus"]
22
21
  end
23
-
24
22
  end
25
23
  end
26
24
  end
@@ -31,16 +31,24 @@ module Google
31
31
 
32
32
  attr_accessor *(GOOGLE_QUERY_KEYWORDS.keys + GOOGLE_OPTIONAL_PARAMETERS.keys).map{|method_name| method_name.to_sym} << :google_books_api_key
33
33
 
34
+ # Instantiates the API for a given Google key.
35
+ #
36
+ # @param [String, #read] -- Google API key.
37
+ # @return [Google::Books::API] -- An API to interact with the Google Books API.
34
38
  def initialize(google_books_api_key)
35
39
  @google_books_api_key = google_books_api_key
36
40
  @total_volumes = 0
37
41
  @volumes = []
38
42
  end
39
43
 
44
+ # Returns a list of accessors that can be used to set the search criteria.
45
+ #
46
+ # @return [Array] -- A list of accessors that can be used to set the search criteria.
40
47
  def search_accessors
41
48
  GOOGLE_QUERY_KEYWORDS.keys + GOOGLE_OPTIONAL_PARAMETERS.keys
42
49
  end
43
50
 
51
+ # Clears the search criteria.
44
52
  def clear_search_options
45
53
  search_accessors.each do |method_name|
46
54
  __send__ "#{method_name}=".to_sym, nil
@@ -49,21 +57,14 @@ module Google
49
57
  nil
50
58
  end
51
59
 
52
- # Build and also let the user query the string.
53
- # schema = https
54
- # host = www.googleapis.com`
55
- # path = books/v1/volumes
56
- # key marker = key
57
- # query marker = q
58
- # keyword separator = + (used in build_query_options())
60
+ # Builds and also lets users query the URI string used to interact with the Google API.
59
61
  def uri_string
60
62
  "https://www.googleapis.com/books/v1/volumes?key=#{@google_books_api_key}#{build_optional_parameters}&q=#{build_query_options}"
61
63
  end
62
64
 
63
- # The Google Books API builds its query using 'OR', not 'AND'. That means that the more keywords used during the search
64
- # the wider the range of results.
65
- # When search options are passed to this method prior search options set with the set_search_option method will be disregarded.
66
- # def search(isbn='9780140196092')
65
+ # Runs the search against the Google API.
66
+ #
67
+ # @return [Array] -- An array of volumes (or what the Google API calls "items").
67
68
  def search
68
69
  google_response = nil
69
70
  uri = URI(uri_string)
@@ -83,8 +84,11 @@ module Google
83
84
  end
84
85
 
85
86
 
86
- # cacert = certification authority certificates
87
+ # Updates the SSL certificates file.
88
+ #
89
+ # @return [String] -- Either a successful message or an error explanation.
87
90
  def update_cacert_file
91
+ # cacert = certification authority certificates
88
92
  file_path = cacert_path
89
93
 
90
94
  Net::HTTP.start("curl.haxx.se") do |http|
@@ -119,6 +123,9 @@ module Google
119
123
 
120
124
  private
121
125
 
126
+ # Returns a string with optional parameters that the URI string uses to query the Google API.
127
+ #
128
+ # @return [String] -- A string with optional parameters that the URI string uses to query the Google API.
122
129
  def build_optional_parameters
123
130
  string = ''
124
131
 
@@ -132,6 +139,9 @@ module Google
132
139
  string
133
140
  end
134
141
 
142
+ # Returns a string with the query string that the URI string uses to query the Google API.
143
+ #
144
+ # @return [String] -- A string with the query string that the URI string uses to query the Google API.
135
145
  def build_query_options
136
146
  string = ''
137
147
 
@@ -146,6 +156,9 @@ module Google
146
156
  string.chop
147
157
  end
148
158
 
159
+ # Returns the full path of where the cacert file lives.
160
+ #
161
+ # @return [String] -- The full path of where the cacert file lives.
149
162
  def cacert_path
150
163
  File.dirname(`gem which bookle`.chomp) + '/cacert/cacert.pem'
151
164
  end
@@ -4,15 +4,13 @@ module Google
4
4
  attr_reader :is_available
5
5
 
6
6
  def initialize(epub)
7
- if epub
8
- @is_available = epub["isAvailable"]
9
- end
7
+ epub = {} unless epub
8
+ @is_available = epub["isAvailable"]
10
9
  end
11
10
 
12
11
  def to_hash
13
12
  {"is_epub_available" => self.is_available}
14
13
  end
15
-
16
14
  end
17
15
  end
18
16
  end
@@ -4,12 +4,10 @@ module Google
4
4
  attr_reader :small_thumbnail, :thumbnail
5
5
 
6
6
  def initialize(image_links)
7
- if image_links
8
- @small_thumbnail = image_links["smallThumbnail"]
9
- @thumbnail = image_links["thumbnail"]
10
- end
7
+ image_links = {} unless image_links
8
+ @small_thumbnail = image_links["smallThumbnail"]
9
+ @thumbnail = image_links["thumbnail"]
11
10
  end
12
-
13
11
  end
14
12
  end
15
13
  end
@@ -4,6 +4,7 @@ module Google
4
4
  attr_reader :type, :identifier
5
5
 
6
6
  def initialize(identifier)
7
+ identifier = {} unless identifier
7
8
  @type = identifier["type"]
8
9
  @identifier = identifier["identifier"]
9
10
  end
@@ -11,7 +12,6 @@ module Google
11
12
  def to_hash
12
13
  {self.type.downcase => self.identifier}
13
14
  end
14
-
15
15
  end
16
16
  end
17
17
  end
@@ -10,6 +10,7 @@ module Google
10
10
  attr_reader :kind, :id, :etag, :self_link, :volume_info, :sale_info, :access_info, :search_info
11
11
 
12
12
  def initialize(item)
13
+ item = {} unless item
13
14
  @kind = item["kind"]
14
15
  @id = item["id"]
15
16
  @etag = item["etag"]
@@ -23,7 +24,6 @@ module Google
23
24
  def hash
24
25
  Hasherizer.to_hash(self)
25
26
  end
26
-
27
27
  end
28
28
  end
29
29
  end
@@ -7,7 +7,6 @@ module Google
7
7
  def to_hash
8
8
  {"list_price_amount" => self.amount, "list_price_currency_code" => self.currency_code}
9
9
  end
10
-
11
10
  end
12
11
  end
13
12
  end
@@ -4,15 +4,13 @@ module Google
4
4
  attr_reader :is_available
5
5
 
6
6
  def initialize(pdf)
7
- if pdf
8
- @is_available = pdf["isAvailable"]
9
- end
7
+ pdf = {} unless pdf
8
+ @is_available = pdf["isAvailable"]
10
9
  end
11
10
 
12
11
  def to_hash
13
12
  {"is_pdf_available" => self.is_available}
14
13
  end
15
-
16
14
  end
17
15
  end
18
16
  end
@@ -4,12 +4,10 @@ module Google
4
4
  attr_reader :amount, :currency_code
5
5
 
6
6
  def initialize(price)
7
- if price
8
- @amount = price["amount"]
9
- @currency_code = price["currencyCode"]
10
- end
7
+ price = {} unless price
8
+ @amount = price["amount"]
9
+ @currency_code = price["currencyCode"]
11
10
  end
12
-
13
11
  end
14
12
  end
15
13
  end
@@ -7,7 +7,6 @@ module Google
7
7
  def to_hash
8
8
  {"retail_price_amount" => self.amount, "retail_price_currency_code" => self.currency_code}
9
9
  end
10
-
11
10
  end
12
11
  end
13
12
  end
@@ -7,16 +7,14 @@ module Google
7
7
  attr_reader :sale_country, :saleability, :is_ebook, :list_price, :retail_price, :buy_link
8
8
 
9
9
  def initialize(sale_info)
10
- if sale_info
11
- @sale_country = sale_info["country"]
12
- @saleability = sale_info["saleability"]
13
- @is_ebook = sale_info["isEbook"]
14
- @list_price = Google::Books::ListPrice.new(sale_info["listPrice"])
15
- @retail_price = Google::Books::RetailPrice.new(sale_info["retailPrice"])
16
- @buy_link = sale_info["buyLink"]
17
- end
10
+ sale_info = {} unless sale_info
11
+ @sale_country = sale_info["country"]
12
+ @saleability = sale_info["saleability"]
13
+ @is_ebook = sale_info["isEbook"]
14
+ @list_price = Google::Books::ListPrice.new(sale_info["listPrice"])
15
+ @retail_price = Google::Books::RetailPrice.new(sale_info["retailPrice"])
16
+ @buy_link = sale_info["buyLink"]
18
17
  end
19
-
20
18
  end
21
19
  end
22
20
  end
@@ -4,9 +4,8 @@ module Google
4
4
  attr_reader :text_snippet
5
5
 
6
6
  def initialize(search_info)
7
- if search_info
8
- @text_snippet = search_info["textSnippet"]
9
- end
7
+ search_info = {} unless search_info
8
+ @text_snippet = search_info["textSnippet"]
10
9
  end
11
10
  end
12
11
  end
@@ -9,30 +9,28 @@ module Google
9
9
  :info_link, :canonical_volume_link
10
10
 
11
11
  def initialize(volume_info)
12
- if volume_info
13
- @title = volume_info["title"]
14
- @subtitle = volume_info["subtitle"]
15
- @authors = volume_info["authors"]
16
- @publisher = volume_info["publisher"]
17
- @published_date = volume_info["published_date"]
18
- @description = volume_info["description"]
19
- @industry_identifiers = volume_info["industryIdentifiers"].collect do
20
- |i| Google::Books::IndustryIdentifier.new(i)
21
- end if volume_info["industryIdentifiers"]
22
- @page_count = volume_info["pageCount"]
23
- @print_type = volume_info["printType"]
24
- @categories = volume_info["categories"]
25
- @average_rating = volume_info["averageRating"]
26
- @ratings_count = volume_info["ratingsCount"]
27
- @content_version = volume_info["contentVersion"]
28
- @image_links = Google::Books::ImageLinks.new(volume_info["imageLinks"])
29
- @language = volume_info["language"]
30
- @preview_link = volume_info["previewLink"]
31
- @info_link = volume_info["infoLink"]
32
- @canonical_volume_link = volume_info["canonicalVolumeLink"]
33
- end
12
+ volume_info = {} unless volume_info
13
+ @title = volume_info["title"]
14
+ @subtitle = volume_info["subtitle"]
15
+ @authors = volume_info["authors"]
16
+ @publisher = volume_info["publisher"]
17
+ @published_date = volume_info["published_date"]
18
+ @description = volume_info["description"]
19
+ @industry_identifiers = volume_info["industryIdentifiers"].collect do
20
+ |i| Google::Books::IndustryIdentifier.new(i)
21
+ end if volume_info["industryIdentifiers"]
22
+ @page_count = volume_info["pageCount"]
23
+ @print_type = volume_info["printType"]
24
+ @categories = volume_info["categories"]
25
+ @average_rating = volume_info["averageRating"]
26
+ @ratings_count = volume_info["ratingsCount"]
27
+ @content_version = volume_info["contentVersion"]
28
+ @image_links = Google::Books::ImageLinks.new(volume_info["imageLinks"])
29
+ @language = volume_info["language"]
30
+ @preview_link = volume_info["previewLink"]
31
+ @info_link = volume_info["infoLink"]
32
+ @canonical_volume_link = volume_info["canonicalVolumeLink"]
34
33
  end
35
-
36
34
  end
37
35
  end
38
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
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: 2012-02-09 00:00:00.000000000 Z
12
+ date: 2012-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &19283832 !ruby/object:Gem::Requirement
16
+ requirement: &76971900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19283832
24
+ version_requirements: *76971900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hasherizer
27
- requirement: &19282476 !ruby/object:Gem::Requirement
27
+ requirement: &76970760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19282476
35
+ version_requirements: *76970760
36
36
  description: Allows to search for books within Google Books. This is basically an
37
37
  adapter for the Google Books API for volume searches.
38
38
  email: pepe.hipolito@gmail.com
@@ -40,23 +40,23 @@ executables: []
40
40
  extensions: []
41
41
  extra_rdoc_files: []
42
42
  files:
43
- - lib/bookle/google_books_access_info.rb
43
+ - lib/bookle/google_books_retail_price.rb
44
+ - lib/bookle/google_books_list_price.rb
45
+ - lib/bookle/google_books_item.rb
46
+ - lib/bookle/google_books_price.rb
47
+ - lib/bookle/google_books_items.rb
44
48
  - lib/bookle/google_books_api.rb
45
49
  - lib/bookle/google_books_epub.rb
50
+ - lib/bookle/google_books_access_info.rb
51
+ - lib/bookle/google_books_search_info.rb
52
+ - lib/bookle/google_books_sale_info.rb
46
53
  - lib/bookle/google_books_image_links.rb
47
- - lib/bookle/google_books_industry_identifier.rb
48
- - lib/bookle/google_books_item.rb
49
- - lib/bookle/google_books_items.rb
50
- - lib/bookle/google_books_list_price.rb
51
54
  - lib/bookle/google_books_pdf.rb
52
- - lib/bookle/google_books_price.rb
53
- - lib/bookle/google_books_retail_price.rb
54
- - lib/bookle/google_books_sale_info.rb
55
- - lib/bookle/google_books_search_info.rb
55
+ - lib/bookle/google_books_industry_identifier.rb
56
56
  - lib/bookle/google_books_volume_info.rb
57
57
  - lib/bookle.rb
58
58
  - lib/cacert/cacert.pem
59
- homepage: http://rubygems.org/gems/bookle
59
+ homepage: https://github.com/pepehipolito/bookle
60
60
  licenses: []
61
61
  post_install_message:
62
62
  rdoc_options: []
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 1.8.11
79
+ rubygems_version: 1.8.17
80
80
  signing_key:
81
81
  specification_version: 3
82
82
  summary: Google Books API volume search.