alexandrite 0.0.1 → 0.1.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1d0a59468bf1b22e33d17848c07d9af25172aadbc78723fbf014d42021bcd55
4
- data.tar.gz: ffb2f6b45788d233ebb91b601f1ea256ba21b54da4bad154e548f4e20bb9f59b
3
+ metadata.gz: daf4377dc5fb6c1b1b122236cdd76e760863a575bd6e1bd177d20d98aab92508
4
+ data.tar.gz: ce9bfcf98c1142b5e539b52189962779c2286705a9c361ba3da7bfa76b80ac81
5
5
  SHA512:
6
- metadata.gz: a706821501297809cad6e2c88c917ae8ea4fd276b5d9fde402b0fddf3aeac0094fdc13f42ac48edd551e397f0b7d34cadab6f3aed3ffa1c21abd1b8c02f7526c
7
- data.tar.gz: f448f181f9980721ef93df28392ffcd8210687033c8257b470cde53693b07c63015f14807a15a70ce649f45789034c2d10fb3e306e007e96d9f083b77dd6d64e
6
+ metadata.gz: 370748c92b5a9db2b9942fa8b8d779a2324a3a3c95c3114059d708346ff4ef6ee3afa8405a6f5aee58312bfef674e93b14b120d0ed4ef5a6c1cfdbaa4c55bc92
7
+ data.tar.gz: b04df9e530984ad698e71ea0057a60911480ad5c423d83ecea46413b8eea13af96e7db0fae3cb7d6c96e538b7d50e4457bd63ca04d6176ac5e8282f18f221a31
data/.gitignore CHANGED
@@ -22,3 +22,4 @@ tmp
22
22
  mkmf.log
23
23
  .idea
24
24
  .rvmrc
25
+ .dump
data/README.md CHANGED
@@ -1,12 +1,18 @@
1
- # gisbn GEM [![Build Status](https://travis-ci.org/eftakhairul/gisbn.svg?branch=master)](https://travis-ci.org/eftakhairul/gisbn) [![GitHub issues](https://img.shields.io/github/issues/eftakhairul/gisbn.svg)](https://github.com/eftakhairul/gisbn/issues) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/eftakhairul/gisbn/master/LICENSE.txt)
1
+ # Alexandrite GEM
2
+ [![Gem Version](https://badge.fury.io/rb/alexandrite.svg)](https://badge.fury.io/rb/alexandrite)
2
3
 
3
- It fetches book's information by ISBN number based on Google Book API.
4
+ Alexandrite is a gem that fetches book's data by ISBN number and other parameters from the [Google API](https://developers.google.com/books) and [OCLC API](http://classify.oclc.org/classify2/). It's intended to help librarians and bibliophiles to manage their bookshelves and classify their books.
4
5
 
5
- - Easy to get all information by ISBN
6
- - Structure data
6
+ With Alexandrite, it's
7
7
 
8
- You don't have to call manually Google API with ISBN number. This gem will do everything for you.
8
+ - Easy to get all information by ISBN and other parameters
9
+ - Structure data
10
+
11
+ ## Features
9
12
 
13
+ - Retrieves Book data from Google API and OCLC API
14
+ - Suggest a Dewey Decimal Classification or a Library of Congress Classification with OCLC Data.
15
+ - Add data to a virtual collection
10
16
 
11
17
 
12
18
  ### Version
@@ -14,6 +20,7 @@ You don't have to call manually Google API with ISBN number. This gem will do ev
14
20
 
15
21
 
16
22
  ### Installation
23
+
17
24
  Add this line to your application's Gemfile:
18
25
 
19
26
  ```ruby
@@ -32,9 +39,13 @@ Or install it yourself as globally:
32
39
  gem install alexandrite
33
40
  ```
34
41
 
42
+ ## Usage
43
+
44
+ Currently, Alexandrite is divided on four modules: Alexandrite, Alexandrite::Book, Alexandrite::GoogleAPI, and AlexandriteOCLCAPI. Require Alexandrite if you want to use an integration of all the modules, or use each module separately.
45
+
35
46
 
36
47
  ## Examples
37
- book = Gisbn::Book.new "0262033844", "AIzaSyDKepjfaVBRcgsnPALw5s2UNyfOk-1FHUU", "ca"
48
+ book = Alexandrite.create_book("0262033844")
38
49
 
39
50
  book.title
40
51
  #=> "Introduction to Algorithms"
@@ -52,17 +63,7 @@ gem install alexandrite
52
63
  #=> 0262033844
53
64
 
54
65
  book.isbn_13
55
- #=> 9780262033848
56
-
57
- book.thumbnail
58
- #=> http://books.google.com/books/content?id=i-bUBQAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api
59
-
60
- book.preview
61
- #=> http://books.google.ca/books?id=i-bUBQAAQBAJ&printsec=frontcover&dq=isbn:0262033844&hl=&cd=1&source=gbs_api
62
-
63
-
64
- book.gisbn.isbn = 9780321573513
65
- book.fetch.title => "Algorithms"
66
+ #=> 978026203384
66
67
 
67
68
 
68
69
 
@@ -100,11 +101,12 @@ Want to contribute? Great!
100
101
 
101
102
  Author
102
103
  -----------
103
- [Eftakhairul Islam](https://eftakhairul.com)
104
+ [J. P. Pérez-Tejada](https://mx.linkedin.com/in/juanpaulopereztejada)
104
105
 
105
- Contributors
106
+ Gem inspired on GISBN. Special greetings to:
106
107
  -----------
107
108
  [Matt Seeberger](https://github.com/thebeardedgeek)
109
+ [Eftakhairul Islam](https://eftakhairul.com)
108
110
 
109
111
  License
110
112
  ----
data/bookshelf.dump ADDED
@@ -0,0 +1,10 @@
1
+ o:Alexandrite::Bookshelf:@collection_nameI"Test Bookshelf:ET:@book_collection[
2
+ I"Google API;T; I"Pedro Páramo;T; [I"Juan Rulfo;TI"Josephine Sacabo;TI"Margaret Sayers Peden;T;
3
+ @ ; I".Todo queda en familia (All in the Family);T; [I"Dona Herweck Rice;T;
4
+ @ ; I"Todo queda en familia;T; [I"Cristina Padilla Dieste;T;
5
+ @ ; 0; 0;
6
+ o; ;
7
+ @ ; 0; 0;
8
+ o; ;
9
+ @ ; I" Cómo llegar a ser japonés;T; [I"Ramón Illán Bacca;T;
10
+ @ ; I"#Sociedad, naturaleza y turismo;T; I"�Seminario Internacional Nuevas Alternativas del Turismo (4th : 2010 : Universidad de Guadalajara. Centro Universitario de la Costa) | Arnáiz Burne, Stella Maris [Author] | Virgen Aguilar, Carlos Rogelio [Author];T;
data/data.dump ADDED
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Alexandrite
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0-alpha'
5
5
  end
data/lib/alexandrite.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'alexandrite_books'
3
+ require_relative 'alexandrite_book'
4
4
  require_relative 'alexandrite_google'
5
5
  require_relative 'alexandrite_oclc'
6
6
  require_relative 'error_type/errors'
@@ -20,8 +20,9 @@ module Alexandrite
20
20
  end
21
21
 
22
22
  # @return [Alexandrite::Book]
23
- def self.create_book(isbn)
24
- volume_info = get_volume_info(isbn)
23
+ def self.create_from_google(key, query)
24
+ volume_info = get_volume_info(key, query)
25
+
25
26
  Alexandrite::Book.new(volume_info)
26
27
  end
27
28
  end
@@ -38,7 +39,7 @@ module Alexandrite
38
39
  end
39
40
 
40
41
  # @return [Alexandrite::Book]
41
- def self.create_book(type, identifier)
42
+ def self.create_from_oclc(type, identifier)
42
43
  query = Alexandrite::OCLC.new(type, identifier)
43
44
  response_code = get_response_code(query.result)
44
45
 
@@ -56,28 +57,30 @@ module Alexandrite
56
57
  end
57
58
 
58
59
  def create_book(key, query)
59
- book = API[:google].create_book(query)
60
- return API[:oclc].create_book(key, query) if book.error_message
60
+ book = API[:google].create_from_google(key, query)
61
+ return API[:oclc].create_from_oclc(key, query) if book.error_message
61
62
 
62
63
  book
63
64
  end
64
65
 
65
- # @param isbns [Array]
66
- # @return [Nil]
67
- def bulk_create(isbns)
68
- isbns.each do |isbn|
69
- volume_info = volume_info(isbn)
70
- book = Alexandrite::Book.new(volume_info)
71
- add_to_collection(book)
66
+ # @param key [String]
67
+ # @param data [Array<String>]
68
+ # @return [Array<Alexandrite::Books]
69
+ def bulk_create(key, data)
70
+ bookshelf = []
71
+ data.each do |query|
72
+ book = create_book(key, query)
73
+ bookshelf << book
72
74
  end
73
- nil
75
+
76
+ bookshelf
74
77
  end
75
78
 
76
79
  private
77
80
 
78
- def get_volume_info(isbn)
79
- query = search_by(:isbn, isbn)
80
- return query[:books].first[:volume_info] unless query[:error_message]
81
+ def get_volume_info(key, query)
82
+ query = search_by(key, query)
83
+ return query[:books].first['volumeInfo'] unless query[:error_message]
81
84
 
82
85
  query
83
86
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'alexandrite'
4
+ require 'nokogiri'
4
5
 
5
6
  module Alexandrite
6
7
  # Create a book objects
@@ -1,15 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'alexandrite'
4
- require_relative 'book'
4
+ require_relative 'alexandrite_book'
5
+ require_relative 'helpers/file_handler'
5
6
 
6
7
  # Create, Read, Update and Delete books in a book collection
7
8
  module Alexandrite
8
9
  # Create a collection of books
9
10
  class Bookshelf
10
- def initialize
11
- @book_collection = []
11
+ extend Alexandrite::Helpers::FileHandler
12
+
13
+ @@library = {}
14
+
15
+ attr_accessor :book_collection
16
+
17
+ attr_reader :collection_name
18
+
19
+ def initialize(collection_name, books = nil)
20
+ @collection_name = collection_name.to_sym
21
+ @book_collection = [books]
22
+ end
23
+
24
+ def save_bookshelf(file_path)
25
+ save(file_path, self)
26
+ end
27
+
28
+ def self.add_bookshelf(file_path)
29
+ bookshelf = open(file_path)
30
+ @@library[bookshelf.collection_name.to_sym] = bookshelf if bookshelf.instance_of?(Alexandrite::Bookshelf)
31
+ end
32
+
33
+ def self.charge_library(file_path)
34
+ bookshelves = open(file_path)
35
+ @@library = bookshelves if bookshelves.all?(Alexandrite::Bookshelf)
36
+ end
37
+
38
+ def self.save_library(file_path)
39
+ save(file_path, @@library)
40
+ end
41
+
42
+ def self.show_library
43
+ @@library
44
+ end
45
+
46
+ def self.find_bookshelf(bookshelf_name)
47
+ query = @@library[bookshelf_name.to_sym]
48
+ return "Bookshelf wasn't found. Check collection name" if query.nil?
49
+
50
+ query
12
51
  end
13
52
  end
14
- def add_book(book) = @book_collection << book if book.instance_of?(Alexandrite::Book)
15
53
  end
@@ -50,6 +50,7 @@ module Alexandrite
50
50
 
51
51
  private
52
52
 
53
+ # @return [Integer]
53
54
  def get_response_code(result) = result.css('response').attribute('code').value.to_i
54
55
 
55
56
  def get_owis(result, length)
@@ -83,6 +84,7 @@ module Alexandrite
83
84
 
84
85
  def create_new_book(query)
85
86
  volume_info = get_book_data(query.result)
87
+
86
88
  Alexandrite::Book.new(volume_info)
87
89
  end
88
90
 
@@ -94,9 +96,9 @@ module Alexandrite
94
96
  end
95
97
 
96
98
  def handle_error_creating_book(query)
97
- raise ErrorType::DataNotFound, response_cases(query, 0, 'none')
99
+ raise ErrorType::DataNotFound, response_cases(query.result, 0, 'none')
98
100
  rescue StandardError => e
99
- Alexandrite::Book.new('error_message' => e.message)
101
+ Alexandrite::Book.new({ :error_message => e.message, 'origin' => 'OCLC API' })
100
102
  end
101
103
 
102
104
  # @param [Nokogiri::XML] result
@@ -104,7 +106,7 @@ module Alexandrite
104
106
  # @param [String] mode Possible: 'ddc' or 'lcc'
105
107
  # @return [String]
106
108
  def response_cases(result, length, mode)
107
- code = get_response_code(result).to_i
109
+ code = get_response_code(result)
108
110
  case code
109
111
  when 0
110
112
  get_classification(result, mode)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alexandrite
4
+ module Helpers
5
+ # Save files of books
6
+ module FileHandler
7
+ # @param [String] file_name
8
+ # @param [Array<Object>] data
9
+ def save(file_name, data)
10
+ File.open(file_name, 'w') { |f| f.write Marshal.dump(data) }
11
+ end
12
+
13
+ def open(file_name)
14
+ file = File.open(file_name)
15
+ Marshal.load(file)
16
+ end
17
+ end
18
+ end
19
+ end
data/test_library.dump ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexandrite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. P. Pérez-Tejada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-21 00:00:00.000000000 Z
11
+ date: 2023-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -152,13 +152,16 @@ files:
152
152
  - README.md
153
153
  - Rakefile
154
154
  - alexandrite.gemspec
155
+ - bookshelf.dump
156
+ - data.dump
155
157
  - lib/alexandrite.rb
156
158
  - lib/alexandrite/version.rb
157
- - lib/alexandrite_books.rb
159
+ - lib/alexandrite_book.rb
158
160
  - lib/alexandrite_bookshelf.rb
159
161
  - lib/alexandrite_google.rb
160
162
  - lib/alexandrite_oclc.rb
161
163
  - lib/error_type/errors.rb
164
+ - lib/helpers/file_handler.rb
162
165
  - lib/helpers/format.rb
163
166
  - lib/helpers/validation.rb
164
167
  - spec/alexandrite_spec.rb
@@ -166,6 +169,7 @@ files:
166
169
  - spec/helpers/format_spec.rb
167
170
  - spec/spec_helper.rb
168
171
  - spec/support/vcr_setup.rb
172
+ - test_library.dump
169
173
  homepage: https://github.com/maclenn77/alexandrite
170
174
  licenses:
171
175
  - MIT
@@ -181,9 +185,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
185
  version: '3.0'
182
186
  required_rubygems_version: !ruby/object:Gem::Requirement
183
187
  requirements:
184
- - - ">="
188
+ - - ">"
185
189
  - !ruby/object:Gem::Version
186
- version: '0'
190
+ version: 1.3.1
187
191
  requirements: []
188
192
  rubygems_version: 3.3.3
189
193
  signing_key: