Class: Etapper::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/etapper/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

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
  # Set the session handler
  @driver.streamhandler.filterchain << SessionFilter.new
  self.url = Etapper::ETAP_URL   # 'nil' is a valid value
  @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.

Raises:

  • (NoMethodError)


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  # This is protected for a reason
  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

#autoconnectObject

Returns the value of attribute autoconnect.



15
16
17
# File 'lib/etapper/client.rb', line 15

def autoconnect
  @autoconnect
end

Instance Method Details

#connectObject



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.(@username, @password)
    if result == ''
      @connected = true
    else  # May need a redirect
      newurl = URI.parse(result)
      newurl.query = nil   # Strip off the '?wsdl' parameter at the end
      driver.endpoint_url = newurl.to_s
      @connected = connect
    end
  end
end

#connected?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/etapper/client.rb', line 60

def connected?
  @connected
end

#disconnectObject



80
81
82
83
84
# File 'lib/etapper/client.rb', line 80

def disconnect
  driver.logout if connected?
  @connected = false
  true
end

#logObject

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

#passwordObject



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

#usernameObject



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