Class: RubyHome::HTTP::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/http/application.rb

Instance Method Summary collapse

Instance Method Details

#bind_addressObject



17
18
19
# File 'lib/ruby_home/http/application.rb', line 17

def bind_address
  '0.0.0.0'
end

#portObject



13
14
15
# File 'lib/ruby_home/http/application.rb', line 13

def port
  @_port ||= Integer(ENV['PORT'] && !ENV['PORT'].empty? ? ENV['PORT'] : 4567)
end

#rack_builderObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby_home/http/application.rb', line 21

def rack_builder
  ::Rack::Builder.new do
    use ::Rack::CommonLogger
    map('/accessories', &Proc.new { run AccessoriesController })
    map('/characteristics', &Proc.new { run CharacteristicsController })
    map('/pair-setup', &Proc.new { run PairSetupsController })
    map('/pair-verify', &Proc.new { run PairVerifiesController })
    map('/pairings', &Proc.new { run PairingsController })
  end
end

#runObject



6
7
8
9
10
11
# File 'lib/ruby_home/http/application.rb', line 6

def run
  RubyHome::Rack::Handler::HAPServer.run rack_builder,
    Port: port,
    Host: bind_address,
    ServerSoftware: 'RubyHome'
end