lib/bookscan_client.rb in bookscan_client-0.0.1 vs lib/bookscan_client.rb in bookscan_client-0.0.2
- old
+ new
@@ -10,10 +10,11 @@
module URL
ROOT = "https://system.bookscan.co.jp/"
LOGIN = "https://system.bookscan.co.jp/login.php"
MYPAGE = "https://system.bookscan.co.jp/bookshelf_all_cover.php"
DOWNLOAD = "https://system.bookscan.co.jp/download.php"
+ OPTIMIZED_BOOKS = "https://system.bookscan.co.jp/tunelablist.php"
end
def initialize(logger: Logger.new(STDOUT), sleep: 0.5)
@mechanize = Mechanize.new
@logger = logger
@@ -29,10 +30,31 @@
names.include?("email") && names.include?("password")
end
def books
page = fetch(URL::MYPAGE)
- BookscanClient::Model::Book.parse_books(page)
+ page.search("#sortable_box .showbook").map{|book_link|
+ url = "#{BookscanClient::URL::ROOT}#{book_link.attr("href")}"
+ params = CGI.parse(URI.parse(url).query)
+ next unless %w[f h d].all?{|key| params.keys.include?(key) }
+ image = book_link.search("img")
+
+ book = BookscanClient::Model::Book.new(filename: params["f"][0], hash: params["h"][0], digest: params["d"][0])
+ book.image_url = image[0].attr("data-original") unless image.empty?
+
+ book
+ }
+ end
+
+ def optimized_books
+ page = fetch(URL::OPTIMIZED_BOOKS)
+ page.search("a.download").map{|book_link|
+ url = "#{BookscanClient::URL::ROOT}#{book_link.attr("href")}"
+ params = CGI.parse(URI.parse(url).query)
+ next unless %w[f d].all?{|key| params.keys.include?(key) }
+
+ BookscanClient::Model::OptimizedBook.new(filename: params["f"][0], digest: params["d"][0])
+ }
end
def cookies
@mechanize.cookies
end