Class: ComicWalker::V1::Client
- Inherits:
-
Object
- Object
- ComicWalker::V1::Client
- 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
- #contents(params = {}) ⇒ Object
- #create_session ⇒ Object
- #create_user ⇒ Object
-
#initialize(jar, uuid) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(jar, uuid) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/comic_walker/v1/client.rb', line 13 def initialize(jar, uuid) @https = Net::HTTP::Persistent.new('comic_walker') @jar = jar @uuid = uuid end |
Instance Method Details
#contents(params = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/comic_walker/v1/client.rb', line 56 def contents(params = {}) params = { AID: AID, AVER: AVER, W: '320', H: '480', FORMATS: 'epub_pdf_fixedlayout', include_hidden: 1, include_meta: 1, languages: 'ja', }.merge(params) on_exception = lambda { |exception| create_session } Retryable.retryable(tries: 2, on: NoValidSessionError, sleep: 0, exception_cb: on_exception) do res = get('/v1/contents', params) case res.body when 'NoValidSessionError' raise NoValidSessionError.new else JSON.parse(res.body) end end end |
#create_session ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/comic_walker/v1/client.rb', line 27 def create_session on_exception = lambda { |exception| create_user } Retryable.retryable(tries: 2, on: UnknownDeviceError, sleep: 0, exception_cb: on_exception) do 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 end end |