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.
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/etapper/client.rb', line 87
def method_missing(method, *params)
raise NoMethodError if method == :driver 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)
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
|
# 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
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
end
end
|
#connected? ⇒ Boolean
60
61
62
|
# File 'lib/etapper/client.rb', line 60
def connected?
@connected
end
|
#disconnect ⇒ Object
80
81
82
83
84
|
# File 'lib/etapper/client.rb', line 80
def disconnect
driver.logout if connected?
@connected = false
true
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
|