Class: Sakura::Client

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/sakura/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

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

#domainObject (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_sessionObject



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)
   unless login?
  visit url
  page
end

#loginObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sakura/client.rb', line 27

def 
  visit BASE_URL
  fill_in 'domain',   with: @domain
  fill_in 'password', with: @passwd
  find('form input[type=image]').click

   = Time.now if page.text =~ /ログインドメイン: #{@domain}/

  raise_when_error
  login?
end

#login?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/sakura/client.rb', line 23

def 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)
   unless login?
  visit url
  instance_eval &block

  raise_when_error
  page
end