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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/accessible-books.rb +24 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c694c6f206d204a7a40172061a23132c433b6ddbadab17780ec1ec81f61e5c38
4
- data.tar.gz: 369c769032bee445214d0caa876e947601816f18595b7508664a23501c476ed1
3
+ metadata.gz: 2e899dda6340210fab2002f7c225e909b47f08df5c4e6f43128ea2218691d849
4
+ data.tar.gz: '0787e923fd55ef18b39a46a6117d570ce6e0c7a2c2795edd3b2e84f3fe054283'
5
5
  SHA512:
6
- metadata.gz: fde1fb4688a05e324c7075b1adaf12d280d1836eae227fb361d9da9d44134c8c27c56df6d51938d7ee4d2bed77ef2e4b2622780dade6af774a662bc2e1215f9b
7
- data.tar.gz: b6adfe3c9ad19f4b069bec8d31bdef17450f1be742cc3c094be67a40779b19b66c4ce706ae03f5defe6421952c27ee4d59345c5f7f91557d6527cd36e88e1051
6
+ metadata.gz: a2029c3b233cedbc3b6d174dd37790124f749ab791e245f9b560ea23cc23550103fe881f27bf482c74f2dcfc2f3aafb79e0b0ae13e994681cd52c145ceb5db47
7
+ data.tar.gz: 95285cc6bf315754bfb7ad6b3528fe377a3dec58186d8750053de82ba64e2f700d49b5c0cc57177bee1e939c5293dae00b9258e161ba4114664397831a0b2a8f
@@ -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.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-03-02 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus