Class: HipTail::Web::RackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptail/web/rack_app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ RackApp

Returns a new instance of RackApp.

Parameters:

  • params (Hash)

    Capability parameters (and manager)

Options Hash (params):

  • :manager (HipTail::Manager)

    HipTail::Manager instance (optional)

  • :key (String)

    Identical key for integration

  • :name (String)

    integration name

  • :base_url (String)

    Base URL for integration

  • :capability_url (String)

    URL for capability

  • :webhook_url (String)

    URL for event webhook

  • :installed_url (String)

    URL for installed / uninstalled event webhook

  • :description (String) — default: same as :name

    integration description (optional)

  • :vendor_name (String) — default: same as :name

    Vendor name (optional)

  • :vendor_url (String) — default: same as :base_url

    Vendor URL (optional)

  • :homepage_url (String) — default: same as :base_url

    Homepage (optional)

  • :sender_name (String) — default: same as :name

    Name of notification sender (optional)

  • :allow_global (String) — default: true

    Allow global installation (optional)

  • :allow_room (String) — default: true

    Allow room installation (optional)

  • :message_filter (String)

    Room message filter regexp (optional)



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

#managerHipTail::Manager (readonly)

Returns HipTail::Manager.

Returns:



11
12
13
# File 'lib/hiptail/web/rack_app.rb', line 11

def manager
  @manager
end

#pathHipTail::Manager (readonly)

Returns HipTail::Manager.

Returns:



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