accessible_books 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/accessible-books.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e899dda6340210fab2002f7c225e909b47f08df5c4e6f43128ea2218691d849
|
4
|
+
data.tar.gz: '0787e923fd55ef18b39a46a6117d570ce6e0c7a2c2795edd3b2e84f3fe054283'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2029c3b233cedbc3b6d174dd37790124f749ab791e245f9b560ea23cc23550103fe881f27bf482c74f2dcfc2f3aafb79e0b0ae13e994681cd52c145ceb5db47
|
7
|
+
data.tar.gz: 95285cc6bf315754bfb7ad6b3528fe377a3dec58186d8750053de82ba64e2f700d49b5c0cc57177bee1e939c5293dae00b9258e161ba4114664397831a0b2a8f
|
data/lib/accessible-books.rb
CHANGED
@@ -5,6 +5,30 @@ require 'nokogiri'
|
|
5
5
|
module AccessibleBooks
|
6
6
|
TARHEEL_REGEX = /https?:\/\/tarheelreader.org\/.+\/.+\/.+\/(.+)\//
|
7
7
|
|
8
|
+
def self.search(q, locale='en')
|
9
|
+
tarheel_prefix = "https://tarheelreader.org" #ENV['TARHEEL_PROXY'] || "https://images.weserv.nl/?url=tarheelreader.org"
|
10
|
+
list = []
|
11
|
+
url = "https://tarheelreader.org/find/?search=#{CGI.escape(q)}&category=&reviewed=R&audience=E&language=#{locale}&page=1&json=1"
|
12
|
+
begin
|
13
|
+
res = Typhoeus.get(url, timeout: 2)
|
14
|
+
results = JSON.parse(res.body)
|
15
|
+
list = []
|
16
|
+
results['books'].each do |book|
|
17
|
+
list << {
|
18
|
+
'book_url' => "https://tarheelreader.org#{book['link']}",
|
19
|
+
'image_url' => tarheel_prefix + book['cover']['url'],
|
20
|
+
'title' => book['title'],
|
21
|
+
'author' => book['author'],
|
22
|
+
'pages' => book['pages'].to_i,
|
23
|
+
'id' => book['slug'],
|
24
|
+
'image_attribution' => "https://tarheelreader.org/photo-credits/?id=#{book['ID']}"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
rescue => e
|
28
|
+
end
|
29
|
+
return list
|
30
|
+
end
|
31
|
+
|
8
32
|
def self.tarheel_id(url)
|
9
33
|
return nil unless url
|
10
34
|
if url.match(TARHEEL_REGEX)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: accessible_books
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Whitmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|