Class: Sakura::Client
- Inherits:
-
Object
- Object
- Sakura::Client
- Includes:
- Capybara::DSL
- Defined in:
- lib/sakura/client.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
Class Method Summary collapse
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #login? ⇒ Boolean
- #process(url, &block) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
20 21 22 |
# File 'lib/sakura/client.rb', line 20 def initialize @domain, @passwd = credentials end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
13 14 15 |
# File 'lib/sakura/client.rb', line 13 def domain @domain end |
Class Method Details
.current_session ⇒ Object
15 16 17 |
# File 'lib/sakura/client.rb', line 15 def self.current_session @current_session ||= new end |
Instance Method Details
#get(url) ⇒ Object
40 41 42 43 44 |
# File 'lib/sakura/client.rb', line 40 def get(url) login unless login? visit url page end |
#login ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sakura/client.rb', line 28 def login visit BASE_URL fill_in 'domain', with: @domain fill_in 'password', with: @passwd find('form input[type=image]').click @last_login = Time.now if page.text =~ /ログインドメイン: #{@domain}/ raise_when_error login? end |
#login? ⇒ Boolean
24 25 26 |
# File 'lib/sakura/client.rb', line 24 def login? !@last_login.nil? end |
#process(url, &block) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/sakura/client.rb', line 46 def process(url, &block) login unless login? visit url instance_eval &block raise_when_error page end |