alexandrite 0.1.0.pre.alpha → 0.1.1.pre.alpha
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.
- checksums.yaml +4 -4
- data/lib/alexandrite/version.rb +1 -1
- data/lib/alexandrite.rb +12 -20
- data/lib/alexandrite_book_data.rb +57 -0
- data/lib/alexandrite_bookshelf.rb +1 -1
- data/lib/alexandrite_google.rb +7 -0
- data/lib/alexandrite_oclc.rb +4 -5
- data/lib/helpers/file_handler.rb +1 -1
- metadata +3 -3
- data/lib/alexandrite_book.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b04594e2817421efbc7843faddd9ea5b6bee3ff093d52c4328d3fa1b76680905
|
4
|
+
data.tar.gz: 6ec96b26a30b7609dcdf2da25ce6ccaf38279d3fb232da07327e6699b39661ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b028aba504cc9e5f14deac610c81eb1c18066b90a563f0d9486cd6f06ca4b3a1be803333417fd0c06240be1db021842d334088695d512d06ea873dbd4f126b08
|
7
|
+
data.tar.gz: 66563405941ad6bd600b26466d229eb93929de988848547305322e878d3642df4da7cba555eafa3f22c055ea5c07314a85bc5028c70d352c5479a535324d8e06
|
data/lib/alexandrite/version.rb
CHANGED
data/lib/alexandrite.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'alexandrite_book_data'
|
4
4
|
require_relative 'alexandrite_google'
|
5
5
|
require_relative 'alexandrite_oclc'
|
6
6
|
require_relative 'error_type/errors'
|
@@ -8,37 +8,38 @@ require_relative 'error_type/errors'
|
|
8
8
|
# Main gem methods for creating books from ISBN
|
9
9
|
module Alexandrite
|
10
10
|
include ErrorType
|
11
|
+
include Alexandrite::BookData
|
11
12
|
|
12
13
|
# Get and Process data from Google API
|
13
14
|
class Google
|
15
|
+
include Alexandrite
|
14
16
|
extend Alexandrite::GoogleAPI
|
15
17
|
|
16
18
|
attr_reader :result
|
17
19
|
|
18
20
|
def initialize(key, query)
|
19
|
-
@result =
|
21
|
+
@result = search_with(key, query)
|
20
22
|
end
|
21
23
|
|
22
|
-
# @return [Alexandrite::
|
24
|
+
# @return [Alexandrite::BookData]
|
23
25
|
def self.create_from_google(key, query)
|
24
|
-
|
25
|
-
|
26
|
-
Alexandrite::Book.new(volume_info)
|
26
|
+
Alexandrite::BookData.create_data(get_volume_info(key, query))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
# Get and Process data from OCLC API
|
31
31
|
class OCLC
|
32
|
+
include Alexandrite
|
32
33
|
extend Alexandrite::OCLCAPI
|
33
34
|
|
34
35
|
attr_reader :result
|
35
36
|
|
36
37
|
# return [Alexandrite::OCLC]
|
37
38
|
def initialize(key, query, api: :oclc)
|
38
|
-
@result =
|
39
|
+
@result = search_with(key, query, api: api)
|
39
40
|
end
|
40
41
|
|
41
|
-
# @return [Alexandrite::
|
42
|
+
# @return [Alexandrite::BookData]
|
42
43
|
def self.create_from_oclc(type, identifier)
|
43
44
|
query = Alexandrite::OCLC.new(type, identifier)
|
44
45
|
response_code = get_response_code(query.result)
|
@@ -52,20 +53,20 @@ module Alexandrite
|
|
52
53
|
oclc: Alexandrite::OCLC
|
53
54
|
}.freeze
|
54
55
|
|
55
|
-
def
|
56
|
+
def search_with(key, query, api: :google)
|
56
57
|
API[api].search_by(key, query)
|
57
58
|
end
|
58
59
|
|
59
60
|
def create_book(key, query)
|
60
61
|
book = API[:google].create_from_google(key, query)
|
61
|
-
return API[:oclc].create_from_oclc(key, query) if book
|
62
|
+
return API[:oclc].create_from_oclc(key, query) if book[:error_message]
|
62
63
|
|
63
64
|
book
|
64
65
|
end
|
65
66
|
|
66
67
|
# @param key [String]
|
67
68
|
# @param data [Array<String>]
|
68
|
-
# @return [Array<Alexandrite::
|
69
|
+
# @return [Array<Alexandrite::BookData]
|
69
70
|
def bulk_create(key, data)
|
70
71
|
bookshelf = []
|
71
72
|
data.each do |query|
|
@@ -75,13 +76,4 @@ module Alexandrite
|
|
75
76
|
|
76
77
|
bookshelf
|
77
78
|
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def get_volume_info(key, query)
|
82
|
-
query = search_by(key, query)
|
83
|
-
return query[:books].first['volumeInfo'] unless query[:error_message]
|
84
|
-
|
85
|
-
query
|
86
|
-
end
|
87
79
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'alexandrite'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module Alexandrite
|
7
|
+
# Create a book objects
|
8
|
+
module BookData
|
9
|
+
# @param volume_info [Hash]
|
10
|
+
# @return [Hash]
|
11
|
+
def self.create_data(volume_info)
|
12
|
+
data = add_basic_values(volume_info)
|
13
|
+
data[:data_source] = add_origin(volume_info)
|
14
|
+
data = add_industry_identifiers(volume_info, data)
|
15
|
+
data[:error_message] = volume_info[:error_message]
|
16
|
+
|
17
|
+
data
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.add_basic_values(volume_info)
|
21
|
+
{
|
22
|
+
title: volume_info['title'],
|
23
|
+
authors: volume_info['authors'],
|
24
|
+
published_date: volume_info['publisher'],
|
25
|
+
page_count: volume_info['pageCount'],
|
26
|
+
description: volume_info['description'],
|
27
|
+
categories: volume_info['categories'],
|
28
|
+
language: volume_info['language']
|
29
|
+
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [Hash] volume_info
|
34
|
+
# @return [String]
|
35
|
+
def self.add_origin(volume_info) = volume_info['origin'] || 'Google API'
|
36
|
+
|
37
|
+
# @param [Hash] volume_info
|
38
|
+
# @param [Hash] data
|
39
|
+
# @return [NilClass]
|
40
|
+
def self.add_industry_identifiers(volume_info, data)
|
41
|
+
return data unless volume_info[:error_message].nil?
|
42
|
+
|
43
|
+
if data[:data_source] == 'OCLC API'
|
44
|
+
data[:isbn10] = volume_info['ISBN_10']
|
45
|
+
data[:isbn13] = volume_info['ISBN_13']
|
46
|
+
return data
|
47
|
+
end
|
48
|
+
|
49
|
+
volume_info['industryIdentifiers'].each do |identifier|
|
50
|
+
data[:isbn10] = identifier['identifier'] if identifier['type'] == 'ISBN_10'
|
51
|
+
data[:isbn13] = identifier['identifier'] if identifier['type'] == 'ISBN_13'
|
52
|
+
end
|
53
|
+
|
54
|
+
data
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/alexandrite_google.rb
CHANGED
@@ -62,6 +62,13 @@ module Alexandrite
|
|
62
62
|
|
63
63
|
private
|
64
64
|
|
65
|
+
def get_volume_info(key, query)
|
66
|
+
query = search_by(key, query)
|
67
|
+
return query[:books].first['volumeInfo'] unless query[:error_message]
|
68
|
+
|
69
|
+
query
|
70
|
+
end
|
71
|
+
|
65
72
|
def zero_results?(response_body) = response_body['totalItems'].zero?
|
66
73
|
|
67
74
|
def process_response(response)
|
data/lib/alexandrite_oclc.rb
CHANGED
@@ -17,6 +17,7 @@ module Alexandrite
|
|
17
17
|
include Nokogiri
|
18
18
|
include Alexandrite::Helpers::Format
|
19
19
|
include Alexandrite::Helpers::Validation
|
20
|
+
include Alexandrite::BookData
|
20
21
|
|
21
22
|
BASE_URL = 'http://classify.oclc.org/classify2/Classify?'
|
22
23
|
|
@@ -83,22 +84,20 @@ module Alexandrite
|
|
83
84
|
end
|
84
85
|
|
85
86
|
def create_new_book(query)
|
86
|
-
|
87
|
-
|
88
|
-
Alexandrite::Book.new(volume_info)
|
87
|
+
Alexandrite::BookData.create_data(get_book_data(query.result))
|
89
88
|
end
|
90
89
|
|
91
90
|
def retry_create_new_book(query)
|
92
91
|
owi = get_owis(query.result, 1)[0]
|
93
92
|
new_query = Alexandrite::OCLC.new('owi', owi)
|
94
93
|
volume_info = get_book_data(new_query.result)
|
95
|
-
Alexandrite::
|
94
|
+
Alexandrite::BookData.create_data(volume_info)
|
96
95
|
end
|
97
96
|
|
98
97
|
def handle_error_creating_book(query)
|
99
98
|
raise ErrorType::DataNotFound, response_cases(query.result, 0, 'none')
|
100
99
|
rescue StandardError => e
|
101
|
-
Alexandrite::
|
100
|
+
Alexandrite::BookData.create_data({ :error_message => e.message, 'origin' => 'OCLC API' })
|
102
101
|
end
|
103
102
|
|
104
103
|
# @param [Nokogiri::XML] result
|
data/lib/helpers/file_handler.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexandrite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1.pre.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J. P. Pérez-Tejada
|
@@ -156,7 +156,7 @@ files:
|
|
156
156
|
- data.dump
|
157
157
|
- lib/alexandrite.rb
|
158
158
|
- lib/alexandrite/version.rb
|
159
|
-
- lib/
|
159
|
+
- lib/alexandrite_book_data.rb
|
160
160
|
- lib/alexandrite_bookshelf.rb
|
161
161
|
- lib/alexandrite_google.rb
|
162
162
|
- lib/alexandrite_oclc.rb
|
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
189
|
- !ruby/object:Gem::Version
|
190
190
|
version: 1.3.1
|
191
191
|
requirements: []
|
192
|
-
rubygems_version: 3.3.
|
192
|
+
rubygems_version: 3.3.7
|
193
193
|
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: Tools for fetching books data from Google and OCLC
|
data/lib/alexandrite_book.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'alexandrite'
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
module Alexandrite
|
7
|
-
# Create a book objects
|
8
|
-
class Book
|
9
|
-
attr_accessor :title, :authors, :publisher, :published_date, :page_count, :description, :categories, :language,
|
10
|
-
:country, :isbn10, :isbn13, :error_message, :ddc, :lcc, :suggested_classifications
|
11
|
-
|
12
|
-
# @param volume_info [Hash]
|
13
|
-
# @return [Alexandrite::Books]
|
14
|
-
def initialize(volume_info)
|
15
|
-
add_origin(volume_info)
|
16
|
-
add_basic_values(volume_info)
|
17
|
-
add_industry_identifiers(volume_info, @origin)
|
18
|
-
@error_message = volume_info[:error_message]
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.collection = @@collection
|
22
|
-
|
23
|
-
def self.add_to_collection(book)
|
24
|
-
@@collection.push(book)
|
25
|
-
end
|
26
|
-
|
27
|
-
# @param [String] ddc_code
|
28
|
-
# @return [NilClass]
|
29
|
-
def add_ddc(ddc_code) = @ddc = ddc_code
|
30
|
-
|
31
|
-
# @param [String] lcc_code
|
32
|
-
# @return [NilClass]
|
33
|
-
def add_lcc(lcc_code) = @lcc = lcc_code
|
34
|
-
|
35
|
-
# @param [Array<String>] suggestions
|
36
|
-
# @return [NilClass]
|
37
|
-
def add_classification_suggested(suggestions) = @suggested_classifications = suggestions
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def add_basic_values(volume_info)
|
42
|
-
@title = volume_info['title']
|
43
|
-
@authors = volume_info['authors']
|
44
|
-
@publisher = volume_info['publisher']
|
45
|
-
@published_date = volume_info['publishedDate']
|
46
|
-
@page_count = volume_info['pageCount']
|
47
|
-
@description = volume_info['description']
|
48
|
-
@categories = volume_info['categories']
|
49
|
-
@language = volume_info['language']
|
50
|
-
end
|
51
|
-
|
52
|
-
# @param [Hash] volume_info
|
53
|
-
# @return [String]
|
54
|
-
def add_origin(volume_info) = @origin = volume_info['origin'] || 'Google API'
|
55
|
-
|
56
|
-
# @param [Hash] volume_info
|
57
|
-
# @param [String] origin
|
58
|
-
# @return [NilClass]
|
59
|
-
def add_industry_identifiers(volume_info, origin)
|
60
|
-
return nil unless volume_info[:error_message].nil?
|
61
|
-
|
62
|
-
if origin == 'OCLC API'
|
63
|
-
@isbn10 = volume_info['ISBN_10']
|
64
|
-
@isbn13 = volume_info['ISBN_13']
|
65
|
-
return
|
66
|
-
end
|
67
|
-
|
68
|
-
volume_info['industryIdentifiers'].each do |identifier|
|
69
|
-
@isbn10 = identifier['identifier'] if identifier['type'] == 'ISBN_10'
|
70
|
-
@isbn13 = identifier['identifier'] if identifier['type'] == 'ISBN_13'
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|