Class: ComicWalker::Client
- Inherits:
-
Object
- Object
- ComicWalker::Client
- Defined in:
- lib/comic_walker/client.rb,
lib/comic_walker/client/license.rb
Defined Under Namespace
Instance Method Summary collapse
- #get_li(cid, u1) ⇒ Object
- #get_license(cid) ⇒ Object
- #get_u1(cid) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/comic_walker/client.rb', line 10 def initialize @bid = '000000000000000000000NFBR' end |
Instance Method Details
#get_li(cid, u1) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/comic_walker/client.rb', line 46 def get_li(cid, u1) uri = Addressable::URI.parse("https://cnts.comic-walker.com/api4js/v1/c/#{cid}/li") uri.query_values = { 'BID' => @bid, 'AID' => 'browser', 'AVER' => '1.2.0', 'S' => u1, 'FORMATS' => 'epub_brws,epub_brws_fixedlayout,epub_brws_omf', 'W' => 720, 'H' => 1280, } https = Net::HTTP.new(uri.host, 443) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_PEER body = https.start do req = Net::HTTP::Get.new(uri.request_uri) res = https.request(req) res.body end JSON.parse(body) end |
#get_license(cid) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/comic_walker/client.rb', line 23 def get_license(cid) u1 = get_u1(cid) json = get_li(cid, u1) if error = json['error'] raise Error.new(error['code'], error['message']) end license_b64 = json['license'] License.new(JSON.parse(Cipher.decrypt_license(@bid, u1, license_b64))) end |
#get_u1(cid) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/comic_walker/client.rb', line 33 def get_u1(cid) uri = Addressable::URI.parse("http://comic-walker.com/viewer/?tw=2&dlcl=ja&cid=#{cid}") Net::HTTP.start(uri.host, 80) do |http| res = http.get(uri.request_uri) if = res['set-cookie'] u1 = HTTP::Cookie.()['u1'] if u1 Addressable::URI.unescape(u1) end end end end |