google_book 0.3.1.1 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,18 +6,18 @@
6
6
 
7
7
  <div>
8
8
  <a href = "https://codeclimate.com/repos/51fa3a5356b102601a00d3e1/feed"><img src="https://codeclimate.com/repos/51fa3a5356b102601a00d3e1/badges/8db2d24d585c3d2ac1f1/gpa.png" /></a>
9
- <a href = "https://travis-ci.org/rajcybage/google_book"><img src= "https://travis-ci.org/rajcybage/google_book.png"/></a>
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
11
  </div>
12
12
 
13
- <h1>Google Book Api Integration For Books and Magazines</h1><br/>
13
+ <h1>Google Book Api Integration For Books and Magazines and Book Shelves</h1><br/>
14
14
  <p>You can use it in your web application as well as desktop application to fetch google books and magazines and also filter them.</p>
15
15
  <div>
16
16
  <h2>Installation</h2>
17
17
  <p>In Gemfile<br/>
18
18
  <code>gem 'google_book', git: 'git@github.com:rajcybage/google_book.git'</code><br/>
19
19
  <span><b>OR</b></span><br/>
20
- <code>gem 'google_book', '0.3.1.1'</code>
20
+ <code>gem 'google_book', '0.3.4'</code>
21
21
  </p>
22
22
  </div>
23
23
  <div>
@@ -53,7 +53,7 @@
53
53
  <code>b.book_info.get_all_titles #to get the all titles of your search book</code> <br/>
54
54
  <code>b.book_info.get_all_subtitles # to get all the subtitles of your search book</code>
55
55
  <code>b.total_count #get the search results count</code><br/>
56
- <code><b>b.price #get the book price with currency</b></code>
56
+
57
57
  </p>
58
58
 
59
59
 
@@ -76,8 +76,13 @@
76
76
  <code><b>b.books.first.version #get the version of the book</b></code><br/>
77
77
  <code><b>b.books.first.preview_link #get the first book preview link</b></code><br/>
78
78
  <code><b>b.books.first.info_link #get the first book information</b></code><br/>
79
+ <code><b>b.price #get the book price with currency</b></code><br/>
79
80
  <code><b>b.books.first.thumbnail_image #get the first book thumbnail image</b></code><br/>
80
81
  <code><b>b.books.first.small_thumbnail_link #get the first book thumbnail image</b></code><br/>
82
+ <h2>If you want to access google checkout for a particular book we can get the link for checkout</h2>
83
+ <code><b>b.books.first.google_checkout_link #get the first book direct google checkout</b></code><br/>
84
+ <h2>Want ISBN Information</h2><br/>
85
+ <code><b>b.books.first.ISBN_info #isbn info for first book it will return hash like {:ISBN_10 => "778545"}</b></code>
81
86
  </div>
82
87
 
83
88
 
@@ -135,5 +140,24 @@
135
140
  </p>
136
141
 
137
142
 
143
+ <div>
144
+ <h2>If You want to get the book shelves of a particular user</h2>
145
+ <div>
146
+ <b>
147
+ <code>bs=BookShelves.new("GOGLE_BOOKS_USER_ID")</code><br/>
148
+ <code>bs.bookshelves #all the book shelves of that user in a instance</code><br/>
149
+ <code>bs.bookshelves.first.title #the title of the books shelve first</code><br/>
150
+ <code>bs.bookshelves.first.self_link #the title of the books shelve first</code><br/>
151
+ </b>
152
+ </div>
153
+ <p>
154
+ <h2>If you want the books of a particular Book shelves</h2>
155
+ <b><code>bs.bookshelves.first.books#get all the books of that book shelves</code></b><br/>
156
+ <b><code>bs.bookshelves.first.books.first.get_title</code></b><br/>
157
+ <b>Now you can access all the methods of those books(ex:-get_title,preview_link....etc) </b>
158
+
159
+ </p>
160
+ </div>
161
+
138
162
  </body>
139
163
  </html>
data/lib/google_book.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  require "google_book/base.rb"
2
2
  require 'google_book/book_info.rb'
3
- require 'google_book/book_item.rb'
3
+ require 'google_book/book_item.rb'
4
+ require 'google_book/book_shelves.rb'
5
+ require 'google_book/uri.rb'
6
+ require 'google_book/book_shelf_item.rb'
@@ -2,11 +2,13 @@ require 'uri'
2
2
  require 'net/http'
3
3
  require 'openssl'
4
4
  require 'json'
5
+
5
6
  require_relative 'book_info.rb'
6
7
  require_relative 'book_item.rb'
7
-
8
+ require_relative 'uri.rb'
8
9
  module GoogleBook
9
10
  class Book
11
+ include URI
10
12
  attr_accessor :api_key, :total_count, :items, :books
11
13
 
12
14
  def initialize(api_key)
@@ -53,11 +55,6 @@ module GoogleBook
53
55
  return @books
54
56
  end
55
57
 
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
58
  def checking_filter_type(type)
62
59
  if type.nil?
63
60
  puts "How you want to filter your search?(example:1)?"
@@ -144,11 +141,11 @@ module GoogleBook
144
141
 
145
142
  def set_normal_url(api_key, type, search_param, main_url)
146
143
  case type
147
- when "download"
144
+ when "download"
148
145
  url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&download=epub&key=#{api_key}"
149
- when "magazine"
146
+ when "magazine"
150
147
  url = main_url+"?q=#{search_param.gsub(/\s+/, "+").strip}&printType=magazines&key=#{api_key}"
151
- else
148
+ else
152
149
  url = main_url+"?q=#{search_param.gsub(/\s+/, "").strip}+#{type}:keyes&key=#{api_key}"
153
150
  end
154
151
  return url
@@ -156,12 +153,9 @@ module GoogleBook
156
153
 
157
154
  def connect_google(key = nil,type = nil,search_param = nil,filter = nil)
158
155
  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)
156
+ uri=URI::Uri.new(uri)
163
157
  # response = Net::HTTP.get_response(uri)
164
- return response.body
158
+ return uri.response.body
165
159
  end
166
160
  end
167
161
  end
@@ -8,7 +8,7 @@ class BookItem
8
8
  @item = item
9
9
  end
10
10
 
11
- # get the title of the book
11
+ # get the title of the book
12
12
  def get_title
13
13
  @item[:item]["volumeInfo"]["title"]
14
14
  end
@@ -28,6 +28,11 @@ class BookItem
28
28
  @item[:item]["volumeInfo"]["publishedDate"]
29
29
  end
30
30
 
31
+ #The categories of the book
32
+ def categories
33
+ @item[:item]["volumeInfo"]["categories"]
34
+ end
35
+
31
36
  #The preview link
32
37
  def preview_link
33
38
  @item[:item]["volumeInfo"]["previewLink"]
@@ -63,9 +68,14 @@ class BookItem
63
68
  @item[:item]["accessInfo"]["webReaderLink"]
64
69
  end
65
70
 
66
- #text snippet description
71
+ #text snippet description
67
72
  def text_snippet_description
68
- @item[:item]["searchInfo"]["textSnippet"] unless @item[:item]["searchInfo"].nil?
73
+ @item[:item]["searchInfo"]["textSnippet"] unless @item[:item]["searchInfo"].nil?
74
+ end
75
+
76
+ #checkout link
77
+ def google_checkout_link
78
+ "https://play.google.com/store/books/details?id=#{@item[:item]["id"]}&rdid=book-#{@item[:item]["id"]}&rdot=1&source=gbs_atb"
69
79
  end
70
80
 
71
81
  #The rating of the book
@@ -75,7 +85,16 @@ class BookItem
75
85
 
76
86
  #The version of the book
77
87
  def version
78
- @item[:item]["volumeInfo"]["contentVersion"]
88
+ @item[:item]["volumeInfo"]["contentVersion"]
89
+ end
90
+
91
+ #ISBN information for the book
92
+ def ISBN_info
93
+ isbn_info = @item[:item]["volumeInfo"]["industryIdentifiers"].inject({}) do |result, isbn|
94
+ result[isbn["type"]] = isbn["identifier"]
95
+ result
96
+ end
97
+ isbn_info
79
98
  end
80
99
 
81
100
  #the total count of the rating
@@ -90,7 +109,7 @@ class BookItem
90
109
 
91
110
 
92
111
  #publish date
93
- def publish_date to
112
+ def publish_date
94
113
  @item[:item]["volumeInfo"]["publishedDate"]
95
114
  end
96
115
 
@@ -0,0 +1,31 @@
1
+ require_relative 'book_info.rb'
2
+ require_relative 'base.rb'
3
+ require_relative 'uri.rb'
4
+
5
+ class BookShelfItem
6
+ attr_accessor :item
7
+
8
+ def initialize(item)
9
+ @item = item
10
+ end
11
+
12
+
13
+ def title
14
+ @item[:item]["title"]
15
+ end
16
+
17
+ def self_link
18
+ @item[:item]["selfLink"]
19
+ end
20
+
21
+ def books
22
+ uri = @item[:item]["selfLink"] + "/volumes"
23
+ response = URI::Uri.new(URI(uri)).response
24
+ @book_items = JSON(response.body)["items"]
25
+ @books = []
26
+ @book_items.each do |item|
27
+ @books << BookItem.new(item: item)
28
+ end
29
+ return @books
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'book_info.rb'
2
+ require_relative 'base.rb'
3
+ require_relative 'uri.rb'
4
+ require_relative 'book_shelf_item.rb'
5
+ class BookShelves
6
+ include GoogleBook
7
+ include URI
8
+ attr_accessor :user_id, :uri, :items
9
+
10
+ def initialize(user_id, item = nil)
11
+ @user_id = user_id
12
+ @uri = "https://www.googleapis.com/books/v1/users/#{user_id}/bookshelves"
13
+ response = URI::Uri.new(URI(@uri)).response
14
+ unless response.body.nil? || JSON.parse(response.body)["items"].nil?
15
+ @items ||= JSON.parse(response.body)["items"].inject([]) do |result,item|
16
+ result << item
17
+ result
18
+ end
19
+ end
20
+ end
21
+
22
+ def bookshelves
23
+ @book_shelf_items = []
24
+ @items.each do |item|
25
+ @book_shelf_items << BookShelfItem.new(item: item)
26
+ end
27
+ return @book_shelf_items
28
+ end
29
+
30
+ end
@@ -0,0 +1,15 @@
1
+ require 'net/http'
2
+ module URI
3
+ class Uri
4
+ attr_reader :uri
5
+ attr_accessor :response
6
+
7
+ def initialize(uri)
8
+ @uri = uri
9
+ http = Net::HTTP.new(@uri.host, @uri.port)
10
+ http.use_ssl = true
11
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
12
+ @response = http.get(@uri.request_uri)
13
+ end
14
+ end
15
+ end
@@ -29,4 +29,51 @@ describe "book_item" do
29
29
  end
30
30
  end
31
31
 
32
+ describe "authors" do
33
+ it "should return perfect authors name" do
34
+ @book_items.first.authors.should =~ ["Daniel Keyes"]
35
+ end
36
+ end
37
+
38
+ describe "preview_link" do
39
+ it "should return perfect preview link" do
40
+ @book_items.first.preview_link.should == "http://books.google.com/books?id=_oG_iTxP1pIC&pg=PA283&dq=Flowers+inauthor:keyes&hl=&cd=1&source=gbs_api"
41
+ end
42
+ end
43
+
44
+ describe "info_link" do
45
+ it "should return perfect info link" do
46
+ @book_items.first.info_link.should == "http://books.google.com/books?id=_oG_iTxP1pIC&dq=Flowers+inauthor:keyes&hl=&source=gbs_api"
47
+ end
48
+ end
49
+
50
+ describe "version" do
51
+ it "should return perfect version" do
52
+ @book_items.first.version.should == "0.6.4.0.preview.3"
53
+ end
54
+ end
55
+
56
+ describe "google_checkout_link" do
57
+ it "should return perfect google checkout link" do
58
+ @book_items.first.google_checkout_link.should == "https://play.google.com/store/books/details?id=_oG_iTxP1pIC&rdid=book-_oG_iTxP1pIC&rdot=1&source=gbs_atb"
59
+ end
60
+ end
61
+
62
+ describe "rating" do
63
+ it "should return the rating of the book" do
64
+ @book_items.first.rating.should == 4.0
65
+ end
66
+ end
67
+
68
+ describe "publisher" do
69
+ it "should return right publisher name" do
70
+ @book_items.first.publisher.should == "Houghton Mifflin Harcourt"
71
+ end
72
+ end
73
+
74
+ describe "publish_date" do
75
+ it "should return the perfect published date" do
76
+ @book_items.first.publish_date.should == "2007-12-01"
77
+ end
78
+ end
32
79
  end
@@ -0,0 +1,35 @@
1
+ require_relative "../lib/google_book/book_shelves.rb"
2
+ require_relative "spec_helper.rb"
3
+
4
+ describe "book_shelves" do
5
+ let(:user_id){"109681907061774445744"}
6
+
7
+ it "should create a book shelves instance with a user id of google" do
8
+ BookShelves.new(user_id).items.should_not be_nil
9
+ BookShelves.new(user_id).items.should be_a_kind_of(Array)
10
+ end
11
+
12
+ it "should not create the book selves instance items if user id is wrong" do
13
+ BookShelves.new("10968190").items.should be_nil
14
+ end
15
+
16
+ it "should create a perfect url" do
17
+ BookShelves.new(user_id).uri.should == "https://www.googleapis.com/books/v1/users/109681907061774445744/bookshelves"
18
+ end
19
+
20
+
21
+ end
22
+
23
+
24
+ describe "bookshelves" do
25
+ let(:user_id){"109681907061774445744"}
26
+ before(:each) do
27
+ @boook_shelves = BookShelves.new(user_id)
28
+ end
29
+
30
+ it "should create book shelves items" do
31
+ @boook_shelves.bookshelves.should_not be_nil
32
+ @boook_shelves.bookshelves.should be_a_kind_of(Array)
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_book
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1.1
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-05 00:00:00.000000000 Z
12
+ date: 2013-08-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: rdasarminus@gmail.com
@@ -22,10 +22,14 @@ files:
22
22
  - Rakefile
23
23
  - spec/base_spec.rb
24
24
  - spec/book_item_spec.rb
25
+ - spec/book_shelves_spec.rb
25
26
  - lib/google_book.rb
26
27
  - lib/google_book/base.rb
27
28
  - lib/google_book/book_info.rb
28
29
  - lib/google_book/book_item.rb
30
+ - lib/google_book/book_shelves.rb
31
+ - lib/google_book/uri.rb
32
+ - lib/google_book/book_shelf_item.rb
29
33
  homepage: https://github.com/rajcybage/google_book
30
34
  licenses:
31
35
  - Copyright (c) Rajarshi Das. All rights reserved
@@ -50,6 +54,6 @@ rubyforge_project:
50
54
  rubygems_version: 1.8.24
51
55
  signing_key:
52
56
  specification_version: 3
53
- summary: Google Book API integration for fetching the information for google books and magazines also filter them. You can eaisly get most of the elements for a particular book and magazine from the google book search. like :-(title,sub title,preview link,authors,publisher,publish date,buylink,downloadlink,version,...many more
57
+ summary: Google Book 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
54
58
  test_files: []
55
59
  has_rdoc: