Class: Socky::Server::HTTP

Inherits:
Object
  • Object
show all
Includes:
Misc
Defined in:
lib/socky/server/http.rb

Defined Under Namespace

Classes: ConnectionError

Constant Summary

DEFAULT_OPTIONS =
{
  :debug => false,
  :timestamp_deviation => 10
}

Instance Method Summary collapse

Methods included from Misc

included, #log

Constructor Details

#initialize(options = {}) ⇒ HTTP



13
14
15
16
# File 'lib/socky/server/http.rb', line 13

def initialize(options = {})
  @options = DEFAULT_OPTIONS.merge(options)
  Config.new(@options)
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/socky/server/http.rb', line 18

def call(env)
  request = Rack::Request.new(env.merge('CONTENT_TYPE' => nil))
  @params = request.params
  log("received", @params)
  
  @app_name = request.path.split('/').last
  
  check_app
  check_channel
  
  check_timestamp
  check_auth
  
  channel = Channel.find_or_create(@app_name, @params['channel'])
  channel.deliver(nil, Message.new(nil, @params))
  
  [202, {}, ['Event sent']]
rescue ConnectionError => e
  [ e.status, {}, [e.message] ]
rescue Exception
  [ 500, {}, ['Unknown error'] ]
end