Class: KakuyomuAgent::Actions::CreateEpisode

Inherits:
KakuyomuAgent::Action show all
Defined in:
lib/kakuyomu_agent/actions/create_episode.rb

Instance Method Summary collapse

Methods inherited from KakuyomuAgent::Action

#initialize

Methods included from UrlHelper

extract_episode_id, extract_work_id

Constructor Details

This class inherits a constructor from KakuyomuAgent::Action

Instance Method Details

#run(work_id, title, body, date = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kakuyomu_agent/actions/create_episode.rb', line 4

def run(work_id, title, body, date = nil)
  driver.get(new_episode_url(work_id))

  title_input = driver.find_element(name: 'title')
  title_input.clear
  title_input.send_keys(title)

  driver.find_element(name: 'body').send_keys(body)

  driver.find_element(id: 'reserveButton').click

  episode_id = if date.nil? || date < Time.now
                 publish
               else
                 reserve(date)
               end

  episode_url(work_id, episode_id)
rescue Selenium::WebDriver::Error::WebDriverError => e
  raise ActionFailedError.new(e)
end