Class: KakuyomuAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/kakuyomu_agent.rb,
lib/kakuyomu_agent/error.rb,
lib/kakuyomu_agent/action.rb,
lib/kakuyomu_agent/version.rb,
lib/kakuyomu_agent/url_helper.rb,
lib/kakuyomu_agent/actions/login.rb,
lib/kakuyomu_agent/actions/create_episode.rb,
lib/kakuyomu_agent/actions/delete_episode.rb,
lib/kakuyomu_agent/actions/update_episode.rb

Defined Under Namespace

Modules: Actions, UrlHelper Classes: Action

Constant Summary collapse

BASE_URL =
'https://kakuyomu.jp'
Error =
Class.new(StandardError)
NotLoggedInError =
Class.new(Error)
ActionFailedError =
Class.new(Error)
VERSION =
'0.4.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: BASE_URL, driver: Selenium::WebDriver.for(:chrome, options: Selenium::WebDriver::Chrome::Options.new.tap(&:headless!))) ⇒ KakuyomuAgent

Returns a new instance of KakuyomuAgent.



18
19
20
21
22
# File 'lib/kakuyomu_agent.rb', line 18

def initialize(base_url: BASE_URL, driver: Selenium::WebDriver.for(:chrome, options: Selenium::WebDriver::Chrome::Options.new.tap(&:headless!)))
  @base_url  = base_url
  @driver    = driver
  @logged_in = false
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



16
17
18
# File 'lib/kakuyomu_agent.rb', line 16

def base_url
  @base_url
end

#driverObject (readonly)

Returns the value of attribute driver.



16
17
18
# File 'lib/kakuyomu_agent.rb', line 16

def driver
  @driver
end

Instance Method Details

#create_episode(work_id:, title:, body:, date: nil) ⇒ Object

Raises:



33
34
35
36
# File 'lib/kakuyomu_agent.rb', line 33

def create_episode(work_id:, title:, body:, date: nil)
  raise NotLoggedInError unless logged_in?
  Actions::CreateEpisode.new(self).run(work_id, title, body, date)
end

#delete_episode(work_id:, episode_id:) ⇒ Object

Raises:



43
44
45
46
# File 'lib/kakuyomu_agent.rb', line 43

def delete_episode(work_id:, episode_id:)
  raise NotLoggedInError unless logged_in?
  Actions::DeleteEpisode.new(self).run(work_id, episode_id)
end

#logged_in?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/kakuyomu_agent.rb', line 24

def logged_in?
  @logged_in
end

#login!(email:, password:) ⇒ Object



28
29
30
31
# File 'lib/kakuyomu_agent.rb', line 28

def login!(email:, password:)
  Actions::Login.new(self).run(email, password)
  @logged_in = true
end

#update_episode(work_id:, episode_id:, title:, body:, date: nil) ⇒ Object

Raises:



38
39
40
41
# File 'lib/kakuyomu_agent.rb', line 38

def update_episode(work_id:, episode_id:, title:, body:, date: nil)
  raise NotLoggedInError unless logged_in?
  Actions::UpdateEpisode.new(self).run(work_id, episode_id, title, body, date)
end