alexandrite 0.1.1.pre.alpha → 0.1.2.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_book_data.rb +7 -5
- data/lib/alexandrite_oclc.rb +18 -16
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1904340a4469d9f82f1d42d16a58cdd7a63e0a23711ed040d20c63648164d4fc
|
|
4
|
+
data.tar.gz: a6e306d3416403661661ed1bee823d43bd332f446cb1e1ee61e1529c8f5362aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40f3d5f4f06ce58a3f99156f4a26e399cb8b3e1c852a34de923947aa1b5cad75f39a2d75cc39ed86fa2a765292318ec890e5acc201fa922d861b91618e4d1d96
|
|
7
|
+
data.tar.gz: 0fc0a88be83ab17e5753cd389dac7de71ecffaa6915e59d7047a5dd4dc547b84a7fb0a2231be8e22fd911cf162945ad2fa16dafa531af82b0891f6539e22d3eb
|
data/lib/alexandrite/version.rb
CHANGED
|
@@ -45,12 +45,14 @@ module Alexandrite
|
|
|
45
45
|
data[:isbn13] = volume_info['ISBN_13']
|
|
46
46
|
return data
|
|
47
47
|
end
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
begin
|
|
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
|
+
rescue NoMethodError
|
|
54
|
+
data
|
|
52
55
|
end
|
|
53
|
-
|
|
54
56
|
data
|
|
55
57
|
end
|
|
56
58
|
end
|
data/lib/alexandrite_oclc.rb
CHANGED
|
@@ -31,28 +31,37 @@ module Alexandrite
|
|
|
31
31
|
Nokogiri::XML(conn.get(search).body)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def extract_value(attribute)
|
|
35
|
+
return nil unless attribute.respond_to?(:value)
|
|
36
|
+
|
|
37
|
+
attribute.value
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def extract_nokogiri_data(document, children, attribute)
|
|
41
|
+
extract_value(document.css(children).attribute(attribute))
|
|
42
|
+
end
|
|
43
|
+
|
|
34
44
|
def get_book_data(result)
|
|
35
45
|
isbn = result.css('input').children.text
|
|
36
46
|
isbn_type = define_isbn_type(isbn)
|
|
37
47
|
{
|
|
38
48
|
'origin' => 'OCLC API',
|
|
39
|
-
'title' => result
|
|
40
|
-
'authors' => result
|
|
41
|
-
'ddc' => result
|
|
49
|
+
'title' => extract_nokogiri_data(result, 'work', 'title'),
|
|
50
|
+
'authors' => extract_nokogiri_data(result, 'work', 'author'),
|
|
51
|
+
'ddc' => extract_nokogiri_data(result, 'mostPopular', 'nsfa'),
|
|
42
52
|
isbn_type => isbn
|
|
43
53
|
}
|
|
44
54
|
end
|
|
45
55
|
|
|
46
56
|
def recommend_classification(key, query, length = 5, mode: 'ddc')
|
|
47
57
|
results = search_by(key, query)
|
|
48
|
-
|
|
49
58
|
response_cases(results, length, mode)
|
|
50
59
|
end
|
|
51
60
|
|
|
52
61
|
private
|
|
53
62
|
|
|
54
63
|
# @return [Integer]
|
|
55
|
-
def get_response_code(result) = result
|
|
64
|
+
def get_response_code(result) = extract_nokogiri_data(result, 'response', 'code').to_i
|
|
56
65
|
|
|
57
66
|
def get_owis(result, length)
|
|
58
67
|
owis = []
|
|
@@ -87,15 +96,8 @@ module Alexandrite
|
|
|
87
96
|
Alexandrite::BookData.create_data(get_book_data(query.result))
|
|
88
97
|
end
|
|
89
98
|
|
|
90
|
-
def
|
|
91
|
-
|
|
92
|
-
new_query = Alexandrite::OCLC.new('owi', owi)
|
|
93
|
-
volume_info = get_book_data(new_query.result)
|
|
94
|
-
Alexandrite::BookData.create_data(volume_info)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def handle_error_creating_book(query)
|
|
98
|
-
raise ErrorType::DataNotFound, response_cases(query.result, 0, 'none')
|
|
99
|
+
def handle_error_creating_book
|
|
100
|
+
raise ErrorType::DataNotFound, yield
|
|
99
101
|
rescue StandardError => e
|
|
100
102
|
Alexandrite::BookData.create_data({ :error_message => e.message, 'origin' => 'OCLC API' })
|
|
101
103
|
end
|
|
@@ -129,9 +131,9 @@ module Alexandrite
|
|
|
129
131
|
when 0, 2
|
|
130
132
|
create_new_book(query)
|
|
131
133
|
when 4
|
|
132
|
-
|
|
134
|
+
handle_error_creating_book { 'Not found exact item. Check coincidences' }
|
|
133
135
|
else
|
|
134
|
-
handle_error_creating_book(query)
|
|
136
|
+
handle_error_creating_book { response_cases(query.result, 0, 'none') }
|
|
135
137
|
end
|
|
136
138
|
end
|
|
137
139
|
end
|
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.1.
|
|
4
|
+
version: 0.1.2.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-
|
|
11
|
+
date: 2023-01-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -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.
|
|
192
|
+
rubygems_version: 3.4.5
|
|
193
193
|
signing_key:
|
|
194
194
|
specification_version: 4
|
|
195
195
|
summary: Tools for fetching books data from Google and OCLC
|