Class: Sakura::Client
- Inherits:
-
Object
- Object
- Sakura::Client
- Includes:
- Capybara::DSL
- Defined in:
- lib/sakura/client.rb
Class Attribute Summary collapse
-
.verbose ⇒ Object
Returns the value of attribute verbose.
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
Class Method Summary collapse
Instance Method Summary collapse
- #get(url, expected) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #login? ⇒ Boolean
- #process(url, expected) {|page| ... } ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
27 28 29 |
# File 'lib/sakura/client.rb', line 27 def initialize @domain, @passwd = credentials end |
Class Attribute Details
.verbose ⇒ Object
Returns the value of attribute verbose.
20 21 22 |
# File 'lib/sakura/client.rb', line 20 def verbose @verbose end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
15 16 17 |
# File 'lib/sakura/client.rb', line 15 def domain @domain end |
Class Method Details
.current_session ⇒ Object
22 23 24 |
# File 'lib/sakura/client.rb', line 22 def current_session @current_session ||= new end |
Instance Method Details
#get(url, expected) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sakura/client.rb', line 59 def get(url, expected) login unless login? warn "visit #{url}" if self.class.verbose visit url wait_for_loading raise Timeout::Error, 'Timed out' unless page.text =~ expected page end |
#login ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sakura/client.rb', line 35 def login warn 'login' if self.class.verbose visit BASE_URL fill_in 'username', with: @domain fill_in 'password', with: @passwd find('form button[type=submit]').click if has_text?('認証コード') puts '認証コード:' otp = $stdin.gets fill_in 'login-otp', with: otp find('form button[type=submit]').click end wait_for_loading @logged_in = true if page.text =~ /サーバーコントロールパネル ホーム/ raise_when_error login? end |
#login? ⇒ Boolean
31 32 33 |
# File 'lib/sakura/client.rb', line 31 def login? @logged_in end |
#process(url, expected) {|page| ... } ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sakura/client.rb', line 70 def process(url, expected) login unless login? get url, expected yield page raise_when_error wait_for_loading page end |