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.
51 52 53 54 55 56 |
# File 'lib/xremotebot.rb', line 51 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.
50 51 52 |
# File 'lib/xremotebot.rb', line 50 def ws @ws end |
Instance Method Details
#authenticate(api_key) ⇒ Object
74 75 76 |
# File 'lib/xremotebot.rb', line 74 def authenticate(api_key) send_ws_msg 'global', 'authenticate', api_key end |
#authentication_required ⇒ Object
70 71 72 |
# File 'lib/xremotebot.rb', line 70 def authentication_required send_ws_msg 'global', 'authentication_required' end |
#fetch_robot ⇒ Object
82 83 84 |
# File 'lib/xremotebot.rb', line 82 def fetch_robot send_ws_msg 'global', 'fetch_robot' end |
#get_robots ⇒ Object
78 79 80 |
# File 'lib/xremotebot.rb', line 78 def get_robots send_ws_msg 'global', 'get_robots' end |
#reserve(robot_model, robot_id) ⇒ Object
86 87 88 |
# File 'lib/xremotebot.rb', line 86 def reserve(robot_model, robot_id) send_ws_msg 'global', 'reserve', robot_model, robot_id end |
#send_ws_msg(entity, method, *args) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/xremotebot.rb', line 58 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 |