google_book 0.2.0 → 0.3.0.1

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'
5
- gem 'webmock'
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'rake'
5
+ gem 'webmock'
data/README.md CHANGED
@@ -14,7 +14,9 @@
14
14
  <div>
15
15
  <h2>Installation</h2>
16
16
  <p>In Gemfile
17
- <code>gem 'google_book', git: 'git@github.com:rajcybage/google_book.git'</code>
17
+ <code>gem 'google_book', git: 'git@github.com:rajcybage/google_book.git'</code><br/>
18
+ <span><b>OR</b></span><br/>
19
+ <code>gem 'google_book', '0.3.0.1'</code>
18
20
  </p>
19
21
  </div>
20
22
  <div>
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
data/lib/google_book.rb CHANGED
@@ -1,3 +1,3 @@
1
- require "google_book/base.rb"
2
- require 'google_book/book_info.rb'
1
+ require "google_book/base.rb"
2
+ require 'google_book/book_info.rb'
3
3
  require 'google_book/book_item.rb'
@@ -1,167 +1,167 @@
1
- require 'uri'
2
- require 'net/http'
3
- require 'openssl'
4
- require 'json'
5
- require_relative 'book_info.rb'
6
- require_relative 'book_item.rb'
7
-
8
- module GoogleBook
9
- class Book
10
- attr_accessor :api_key, :total_count, :items, :books
11
-
12
- def initialize(api_key)
13
- unless api_key.nil?
14
- @api_key = api_key[:api_key]
15
- else
16
- raise "Api key can not be nil. Please given your api_key"
17
- end
18
- end
19
-
20
- #Google books search
21
- def search(query,type = nil)
22
- checking_type(type)
23
- type = set_type(type) unless type.nil?
24
- if query.nil?
25
- puts 'Enter the text to search'
26
- text = gets
27
- end
28
- json = JSON.parse(connect_google(@api_key,type,query))
29
- @total_count = json["totalItems"]
30
- @items = json["items"]
31
- end
32
-
33
- #Google books filtration
34
- def filter(query, type = nil)
35
- checking_filter_type(type)
36
- filter_type = set_filter_type(type) unless type.nil?
37
- json = JSON.parse(connect_google(@api_key,nil,query,filter_type))
38
- @total_count = json["totalItems"]
39
- @items = json["items"]
40
- end
41
-
42
- #get all the books information
43
- def book_info
44
- BookInfo.new(items: @items)
45
- end
46
-
47
- #create all book instances
48
- def books
49
- @books = []
50
- @items.each do |item|
51
- @books << BookItem.new(item: item)
52
- end
53
- return @books
54
- end
55
-
56
- #use for rails application
57
- def api_key
58
- @api_key = YAML.load_file("#{Rails.root}/config/api_key_google_book.yml")[Rails.env]
59
- end
60
-
61
- def checking_filter_type(type)
62
- if type.nil?
63
- puts "How you want to filter your search?(example:1)?"
64
- puts "1)Free ebooks"
65
- puts "2)Paid ebboks"
66
- puts "3)Full text"
67
- f_type = gets
68
- else
69
- type = "1"
70
- end
71
- end
72
-
73
-
74
- def set_filter_type(type)
75
- case type.to_i
76
- when 1
77
- type = "free-ebooks"
78
- when 2
79
- type = "paid-ebooks"
80
- when 3
81
- type = "full"
82
- else
83
- type = "ebooks"
84
- end
85
- end
86
-
87
-
88
- def checking_type(type)
89
- if type.nil?
90
- puts "How you want to search?input only list number(ex:1)\n"
91
- puts "1)By Title\n"
92
- puts "2)By Author Name\n"
93
- puts "3)By Publisher\n"
94
- puts "4)By Subject\n"
95
- puts "5)By ISBN number:- \n"
96
- puts "6)Library of Congress Control Number\n"
97
- puts "7)By Online Computer Library Center number\n"
98
- puts "8)Want to search Downloadable book"
99
- puts "9)Want to search downloadable Magazines"
100
- type = gets
101
- else
102
- type = "1"
103
- end
104
- end
105
-
106
- def set_type(type)
107
- case type.to_i
108
- when 1
109
- type = "intitle"
110
- when 2
111
- type = "inauthor"
112
- when 3
113
- type = "inpublisher"
114
- when 4
115
- type = "subject"
116
- when 5
117
- type = "isbn"
118
- when 6
119
- type = "lccn"
120
- when 7
121
- type = "oclc"
122
- when 8
123
- type = "download"
124
- when 9
125
- type = "magazine"
126
- else
127
- type = "inauthor"
128
- end
129
- return type
130
- end
131
-
132
- def url_formation(api_key = nil,type = nil,search_param = nil, filter = nil)
133
- main_url = "https://www.googleapis.com/books/v1/volumes"
134
- if !type.nil?
135
- url = set_normal_url(api_key, type, search_param, main_url)
136
- elsif type.nil? && !filter.nil?
137
- url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&filter=#{filter}&key=#{@api_key}"
138
- else
139
- url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&key=#{@api_key}"
140
- end
141
- puts "#{url}"
142
- return URI(url)
143
- end
144
-
145
- def set_normal_url(api_key, type, search_param, main_url)
146
- case type
147
- when "download"
148
- url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&download=epub&key=#{api_key}"
149
- when "magazine"
150
- url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&printType=magazines&key=#{api_key}"
151
- else
152
- url = main_url+"?q=#{search_param.gsub(/\s+/, "").strip}+#{type}:keyes&key=#{api_key}"
153
- end
154
- return url
155
- end
156
-
157
- def connect_google(key = nil,type = nil,search_param = nil,filter = nil)
158
- uri = url_formation(key,type,search_param,filter)
159
- http = Net::HTTP.new(uri.host, uri.port)
160
- http.use_ssl = true
161
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
162
- response = http.get(uri.request_uri)
163
- # response = Net::HTTP.get_response(uri)
164
- return response.body
165
- end
166
- end
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'json'
5
+ require_relative 'book_info.rb'
6
+ require_relative 'book_item.rb'
7
+
8
+ module GoogleBook
9
+ class Book
10
+ attr_accessor :api_key, :total_count, :items, :books
11
+
12
+ def initialize(api_key)
13
+ unless api_key.nil?
14
+ @api_key = api_key[:api_key]
15
+ else
16
+ raise "Api key can not be nil. Please given your api_key"
17
+ end
18
+ end
19
+
20
+ #Google books search
21
+ def search(query,type = nil)
22
+ checking_type(type)
23
+ type = set_type(type) unless type.nil?
24
+ if query.nil?
25
+ puts 'Enter the text to search'
26
+ text = gets
27
+ end
28
+ json = JSON.parse(connect_google(@api_key,type,query))
29
+ @total_count = json["totalItems"]
30
+ @items = json["items"]
31
+ end
32
+
33
+ #Google books filtration
34
+ def filter(query, type = nil)
35
+ checking_filter_type(type)
36
+ filter_type = set_filter_type(type) unless type.nil?
37
+ json = JSON.parse(connect_google(@api_key,nil,query,filter_type))
38
+ @total_count = json["totalItems"]
39
+ @items = json["items"]
40
+ end
41
+
42
+ #get all the books information
43
+ def book_info
44
+ BookInfo.new(items: @items)
45
+ end
46
+
47
+ #create all book instances
48
+ def books
49
+ @books = []
50
+ @items.each do |item|
51
+ @books << BookItem.new(item: item)
52
+ end
53
+ return @books
54
+ end
55
+
56
+ #use for rails application
57
+ def api_key
58
+ @api_key = YAML.load_file("#{Rails.root}/config/api_key_google_book.yml")[Rails.env]
59
+ end
60
+
61
+ def checking_filter_type(type)
62
+ if type.nil?
63
+ puts "How you want to filter your search?(example:1)?"
64
+ puts "1)Free ebooks"
65
+ puts "2)Paid ebboks"
66
+ puts "3)Full text"
67
+ f_type = gets
68
+ else
69
+ type = "1"
70
+ end
71
+ end
72
+
73
+
74
+ def set_filter_type(type)
75
+ case type.to_i
76
+ when 1
77
+ type = "free-ebooks"
78
+ when 2
79
+ type = "paid-ebooks"
80
+ when 3
81
+ type = "full"
82
+ else
83
+ type = "ebooks"
84
+ end
85
+ end
86
+
87
+
88
+ def checking_type(type)
89
+ if type.nil?
90
+ puts "How you want to search?input only list number(ex:1)\n"
91
+ puts "1)By Title\n"
92
+ puts "2)By Author Name\n"
93
+ puts "3)By Publisher\n"
94
+ puts "4)By Subject\n"
95
+ puts "5)By ISBN number:- \n"
96
+ puts "6)Library of Congress Control Number\n"
97
+ puts "7)By Online Computer Library Center number\n"
98
+ puts "8)Want to search Downloadable book"
99
+ puts "9)Want to search downloadable Magazines"
100
+ type = gets
101
+ else
102
+ type = "1"
103
+ end
104
+ end
105
+
106
+ def set_type(type)
107
+ case type.to_i
108
+ when 1
109
+ type = "intitle"
110
+ when 2
111
+ type = "inauthor"
112
+ when 3
113
+ type = "inpublisher"
114
+ when 4
115
+ type = "subject"
116
+ when 5
117
+ type = "isbn"
118
+ when 6
119
+ type = "lccn"
120
+ when 7
121
+ type = "oclc"
122
+ when 8
123
+ type = "download"
124
+ when 9
125
+ type = "magazine"
126
+ else
127
+ type = "inauthor"
128
+ end
129
+ return type
130
+ end
131
+
132
+ def url_formation(api_key = nil,type = nil,search_param = nil, filter = nil)
133
+ main_url = "https://www.googleapis.com/books/v1/volumes"
134
+ if !type.nil?
135
+ url = set_normal_url(api_key, type, search_param, main_url)
136
+ elsif type.nil? && !filter.nil?
137
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&filter=#{filter}&key=#{@api_key}"
138
+ else
139
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&key=#{@api_key}"
140
+ end
141
+ puts "#{url}"
142
+ return URI(url)
143
+ end
144
+
145
+ def set_normal_url(api_key, type, search_param, main_url)
146
+ case type
147
+ when "download"
148
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&download=epub&key=#{api_key}"
149
+ when "magazine"
150
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&printType=magazines&key=#{api_key}"
151
+ else
152
+ url = main_url+"?q=#{search_param.gsub(/\s+/, "").strip}+#{type}:keyes&key=#{api_key}"
153
+ end
154
+ return url
155
+ end
156
+
157
+ def connect_google(key = nil,type = nil,search_param = nil,filter = nil)
158
+ uri = url_formation(key,type,search_param,filter)
159
+ http = Net::HTTP.new(uri.host, uri.port)
160
+ http.use_ssl = true
161
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
162
+ response = http.get(uri.request_uri)
163
+ # response = Net::HTTP.get_response(uri)
164
+ return response.body
165
+ end
166
+ end
167
167
  end
@@ -1,37 +1,37 @@
1
- require_relative 'base.rb'
2
- require_relative 'book_item.rb'
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].each do |item|
33
- @titles << item["volumeInfo"]["title"]
34
- end
35
- end
36
-
1
+ require_relative 'base.rb'
2
+ require_relative 'book_item.rb'
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].each do |item|
33
+ @titles << item["volumeInfo"]["title"]
34
+ end
35
+ end
36
+
37
37
  end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_book
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Rajarshi Das
8
- autorequire:
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
  date: 2013-07-30 00:00:00.000000000 Z
12
13
  dependencies: []
13
- description: Integrate the google book api into your app
14
+ description:
14
15
  email: rdasarminus@gmail.com
15
16
  executables: []
16
17
  extensions: []
@@ -26,9 +27,9 @@ files:
26
27
  - lib/google_book/book_info.rb
27
28
  - lib/google_book/book_item.rb
28
29
  homepage: https://github.com/rajcybage/google_book
29
- licenses: []
30
- metadata: {}
31
- post_install_message:
30
+ licenses:
31
+ - Copyright (c) Rajarshi Das. All rights reserved
32
+ post_install_message:
32
33
  rdoc_options: []
33
34
  require_paths:
34
35
  - lib
@@ -37,15 +38,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
38
  - - '>='
38
39
  - !ruby/object:Gem::Version
39
40
  version: '0'
41
+ none: false
40
42
  required_rubygems_version: !ruby/object:Gem::Requirement
41
43
  requirements:
42
44
  - - '>='
43
45
  - !ruby/object:Gem::Version
44
46
  version: '0'
47
+ none: false
45
48
  requirements: []
46
- rubyforge_project:
47
- rubygems_version: 2.0.3
48
- signing_key:
49
- specification_version: 4
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
50
53
  summary: Google Book API integration
51
54
  test_files: []
55
+ has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 34025d0e5be1f2a4b0ef1dd93f32d53af55f5899
4
- data.tar.gz: 88ea8dc02c2e0f6d780919a49df67c32695c0128
5
- SHA512:
6
- metadata.gz: bc827dacb2afeb540e7284cfd2db63fee4925c716bb2cc36688ddc05d6fb0b1f498cc0a47468b605d308c734d4e80f89c40db1e419ab4f8e119c7c6131396f7c
7
- data.tar.gz: 935404e9528281c8da1315174e2fe8eb634e0042ab1142dc921699aeaa82146163b0a4fa407e358769080726debbfa3c32ef13c499f5d99ba1c70a9d3284f1af