Sha256: b198083625dd5429fc6a5781eceda425555ad663bcd46ab533393a5621c542da
Contents?: true
Size: 1000 Bytes
Versions: 1
Compression:
Stored size: 1000 Bytes
Contents
require "bookscan_client/version" require "bookscan_client/model" require "uri" require "cgi/util" require "mechanize" require "logger" class BookscanClient 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" end def initialize(logger: Logger.new(STDOUT), sleep: 0.5) @mechanize = Mechanize.new @logger = logger @sleep = sleep end def login(email, password) @mechanize.post(URL::LOGIN, "email" => email, "password" => password) end def login? names = cookies.map(&:name) names.include?("email") && names.include?("password") end def books page = fetch(URL::MYPAGE) BookscanClient::Model::Book.parse_books(page) end def cookies @mechanize.cookies end private def fetch(url) @logger.info("GET #{url}...") @mechanize.get(url) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bookscan_client-0.0.1 | lib/bookscan_client.rb |