Class: A4Tools::UsherClient

Inherits:
AcresClient show all
Defined in:
lib/clients/usher_client.rb

Instance Attribute Summary collapse

Attributes inherited from AcresClient

#connect_time, #connected, #history, #password, #ready, #server_info, #start_time, #token, #uri, #username, #version

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AcresClient

#add_message_to_history, #app_info, #attempt_snoop, #authenticate, #authenticate_if_needed, #connect, #connect_if_needed, #device_info, #disconnect, #empty_query, #inject_token, #jsonrpc_message, #make_password, #next_msg_id, #response_body, #send_message, #snoop_token, #transport_connect, #wrapped_message

Methods included from EventGenerator

#on, #passthrough, #signal

Constructor Details

#initialize(uri = nil) ⇒ UsherClient

Returns a new instance of UsherClient.



20
21
22
# File 'lib/clients/usher_client.rb', line 20

def initialize(uri=nil)
  super(uri || self.class.random_mirror)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



18
19
20
# File 'lib/clients/usher_client.rb', line 18

def response
  @response
end

Class Method Details

.mirrorsObject



4
5
6
7
8
9
10
# File 'lib/clients/usher_client.rb', line 4

def mirrors
  [
    "http://s01.ushers.acres4.net:8080/usher2/json?wrap",
    "http://s02.ushers.acres4.net:8080/usher2/json?wrap",
    "http://s03.ushers.acres4.net:8080/usher2/json?wrap"
  ]
end

.random_mirrorObject



12
13
14
15
# File 'lib/clients/usher_client.rb', line 12

def random_mirror
  _m = mirrors
  _m[rand(_m.length)]
end

Instance Method Details

#dump_usher_response(response = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/clients/usher_client.rb', line 47

def dump_usher_response(response=nil)
  response ||= @list
  s = "Site #{response['siteID']} (#{response['siteName']})\n"

  response[:hosts].each do |host|
    s += "\t#{host["product"]}, #{host["url"]}#{host["context"]}\n"
  end
  s += "\n"
end

#list_servers(params = {}) ⇒ Object



42
43
44
45
# File 'lib/clients/usher_client.rb', line 42

def list_servers(params={})
  list_servers_raw
  @list
end

#list_servers_raw(params = {}) ⇒ Object



36
37
38
39
40
# File 'lib/clients/usher_client.rb', line 36

def list_servers_raw(params={})
  response = send_message(wrapped_message(params[:full] ? "usherAlt" : "usher", "com.acres4.common.info.usher.UsherRequest", usher_request_for_params(params)))
  @list = response_body response
  response
end

#locate_service(service, response = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/clients/usher_client.rb', line 57

def locate_service(service, response=nil)
  list_servers unless @list
  response ||= @list

  products = response[:hosts].select do |h|
    h[:product].match("^#{service}(-(Secure|Server))?$")
  end

  products.sort! do |h,o|
    h[:product] <=> o[:product]
  end

  products.first
end

#usher_request_for_params(params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/clients/usher_client.rb', line 24

def usher_request_for_params(params)
  request = {
    app: app_info,
    device: device_info
  }

  request[:device][:serialNumber] = params[:serial] if params.has_key?(:serial)
  request[:ipOverride] = params[:ip] if params.has_key?(:ip)

  request
end