class RubyRobot::Webapp
Simple Sinatra webapp that supports:
Run HTTP GET on /swagger.json to fetch a static JSON OpenAPI description for this webapp (suitable for use with swagger.io's GUI).
Constants
- ERR_PLACEMENT_MSG
- REPORT_EXAMPLE
- REPORT_EXAMPLE_OBJ
Public Instance Methods
formatted_report()
click to toggle source
# File lib/ruby_robot/webapp.rb, line 117 def formatted_report r = robot.REPORT(false) if !r.nil? r[:direction] = r[:direction].upcase unless r[:direction].nil? end r end
max_error_message_length()
click to toggle source
# File lib/ruby_robot/webapp.rb, line 45 def max_error_message_length # Grab from the schema (response_schema['definitions']['Error']['properties']['message']['maxLength'] || 1024) end
not_placed_error()
click to toggle source
# File lib/ruby_robot/webapp.rb, line 113 def not_placed_error [400, {code: 400, message: ERR_PLACEMENT_MSG}.to_json] end
position_report()
click to toggle source
# File lib/ruby_robot/webapp.rb, line 125 def position_report # Pass along the report, but the direction needs to be upcased to # comply w/ the JSON schema for the web API [200, formatted_report.to_json] end
request_schema()
click to toggle source
# File lib/ruby_robot/webapp.rb, line 37 def request_schema @@request_schema ||= schema = load_schema('request') end
response_schema()
click to toggle source
# File lib/ruby_robot/webapp.rb, line 41 def response_schema @@response_schema ||= schema = load_schema('response') end
robot()
click to toggle source
“Normal” sinatra/ruby code.
# File lib/ruby_robot/webapp.rb, line 104 def robot @@robot ||= proc { rr = ::RubyRobot::Shell.new # In the webapp, don't log the REPORT messages to stdout rr.logger.formatter = proc { |severity, datetime, progname, msg| "" } rr }.call end