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.
19 20 21 |
# File 'lib/sakura/client.rb', line 19 def initialize @domain, @passwd = credentials end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/sakura/client.rb', line 12 def domain @domain end |
Class Method Details
.current_session ⇒ Object
14 15 16 |
# File 'lib/sakura/client.rb', line 14 def self.current_session @current_session ||= new end |
Instance Method Details
#get(url) ⇒ Object
39 40 41 42 43 |
# File 'lib/sakura/client.rb', line 39 def get(url) login unless login? visit url page end |
#login ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sakura/client.rb', line 27 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
23 24 25 |
# File 'lib/sakura/client.rb', line 23 def login? !@last_login.nil? end |
#process(url, &block) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/sakura/client.rb', line 45 def process(url, &block) login unless login? visit url instance_eval &block raise_when_error page end |