Class: ComicWalker::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/comic_walker/client.rb,
lib/comic_walker/client/license.rb

Defined Under Namespace

Classes: Error, License

Instance Method Summary collapse

Constructor Details

#initializeClient

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/comic_walker/client.rb', line 41

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
# File 'lib/comic_walker/client.rb', line 33

def get_u1(cid)
  uri = Addressable::URI.parse("http://comic-walker.com/viewer/?cid=#{cid}")
  Net::HTTP.start(uri.host, 80) do |http|
    res = http.get(uri.request_uri)
    Addressable::URI.unescape(HTTP::Cookie.cookie_value_to_hash(res['set-cookie'])['u1'])
  end
end