Class: XRemoteBot::Server
- Inherits:
-
Object
- Object
- XRemoteBot::Server
- Defined in:
- lib/xremotebot.rb
Instance Attribute Summary collapse
-
#ws ⇒ Object
readonly
Returns the value of attribute ws.
Instance Method Summary collapse
- #authenticate(api_key) ⇒ Object
- #authentication_required ⇒ Object
- #fetch_robot ⇒ Object
- #get_robots ⇒ Object
-
#initialize(host, port, path, api_key) ⇒ Server
constructor
A new instance of Server.
- #reserve(robot_model, robot_id) ⇒ Object
- #send_ws_msg(entity, method, *args) ⇒ Object
Constructor Details
#initialize(host, port, path, api_key) ⇒ Server
Returns a new instance of Server.
50 51 52 53 54 55 |
# File 'lib/xremotebot.rb', line 50 def initialize(host, port, path, api_key) @ws = WS.new(host, port, path) if authentication_required raise Exception, 'Authentication failed' unless authenticate(api_key) end end |
Instance Attribute Details
#ws ⇒ Object (readonly)
Returns the value of attribute ws.
49 50 51 |
# File 'lib/xremotebot.rb', line 49 def ws @ws end |
Instance Method Details
#authenticate(api_key) ⇒ Object
73 74 75 |
# File 'lib/xremotebot.rb', line 73 def authenticate(api_key) send_ws_msg 'global', 'authenticate', api_key end |
#authentication_required ⇒ Object
69 70 71 |
# File 'lib/xremotebot.rb', line 69 def authentication_required send_ws_msg 'global', 'authentication_required' end |
#fetch_robot ⇒ Object
81 82 83 |
# File 'lib/xremotebot.rb', line 81 def fetch_robot send_ws_msg 'global', 'fetch_robot' end |
#get_robots ⇒ Object
77 78 79 |
# File 'lib/xremotebot.rb', line 77 def get_robots send_ws_msg 'global', 'get_robots' end |
#reserve(robot_model, robot_id) ⇒ Object
85 86 87 |
# File 'lib/xremotebot.rb', line 85 def reserve(robot_model, robot_id) send_ws_msg 'global', 'reserve', robot_model, robot_id end |
#send_ws_msg(entity, method, *args) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/xremotebot.rb', line 57 def send_ws_msg(entity, method, *args) msg = JSON.dump({ entity: entity, method: method, args: args, }) ws.send(msg) response = JSON.load ws.receive raise Exception, response['message'] if response['response'] == 'error' response['value'] end |