google_book 0.3.12 → 0.3.14

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/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'rspec'
4
- gem 'rake'
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'rake'
5
5
  gem 'webmock'
data/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
  <a href = "https://codeclimate.com/repos/51fa3a5356b102601a00d3e1/feed"><img src="https://codeclimate.com/repos/51fa3a5356b102601a00d3e1/badges/8db2d24d585c3d2ac1f1/gpa.png" /></a>
9
9
  <a href = "https://travis-ci.org/rajcybage/google_book"><img src= "https://travis-ci.org/rajcybage/google_book.png?branch=master"/></a>
10
10
  <img src = "https://badge.fury.io/rb/google_book.png"/>
11
+
12
+ <div rel="tooltip" id="project_status_wrapper" data-original-title="Copy badge url to clipboard"><a href="#"><img src="https://gemnasium.com/rajcybage/google_book.png" id="project_status" alt="Google_book"></a></div>
11
13
  </div>
12
14
 
13
15
  <h1>Google Book Api Integration For Books and Magazines and Book Shelves</h1><br/>
@@ -15,7 +17,7 @@
15
17
  <div>
16
18
  <h2>Installation</h2>
17
19
  <p>In Gemfile<br/>
18
- <code>gem 'google_book', '0.3.12'</code>
20
+ <code>gem 'google_book', '0.3.13'</code>
19
21
  </p>
20
22
  </div>
21
23
  <div>
@@ -48,7 +50,6 @@
48
50
  <p>
49
51
  <code>b=GoogleBook::Book.new(:api_key => "YOUR_GOOOGLE_API_KEY")</code> <br/>
50
52
  <code> b.search("keyword or book name",1)</code> <br/>
51
- <code>b.book_info.get_all_titles #to get the all titles of your search book</code> <br/>
52
53
  <code>b.book_info.get_all_subtitles # to get all the subtitles of your search book</code>
53
54
  <code>b.total_count #get the search results count</code><br/>
54
55
 
@@ -157,5 +158,16 @@
157
158
  </p>
158
159
  </div>
159
160
 
161
+ <div>
162
+ <h1>Contributing</h1>
163
+
164
+ <p>Fork it</p>
165
+ <p>Create your feature branch (git checkout -b my-new-feature)</p>
166
+ <p>Commit your changes (git commit -am 'Add some feature')</p>
167
+ <p>Push to the branch (git push origin my-new-feature)</p>
168
+ <p>Create new Pull Request</p>
169
+
170
+ </div>
171
+
160
172
  </body>
161
173
  </html>
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
- require 'rspec'
4
- require 'rspec/core'
5
- require 'rspec/mocks'
6
- require 'rspec/expectations'
7
- require 'rspec/core/rake_task'
8
- RSpec::Core::RakeTask.new(:spec) do |t|
9
- t.pattern = 'spec/*_spec.rb'
10
- t.rspec_opts ||= []
11
- t.rspec_opts << '--color'
12
- t.rspec_opts << '-f documentation'
13
- end
14
-
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rspec'
4
+ require 'rspec/core'
5
+ require 'rspec/mocks'
6
+ require 'rspec/expectations'
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = 'spec/*_spec.rb'
10
+ t.rspec_opts ||= []
11
+ t.rspec_opts << '--color'
12
+ t.rspec_opts << '-f documentation'
13
+ end
14
+
15
15
  task :default => :spec
@@ -1,6 +1,6 @@
1
- require "google_book/base.rb"
2
- require 'google_book/book_info.rb'
3
- require 'google_book/book_item.rb'
4
- require 'google_book/book_shelves.rb'
5
- require 'google_book/uri.rb'
1
+ require "google_book/base.rb"
2
+ require 'google_book/book_info.rb'
3
+ require 'google_book/book_item.rb'
4
+ require 'google_book/book_shelves.rb'
5
+ require 'google_book/uri.rb'
6
6
  require 'google_book/book_shelf_item.rb'
@@ -1,161 +1,161 @@
1
- require 'uri'
2
- require 'net/http'
3
- require 'openssl'
4
- require 'json'
5
-
6
- require_relative 'book_info.rb'
7
- require_relative 'book_item.rb'
8
- require_relative 'uri.rb'
9
- module GoogleBook
10
- class Book
11
- include URI
12
- attr_accessor :api_key, :total_count, :items, :books
13
-
14
- def initialize(api_key)
15
- unless api_key.nil?
16
- @api_key = api_key[:api_key]
17
- else
18
- raise "Api key can not be nil. Please given your api_key"
19
- end
20
- end
21
-
22
- #Google books search
23
- def search(query,type = nil)
24
- checking_type(type)
25
- type = set_type(type) unless type.nil?
26
- if query.nil?
27
- puts 'Enter the text to search'
28
- text = gets
29
- end
30
- json = JSON.parse(connect_google(@api_key,type,query))
31
- @total_count = json["totalItems"]
32
- @items = json["items"]
33
- end
34
-
35
- #Google books filtration
36
- def filter(query, type = nil)
37
- checking_filter_type(type)
38
- filter_type = set_filter_type(type) unless type.nil?
39
- json = JSON.parse(connect_google(@api_key,nil,query,filter_type))
40
- @total_count = json["totalItems"]
41
- @items = json["items"]
42
- end
43
-
44
- #get all the books information
45
- def book_info
46
- BookInfo.new(items: @items)
47
- end
48
-
49
- #create all book instances
50
- def books
51
- @books = []
52
- @items.each do |item|
53
- @books << BookItem.new(item: item)
54
- end
55
- return @books
56
- end
57
-
58
- def checking_filter_type(type)
59
- if type.nil?
60
- puts "How you want to filter your search?(example:1)?"
61
- puts "1)Free ebooks"
62
- puts "2)Paid ebboks"
63
- puts "3)Full text"
64
- f_type = gets
65
- else
66
- type = "1"
67
- end
68
- end
69
-
70
-
71
- def set_filter_type(type)
72
- case type.to_i
73
- when 1
74
- type = "free-ebooks"
75
- when 2
76
- type = "paid-ebooks"
77
- when 3
78
- type = "full"
79
- else
80
- type = "ebooks"
81
- end
82
- end
83
-
84
-
85
- def checking_type(type)
86
- if type.nil?
87
- puts "How you want to search?input only list number(ex:1)\n"
88
- puts "1)By Title\n"
89
- puts "2)By Author Name\n"
90
- puts "3)By Publisher\n"
91
- puts "4)By Subject\n"
92
- puts "5)By ISBN number:- \n"
93
- puts "6)Library of Congress Control Number\n"
94
- puts "7)By Online Computer Library Center number\n"
95
- puts "8)Want to search Downloadable book"
96
- puts "9)Want to search downloadable Magazines"
97
- type = gets
98
- else
99
- type = "1"
100
- end
101
- end
102
-
103
- def set_type(type)
104
- case type.to_i
105
- when 1
106
- type = "intitle"
107
- when 2
108
- type = "inauthor"
109
- when 3
110
- type = "inpublisher"
111
- when 4
112
- type = "subject"
113
- when 5
114
- type = "isbn"
115
- when 6
116
- type = "lccn"
117
- when 7
118
- type = "oclc"
119
- when 8
120
- type = "download"
121
- when 9
122
- type = "magazine"
123
- else
124
- type = "inauthor"
125
- end
126
- return type
127
- end
128
-
129
- def url_formation(api_key = nil,type = nil,search_param = nil, filter = nil)
130
- main_url = "https://www.googleapis.com/books/v1/volumes"
131
- if !type.nil?
132
- url = set_normal_url(api_key, type, search_param, main_url)
133
- elsif type.nil? && !filter.nil?
134
- url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&filter=#{filter}&key=#{@api_key}"
135
- else
136
- url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&key=#{@api_key}"
137
- end
138
- puts "#{url}"
139
- return URI(url)
140
- end
141
-
142
- def set_normal_url(api_key, type, search_param, main_url)
143
- case type
144
- when "download"
145
- url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&download=epub&key=#{api_key}"
146
- when "magazine"
147
- url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&printType=magazines&key=#{api_key}"
148
- else
149
- url = main_url+"?q=#{search_param.gsub(/\s+/, "").strip}+#{type}:keyes&key=#{api_key}"
150
- end
151
- return url
152
- end
153
-
154
- def connect_google(key = nil,type = nil,search_param = nil,filter = nil)
155
- uri = url_formation(key,type,search_param,filter)
156
- uri=URI::Uri.new(uri)
157
- # response = Net::HTTP.get_response(uri)
158
- return uri.response.body
159
- end
160
- end
161
- end
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'json'
5
+
6
+ require_relative 'book_info.rb'
7
+ require_relative 'book_item.rb'
8
+ require_relative 'uri.rb'
9
+ module GoogleBook
10
+ class Book
11
+ include URI
12
+ attr_accessor :api_key, :total_count, :items, :books
13
+
14
+ def initialize(api_key)
15
+ unless api_key.nil?
16
+ @api_key = api_key[:api_key]
17
+ else
18
+ raise "Api key can not be nil. Please given your api_key"
19
+ end
20
+ end
21
+
22
+ #Google books search
23
+ def search(query,type = nil)
24
+ checking_type(type)
25
+ type = set_type(type) unless type.nil?
26
+ if query.nil?
27
+ puts 'Enter the text to search'
28
+ text = gets
29
+ end
30
+ json = JSON.parse(connect_google(@api_key,type,query))
31
+ @total_count = json["totalItems"]
32
+ @items = json["items"]
33
+ end
34
+
35
+ #Google books filtration
36
+ def filter(query, type = nil)
37
+ checking_filter_type(type)
38
+ filter_type = set_filter_type(type) unless type.nil?
39
+ json = JSON.parse(connect_google(@api_key,nil,query,filter_type))
40
+ @total_count = json["totalItems"]
41
+ @items = json["items"]
42
+ end
43
+
44
+ #get all the books information
45
+ def book_info
46
+ BookInfo.new(items: @items)
47
+ end
48
+
49
+ #create all book instances
50
+ def books
51
+ @books = []
52
+ @items.each do |item|
53
+ @books << BookItem.new(item: item)
54
+ end
55
+ return @books
56
+ end
57
+
58
+ def checking_filter_type(type)
59
+ if type.nil?
60
+ puts "How you want to filter your search?(example:1)?"
61
+ puts "1)Free ebooks"
62
+ puts "2)Paid ebboks"
63
+ puts "3)Full text"
64
+ f_type = gets
65
+ else
66
+ type = "1"
67
+ end
68
+ end
69
+
70
+
71
+ def set_filter_type(type)
72
+ case type.to_i
73
+ when 1
74
+ type = "free-ebooks"
75
+ when 2
76
+ type = "paid-ebooks"
77
+ when 3
78
+ type = "full"
79
+ else
80
+ type = "ebooks"
81
+ end
82
+ end
83
+
84
+
85
+ def checking_type(type)
86
+ if type.nil?
87
+ puts "How you want to search?input only list number(ex:1)\n"
88
+ puts "1)By Title\n"
89
+ puts "2)By Author Name\n"
90
+ puts "3)By Publisher\n"
91
+ puts "4)By Subject\n"
92
+ puts "5)By ISBN number:- \n"
93
+ puts "6)Library of Congress Control Number\n"
94
+ puts "7)By Online Computer Library Center number\n"
95
+ puts "8)Want to search Downloadable book"
96
+ puts "9)Want to search downloadable Magazines"
97
+ type = gets
98
+ else
99
+ type = "1"
100
+ end
101
+ end
102
+
103
+ def set_type(type)
104
+ case type.to_i
105
+ when 1
106
+ type = nil
107
+ when 2
108
+ type = "inauthor"
109
+ when 3
110
+ type = "inpublisher"
111
+ when 4
112
+ type = "subject"
113
+ when 5
114
+ type = "isbn"
115
+ when 6
116
+ type = "lccn"
117
+ when 7
118
+ type = "oclc"
119
+ when 8
120
+ type = "download"
121
+ when 9
122
+ type = "magazine"
123
+ else
124
+ type = "inauthor"
125
+ end
126
+ return type
127
+ end
128
+
129
+ def url_formation(api_key = nil,type = nil,search_param = nil, filter = nil)
130
+ main_url = "https://www.googleapis.com/books/v1/volumes"
131
+ if !type.nil?
132
+ url = set_normal_url(api_key, type, search_param, main_url)
133
+ elsif type.nil? && !filter.nil?
134
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&filter=#{filter}"
135
+ else
136
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}"
137
+ end
138
+ puts "#{url}"
139
+ return URI(url)
140
+ end
141
+
142
+ def set_normal_url(api_key, type, search_param, main_url)
143
+ case type
144
+ when "download"
145
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&download=epub"
146
+ when "magazine"
147
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&printType=magazines"
148
+ else
149
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "").strip}+#{type}"
150
+ end
151
+ return url
152
+ end
153
+
154
+ def connect_google(key = nil,type = nil,search_param = nil,filter = nil)
155
+ uri = url_formation(key,type,search_param,filter)
156
+ uri=URI::Uri.new(uri)
157
+ # response = Net::HTTP.get_response(uri)
158
+ return uri.response.body
159
+ end
160
+ end
161
+ end
@@ -1,37 +1,37 @@
1
- require_relative 'base.rb'
2
-
3
- class BookInfo
4
- attr_accessor :items, :titles, :subtitles, :book
5
- @titles = []
6
- @subtitles = []
7
- def initialize(items=[])
8
- @items = items
9
- end
10
-
11
- #return the all titles of those books
12
- def get_all_titles
13
- show_all_titles_and_subtitles("title")
14
- return @titles
15
- end
16
-
17
- #return all the subtitles
18
- def get_all_sub_titles
19
- show_all_titles_and_subtitles("subtitle")
20
- return @subtitles
21
- end
22
-
23
-
24
- #return the particular book
25
- def get_book(params = {})
26
- item = @items.detect{|i| i[params.keys.first] == params.values.first} || @items.detect{|i| i["volumeInfo"][params.keys.first] == params.values.first}
27
- @book = BookItem.new(item: item)
28
- end
29
-
30
- private
31
- def show_all_titles_and_subtitles(flag)
32
- @items[:items].inject do |item|
33
- @titles << item["volumeInfo"]["title"]
34
- end
35
- end
36
-
1
+ require_relative 'base.rb'
2
+
3
+ class BookInfo
4
+ attr_accessor :items, :titles, :subtitles, :book
5
+ @titles = []
6
+ @subtitles = []
7
+ def initialize(items=[])
8
+ @items = items
9
+ end
10
+
11
+ #return the all titles of those books
12
+ def get_all_titles
13
+ show_all_titles_and_subtitles("title")
14
+ return @titles
15
+ end
16
+
17
+ #return all the subtitles
18
+ def get_all_sub_titles
19
+ show_all_titles_and_subtitles("subtitle")
20
+ return @subtitles
21
+ end
22
+
23
+
24
+ #return the particular book
25
+ def get_book(params = {})
26
+ item = @items.detect{|i| i[params.keys.first] == params.values.first} || @items.detect{|i| i["volumeInfo"][params.keys.first] == params.values.first}
27
+ @book = BookItem.new(item: item)
28
+ end
29
+
30
+ private
31
+ def show_all_titles_and_subtitles(flag)
32
+ @items[:items].inject do |item|
33
+ @titles << item["volumeInfo"]["title"]
34
+ end
35
+ end
36
+
37
37
  end
@@ -1,3 +1,3 @@
1
1
  module GoogleBook
2
- Version = "0.3.12"
2
+ Version = "0.3.14"
3
3
  end
@@ -37,7 +37,7 @@ describe "book_item" do
37
37
 
38
38
  describe "preview_link" do
39
39
  it "should return perfect preview link" do
40
- @book_items.first.preview_link.should == "http://books.google.com/books?id=_oG_iTxP1pIC&printsec=frontcover&dq=Flowers+inauthor:keyes&hl=&cd=1&source=gbs_api"
40
+ @book_items.first.preview_link.should == "http://books.google.com/books?id=_oG_iTxP1pIC&pg=PA224&dq=Flowers+inauthor:keyes&hl=&cd=1&source=gbs_api"
41
41
  end
42
42
  end
43
43
 
@@ -76,4 +76,4 @@ describe "book_item" do
76
76
  @book_items.first.publish_date.should == "2007-12-01"
77
77
  end
78
78
  end
79
- end
79
+ end
@@ -1,22 +1,22 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
- require 'rspec'
8
- require 'rspec/expectations'
9
- require 'rspec/mocks'
10
- require 'rspec/core'
11
- require 'webmock/rspec'
12
- RSpec.configure do |config|
13
- config.treat_symbols_as_metadata_keys_with_true_values = true
14
- config.run_all_when_everything_filtered = true
15
- config.filter_run :focus
16
- WebMock.allow_net_connect!(:net_http_connect_on_start => true)
17
- # Run specs in random order to surface order dependencies. If you find an
18
- # order dependency and want to debug it, you can fix the order by providing
19
- # the seed, which is printed after each run.
20
- # --seed 1234
21
- config.order = 'random'
22
- end
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'rspec'
8
+ require 'rspec/expectations'
9
+ require 'rspec/mocks'
10
+ require 'rspec/core'
11
+ require 'webmock/rspec'
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+ WebMock.allow_net_connect!(:net_http_connect_on_start => true)
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_book
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
5
- prerelease:
4
+ version: 0.3.14
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rajarshi Das
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-21 00:00:00.000000000 Z
12
+ date: 2013-09-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description:
14
+ description:
15
15
  email: rdasarminus@gmail.com
16
16
  executables: []
17
17
  extensions: []
@@ -22,41 +22,45 @@ files:
22
22
  - Rakefile
23
23
  - spec/base_spec.rb
24
24
  - spec/book_item_spec.rb
25
- - spec/book_shelf_item_spec.rb
26
- - spec/book_shelves_spec.rb
27
25
  - spec/spec_helper.rb
26
+ - spec/book_shelves_spec.rb
27
+ - spec/book_shelf_item_spec.rb
28
28
  - lib/google_book.rb
29
- - lib/google_book/base.rb
29
+ - lib/google_book/book_shelves.rb
30
30
  - lib/google_book/book_info.rb
31
31
  - lib/google_book/book_item.rb
32
32
  - lib/google_book/book_shelf_item.rb
33
- - lib/google_book/book_shelves.rb
34
- - lib/google_book/uri.rb
35
33
  - lib/google_book/version.rb
34
+ - lib/google_book/uri.rb
35
+ - lib/google_book/base.rb
36
36
  homepage: https://github.com/rajcybage/google_book
37
37
  licenses:
38
38
  - Copyright (c) Rajarshi Das. All rights reserved
39
- post_install_message:
39
+ post_install_message:
40
40
  rdoc_options: []
41
41
  require_paths:
42
42
  - lib
43
43
  required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
44
45
  requirements:
45
- - - '>='
46
+ - - ! '>='
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
- none: false
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
50
51
  requirements:
51
- - - '>='
52
+ - - ! '>='
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
54
- none: false
55
55
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 1.8.24
58
- signing_key:
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.23
58
+ signing_key:
59
59
  specification_version: 3
60
- summary: Google Book/Magazine API integration for fetching the information for google books and magazines and book shelves also filter them. You can eaisly get most of the elements for a particular book and magazine or the books of a book shelf from the google book search. like :-(title,sub title,preview link,authors,publisher,publish date,buylink,downloadlink,version,ISBN information,ratings,...many more..Also you can get the google checkout link for that book/magazine
60
+ summary: Google Book/Magazine API integration for fetching the information for google
61
+ books and magazines and book shelves also filter them. You can eaisly get most of
62
+ the elements for a particular book and magazine or the books of a book shelf from
63
+ the google book search. like :-(title,sub title,preview link,authors,publisher,publish
64
+ date,buylink,downloadlink,version,ISBN information,ratings,...many more..Also you
65
+ can get the google checkout link for that book/magazine
61
66
  test_files: []
62
- has_rdoc: