bookscan_client 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e80c696dea04315b45a82d625d144baea979194f
4
- data.tar.gz: c2b7930302400b35f5d9c29efa08e0d55d8b69da
3
+ metadata.gz: 2127994119e09cb507b05d5e7b1bb93e804239cf
4
+ data.tar.gz: f875faa5e71e836e423eb2dd0401eb4e65d67055
5
5
  SHA512:
6
- metadata.gz: 9d22b93bbfd8bdb6179a5a643b5d956550fb971cc94dd9907ca58a6f63f432dd484aad1ca52301915a5b5dbbc1a635b4d78826e64cb27cc12f1ad5199f05a997
7
- data.tar.gz: c9acf428a24ad4b60fcf7c5b8b566dc789be28163b93d1723dfd4e6913d7b05ef064f7bfaf1836787c5d364a67be18c43dc559751defa4b147de5031c9274179
6
+ metadata.gz: 8dd14137e893130ab759fb0e5dea9c4eccb0c19f4d4271e77481cb87205ca83f6838a2ef2a9fa4535fd1a66b096c1c9ef7c53e78dc6f8e0d95477b2b1d382e9c
7
+ data.tar.gz: 9eea2e94a6bf0a47dca73d5ca7ad6e8175cb6a874c42d34426a4a328412e82f004c3b30376678f895231a61599eacfc24414cb58d8e7a14117aefda809472ce4
@@ -12,6 +12,7 @@ class BookscanClient
12
12
  LOGIN = "https://system.bookscan.co.jp/login.php"
13
13
  MYPAGE = "https://system.bookscan.co.jp/bookshelf_all_cover.php"
14
14
  DOWNLOAD = "https://system.bookscan.co.jp/download.php"
15
+ OPTIMIZED_BOOKS = "https://system.bookscan.co.jp/tunelablist.php"
15
16
  end
16
17
 
17
18
  def initialize(logger: Logger.new(STDOUT), sleep: 0.5)
@@ -31,7 +32,28 @@ class BookscanClient
31
32
 
32
33
  def books
33
34
  page = fetch(URL::MYPAGE)
34
- BookscanClient::Model::Book.parse_books(page)
35
+ page.search("#sortable_box .showbook").map{|book_link|
36
+ url = "#{BookscanClient::URL::ROOT}#{book_link.attr("href")}"
37
+ params = CGI.parse(URI.parse(url).query)
38
+ next unless %w[f h d].all?{|key| params.keys.include?(key) }
39
+ image = book_link.search("img")
40
+
41
+ book = BookscanClient::Model::Book.new(filename: params["f"][0], hash: params["h"][0], digest: params["d"][0])
42
+ book.image_url = image[0].attr("data-original") unless image.empty?
43
+
44
+ book
45
+ }
46
+ end
47
+
48
+ def optimized_books
49
+ page = fetch(URL::OPTIMIZED_BOOKS)
50
+ page.search("a.download").map{|book_link|
51
+ url = "#{BookscanClient::URL::ROOT}#{book_link.attr("href")}"
52
+ params = CGI.parse(URI.parse(url).query)
53
+ next unless %w[f d].all?{|key| params.keys.include?(key) }
54
+
55
+ BookscanClient::Model::OptimizedBook.new(filename: params["f"][0], digest: params["d"][0])
56
+ }
35
57
  end
36
58
 
37
59
  def cookies
@@ -1 +1,2 @@
1
1
  require "bookscan_client/model/book"
2
+ require "bookscan_client/model/optimized_book"
@@ -10,20 +10,6 @@ class BookscanClient
10
10
  @image_url = image_url
11
11
  end
12
12
 
13
- def self.parse_books(page)
14
- page.search("#sortable_box .showbook").map{|book_link|
15
- url = "#{BookscanClient::URL::ROOT}#{book_link.attr("href")}"
16
- params = CGI.parse(URI.parse(url).query)
17
- next unless %w[f h d].all?{|key| params.keys.include?(key) }
18
- image = book_link.search("img")
19
-
20
- book = Book.new(filename: params["f"][0], hash: params["h"][0], digest: params["d"][0])
21
- book.image_url = image[0].attr("data-original") unless image.empty?
22
-
23
- book
24
- }
25
- end
26
-
27
13
  def download_url
28
14
  "#{BookscanClient::URL::DOWNLOAD}?d=#{digest}&f=#{CGI.escape(filename)}"
29
15
  end
@@ -0,0 +1,16 @@
1
+ class BookscanClient
2
+ module Model
3
+ class OptimizedBook
4
+ attr_accessor :filename, :digest
5
+
6
+ def initialize(filename: nil, digest: nil)
7
+ @filename = filename
8
+ @digest = digest
9
+ end
10
+
11
+ def download_url
12
+ "#{BookscanClient::URL::DOWNLOAD}?d=#{digest}&f=#{CGI.escape(filename)}&optimize=1"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  class BookscanClient
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,6 +2,7 @@ require_relative "./test_helper"
2
2
 
3
3
  describe BookscanClient do
4
4
  before do
5
+ stub_requests
5
6
  @client = BookscanClient.new
6
7
  end
7
8
 
@@ -17,4 +18,15 @@ describe BookscanClient do
17
18
  assert_equal books[1].image_url, "http://example.com/hoge.jpg"
18
19
  end
19
20
  end
21
+
22
+ describe "#optimized_books" do
23
+ it "returns optimized_book model array" do
24
+ optbooks = @client.optimized_books
25
+ assert_equal optbooks.size, 2
26
+ assert_equal optbooks[0].filename, "filename1"
27
+ assert_equal optbooks[0].digest, "digest1"
28
+ assert_equal optbooks[1].filename, "filename2"
29
+ assert_equal optbooks[1].digest, "digest2"
30
+ end
31
+ end
20
32
  end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head lang="en">
4
+ <meta charset="UTF-8">
5
+ <title></title>
6
+ </head>
7
+ <body>
8
+
9
+ <a class="download" href="download.php?d=digest1&f=filename1">optimized book 1</a>
10
+
11
+ <a class="download" href="download.php?d=digest2&f=filename2">optimized book 2</a>
12
+
13
+ </body>
14
+ </html>
@@ -8,10 +8,15 @@ require "webmock/minitest"
8
8
  WEBMOCK_DATADIR = File.expand_path('../data', __FILE__)
9
9
  WEBMOCK_PAGES = {
10
10
  BookscanClient::URL::MYPAGE => "mypage.html",
11
+ BookscanClient::URL::OPTIMIZED_BOOKS => "optimized_books.html",
11
12
  }
12
- WEBMOCK_PAGES.each do |url, filename|
13
- path = File.expand_path(filename, WEBMOCK_DATADIR)
14
- WebMock.
15
- stub_request(:get, url).
16
- to_return(body: File.new(path), status: 200, headers: { 'Content-Type' => 'text/html' })
13
+
14
+ def stub_requests
15
+ WEBMOCK_PAGES.each do |url, filename|
16
+ path = File.join(WEBMOCK_DATADIR, filename)
17
+ WebMock.
18
+ stub_request(:get, url).
19
+ to_return(body: File.new(path), status: 200, headers: { 'Content-Type' => 'text/html' })
20
+ p "stub #{url}"
21
+ end
17
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookscan_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hogelog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-07 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -138,9 +138,11 @@ files:
138
138
  - lib/bookscan_client.rb
139
139
  - lib/bookscan_client/model.rb
140
140
  - lib/bookscan_client/model/book.rb
141
+ - lib/bookscan_client/model/optimized_book.rb
141
142
  - lib/bookscan_client/version.rb
142
143
  - test/bookscan_client_test.rb
143
144
  - test/data/mypage.html
145
+ - test/data/optimized_books.html
144
146
  - test/test_helper.rb
145
147
  homepage: https://github.com/hogelog/bookscan-client-ruby
146
148
  licenses:
@@ -169,4 +171,5 @@ summary: Unofficial bookscan client.
169
171
  test_files:
170
172
  - test/bookscan_client_test.rb
171
173
  - test/data/mypage.html
174
+ - test/data/optimized_books.html
172
175
  - test/test_helper.rb