Class: NarouAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/narou_agent.rb,
lib/narou_agent/error.rb,
lib/narou_agent/action.rb,
lib/narou_agent/version.rb,
lib/narou_agent/url_helper.rb,
lib/narou_agent/actions/login.rb,
lib/narou_agent/actions/create_part.rb,
lib/narou_agent/actions/delete_part.rb,
lib/narou_agent/actions/update_part.rb

Defined Under Namespace

Modules: Actions, UrlHelper Classes: Action

Constant Summary collapse

BASE_URL =
'https://syosetu.com'
DEFAULT_WAIT_DURATION =
60
Error =
Class.new(StandardError)
NotLoggedInError =
Class.new(Error)
ActionFailedError =
Class.new(Error)
VERSION =
'0.3.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!))) ⇒ NarouAgent

Returns a new instance of NarouAgent.



20
21
22
23
24
# File 'lib/narou_agent.rb', line 20

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.



18
19
20
# File 'lib/narou_agent.rb', line 18

def base_url
  @base_url
end

#driverObject (readonly)

Returns the value of attribute driver.



18
19
20
# File 'lib/narou_agent.rb', line 18

def driver
  @driver
end

Instance Method Details

#create_part(ncode:, subtitle:, body:, date: nil, wait_duration: DEFAULT_WAIT_DURATION) ⇒ Object

Raises:



35
36
37
38
# File 'lib/narou_agent.rb', line 35

def create_part(ncode:, subtitle:, body:, date: nil, wait_duration: DEFAULT_WAIT_DURATION)
  raise NotLoggedInError unless logged_in?
  Actions::CreatePart.new(self).run(ncode, subtitle, body, date, wait_duration)
end

#delete_part(ncode:, part_id:) ⇒ Object

Raises:



45
46
47
48
# File 'lib/narou_agent.rb', line 45

def delete_part(ncode:, part_id:)
  raise NotLoggedInError unless logged_in?
  Actions::DeletePart.new(self).run(ncode, part_id)
end

#logged_in?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/narou_agent.rb', line 26

def logged_in?
  @logged_in
end

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



30
31
32
33
# File 'lib/narou_agent.rb', line 30

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

#update_part(ncode:, part_id:, subtitle:, body:, date: nil) ⇒ Object

Raises:



40
41
42
43
# File 'lib/narou_agent.rb', line 40

def update_part(ncode:, part_id:, subtitle:, body:, date: nil)
  raise NotLoggedInError unless logged_in?
  Actions::UpdatePart.new(self).run(ncode, part_id, subtitle, body, date)
end