Class: Superbot::Web
- Inherits:
-
Object
- Object
- Superbot::Web
- Defined in:
- lib/superbot/web.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(webdriver_type: 'cloud', region: nil, organization: nil) ⇒ Web
constructor
A new instance of Web.
- #quit! ⇒ Object
- #run! ⇒ Object
- #run_async! ⇒ Object
- #run_async_after_running! ⇒ Object
Constructor Details
#initialize(webdriver_type: 'cloud', region: nil, organization: nil) ⇒ Web
Returns a new instance of Web.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/superbot/web.rb', line 9 def initialize(webdriver_type: 'cloud', region: nil, organization: nil) @sinatra = Sinatra.new @sinatra.set :bind, ENV.fetch('SUPERBOT_BIND_ADDRESS', '127.0.0.1') @sinatra.set :silent_sinatra, true @sinatra.set :silent_webrick, true @sinatra.set :silent_access_log, false @sinatra.server_settings[:Silent] = true @sinatra.set :webdriver_type, webdriver_type @sinatra.set :webdriver_url, Superbot.webdriver_endpoint(webdriver_type) @sinatra.set :region, region @sinatra.set :organization, organization @sinatra.before do headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS' headers['Access-Control-Allow-Origin'] = '*' headers['Access-Control-Allow-Headers'] = 'accept, authorization, origin' end @sinatra. '*' do response.headers['Allow'] = 'HEAD,GET,PUT,DELETE,OPTIONS,POST' response.headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept' end @sinatra.get "/__superbot/v1/ping" do "PONG" end @sinatra.register Superbot::Teleport::Web if defined?(Superbot::Teleport::Web) @sinatra.register Superbot::Cloud::Web if defined?(Superbot::Cloud::Web) @sinatra.register Superbot::Convert::Web if defined?(Superbot::Convert::Web) end |
Class Method Details
.run!(options = { webdriver_type: 'cloud', region: nil, organization: nil }) ⇒ Object
42 43 44 |
# File 'lib/superbot/web.rb', line 42 def self.run!( = { webdriver_type: 'cloud', region: nil, organization: nil }) new().tap(&:run!) end |
Instance Method Details
#quit! ⇒ Object
66 67 68 |
# File 'lib/superbot/web.rb', line 66 def quit! @sinatra&.quit! end |
#run! ⇒ Object
50 51 52 |
# File 'lib/superbot/web.rb', line 50 def run! @sinatra.run! end |
#run_async! ⇒ Object
46 47 48 |
# File 'lib/superbot/web.rb', line 46 def run_async! @sinatra.run_async! end |
#run_async_after_running! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/superbot/web.rb', line 54 def run_async_after_running! Thread.new do @sinatra.run! end loop do break if @sinatra.running? sleep 0.001 end end |