Class: ComicWalker::V1::Client
- Inherits:
-
Object
- Object
- ComicWalker::V1::Client
show all
- Defined in:
- lib/comic_walker/v1/client.rb
Defined Under Namespace
Classes: NoValidSessionError, UnknownDeviceError
Constant Summary
collapse
- BASE_URI =
Addressable::URI.parse("https://cnts.comic-walker.com")
- AID =
'KDCWI_JP'
- AVER =
'1.2.0'
Instance Method Summary
collapse
Constructor Details
#initialize(jar, uuid) ⇒ Client
Returns a new instance of Client.
11
12
13
14
15
16
17
|
# File 'lib/comic_walker/v1/client.rb', line 11
def initialize(jar, uuid)
@https = Net::HTTP.new(BASE_URI.host, 443)
@https.use_ssl = true
@https.verify_mode = OpenSSL::SSL::VERIFY_PEER
@jar = jar
@uuid = uuid
end
|
Instance Method Details
#contents(params = {}) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/comic_walker/v1/client.rb', line 70
def contents(params = {})
retried = 0
params = {
AID: AID,
AVER: AVER,
W: '320',
H: '480',
FORMATS: 'epub_pdf_fixedlayout',
include_hidden: 1,
include_meta: 1,
languages: 'ja',
}.merge(params)
begin
res = get('/v1/contents', params)
case res.body
when 'NoValidSessionError'
raise NoValidSessionError.new
else
JSON.parse(res.body)
end
rescue NoValidSessionError => e
if retried == 0
retried += 1
create_session
retry
else
raise e
end
end
end
|
#create_session ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/comic_walker/v1/client.rb', line 33
def create_session
retried = 0
begin
res = post('/user_sessions/create', {
DID: @uuid,
PIN: @uuid,
AID: AID,
AVER: AVER,
})
case res.body
when 'UnknownDeviceError'
raise UnknownDeviceError.new
when 'ValidSessionExistsError'
nil
else
JSON.parse(res.body)
end
rescue UnknownDeviceError => e
if retried == 0
retried += 1
create_user
retry
else
raise e
end
end
end
|
#create_user ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/comic_walker/v1/client.rb', line 61
def create_user
post('/users/create', {
DID: @uuid,
PIN: @uuid,
AID: AID,
AVER: AVER,
})
end
|
#start(&block) ⇒ Object
19
20
21
22
23
|
# File 'lib/comic_walker/v1/client.rb', line 19
def start(&block)
@https.start do
block.call
end
end
|