Class: Sakura::Client
- Inherits:
-
Object
- Object
- Sakura::Client
- Includes:
- Capybara::DSL
- Defined in:
- lib/sakura/client.rb
Constant Summary collapse
- @@verbose =
false
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.
26 27 28 |
# File 'lib/sakura/client.rb', line 26 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
17 18 19 |
# File 'lib/sakura/client.rb', line 17 def current_session @current_session ||= new end |
.verbose=(bool) ⇒ Object
21 22 23 |
# File 'lib/sakura/client.rb', line 21 def verbose=(bool) @@verbose = !!bool end |
Instance Method Details
#get(url, expected) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sakura/client.rb', line 52 def get(url, expected) login unless login? $stderr.puts "visit #{url}" if @@verbose visit url wait_for_loading unless page.text =~ expected raise Timeout::Error.new('Timed out') end page end |
#login ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sakura/client.rb', line 34 def login $stderr.puts 'login' if @@verbose visit BASE_URL fill_in 'login-username', with: @domain fill_in 'login-password', with: @passwd find('form button[type=submit]').click wait_for_loading if page.text =~ /サーバコントロールパネル ホーム/ @logged_in = true end raise_when_error login? end |
#login? ⇒ Boolean
30 31 32 |
# File 'lib/sakura/client.rb', line 30 def login? @logged_in end |
#process(url, expected) {|page| ... } ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/sakura/client.rb', line 65 def process(url, expected, &block) login unless login? get url, expected yield page raise_when_error page end |