Class: KakuyomuAgent
- Inherits:
-
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
-
#create_episode(work_id:, title:, body:, date: nil) ⇒ Object
-
#delete_episode(work_id:, episode_id:) ⇒ Object
-
#initialize(base_url: BASE_URL, driver: Selenium::WebDriver.for(:chrome, options: Selenium::WebDriver::Chrome::Options.new.tap(&:headless!))) ⇒ KakuyomuAgent
constructor
A new instance of KakuyomuAgent.
-
#logged_in? ⇒ Boolean
-
#login!(email:, password:) ⇒ Object
-
#update_episode(work_id:, episode_id:, title:, body:, date: nil) ⇒ Object
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_url ⇒ Object
Returns the value of attribute base_url.
16
17
18
|
# File 'lib/kakuyomu_agent.rb', line 16
def base_url
@base_url
end
|
#driver ⇒ Object
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
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
#logged_in? ⇒ 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
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
|