Class: Etapper::Client
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/etapper/client.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/etapper/client.rb', line 21
def initialize
@driver = API::MessagingService.new
@driver.streamhandler.filterchain << SessionFilter.new
self.url = Etapper::ETAP_URL @autoconnect = true
@username = nil
@password = nil
@connected = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *params) ⇒ Object
Our primary proxy. Sends anything we don’t know about to the driver for processing.
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/etapper/client.rb', line 97
def method_missing(method, *params)
raise NoMethodError if method == :driver tries = 0
begin
unless connected?
if autoconnect
connect
else
raise ConnectionError, "Autoconnect is disabled! Use the 'connect' method before making any API calls."
end
end
driver.send(method, *params)
rescue StandardError, SocketError => e
while tries < 3
sleep (tries += 1)
disconnect
retry
end
raise end
end
|
Instance Attribute Details
#autoconnect ⇒ Object
Returns the value of attribute autoconnect.
15
16
17
|
# File 'lib/etapper/client.rb', line 15
def autoconnect
@autoconnect
end
|
Instance Method Details
#connect ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/etapper/client.rb', line 64
def connect
unless connected?
raise ConnectionError, "Username is required!" unless username
raise ConnectionError, "Password is required!" unless password
begin
result = driver.login(@username, @password)
if result == ''
@connected = true
else newurl = URI.parse(result)
newurl.query = nil driver.endpoint_url = newurl.to_s
@connected = connect
end
rescue @connected = false
false
end
end
end
|
#connected? ⇒ Boolean
60
61
62
|
# File 'lib/etapper/client.rb', line 60
def connected?
@connected
end
|
#disconnect ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/etapper/client.rb', line 85
def disconnect
begin
driver.logout if connected?
true
rescue false
ensure
@connected = false
end
end
|
#log ⇒ Object
Delegates from the driver’s annoyingly named wiredump_dev property
51
52
53
|
# File 'lib/etapper/client.rb', line 51
def log
driver.wiredump_dev
end
|
#log=(logthing) ⇒ Object
Delegates to the driver’s annoyingly named wiredump_dev property
56
57
58
|
# File 'lib/etapper/client.rb', line 56
def log=(logthing)
driver.wiredump_dev = logthing
end
|
#password ⇒ Object
41
42
43
|
# File 'lib/etapper/client.rb', line 41
def password
@password ||= ENV['ETAPPER_PASSWORD'] || config_file["password"]
end
|
#password=(val) ⇒ Object
45
46
47
48
|
# File 'lib/etapper/client.rb', line 45
def password=(val)
@password = val
disconnect
end
|
#username ⇒ Object
32
33
34
|
# File 'lib/etapper/client.rb', line 32
def username
@username ||= ENV['ETAPPER_USERNAME'] || config_file["username"]
end
|
#username=(val) ⇒ Object
36
37
38
39
|
# File 'lib/etapper/client.rb', line 36
def username=(val)
@username = val
disconnect
end
|