Class: HipTail::Web::RackApp
- Inherits:
-
Object
- Object
- HipTail::Web::RackApp
- Defined in:
- lib/hiptail/web/rack_app.rb
Instance Attribute Summary collapse
-
#manager ⇒ HipTail::Manager
readonly
Returns HipTail::Manager.
-
#path ⇒ HipTail::Manager
readonly
Returns HipTail::Manager.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(params) ⇒ RackApp
constructor
A new instance of RackApp.
Constructor Details
#initialize(params) ⇒ RackApp
Returns a new instance of RackApp.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hiptail/web/rack_app.rb', line 29 def initialize(params) params = params.dup @manager = params.delete(:manager) || Manager.new @handler = Web::Handler.new(@manager) params[:base_path] ||= '/' params[:webhook_path] ||= '/event' params[:installed_path] ||= '/install' params[:capability_path] ||= '/cap' @capability_params = params base_url = URI.parse('http://example.com/').merge(params[:base_path]) @path = { :base => base_url.request_uri, } [ :webhook, :installed, :capability ].each do |key| @path[key] = base_url.merge('./' + params["#{key}_path".to_sym]).request_uri end @regex = {} @regex[:capability] = %r{\A #{Regexp.escape(@path[:capability])} \z}xm @regex[:event] = %r{\A #{Regexp.escape(@path[:webhook])} \z}xm @regex[:install] = %r{\A #{Regexp.escape(@path[:installed])} \z}xm @regex[:uninstall] = %r{\A #{Regexp.escape(@path[:installed])} / ([-0-9a-fA-F]+) \z}xm end |
Instance Attribute Details
#manager ⇒ HipTail::Manager (readonly)
Returns HipTail::Manager.
11 12 13 |
# File 'lib/hiptail/web/rack_app.rb', line 11 def manager @manager end |
#path ⇒ HipTail::Manager (readonly)
Returns HipTail::Manager.
11 12 13 |
# File 'lib/hiptail/web/rack_app.rb', line 11 def path @path end |
Instance Method Details
#call(env) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/hiptail/web/rack_app.rb', line 56 def call(env) req = Rack::Request.new(env) case req.path_info when @regex[:capability] if req.get? return on_capability(req) end when @regex[:event] if req.post? return on_event(req) end when @regex[:install] if req.post? return on_install(req) end when @regex[:uninstall] if req.delete? return on_uninstall(req, $1) end end return @handler.create_response({}, 404) end |