Class: Lita::Handlers::RubyGemsWebhooks::WebhookHandler

Inherits:
Lita::Handler
  • Object
show all
Defined in:
lib/lita/handlers/rubygems_webhooks/webhook_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.nameObject



10
11
12
# File 'lib/lita/handlers/rubygems_webhooks/webhook_handler.rb', line 10

def name
  'RubygemsWebhooks'
end

Instance Method Details

#handle_webhook(request, response) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lita/handlers/rubygems_webhooks/webhook_handler.rb', line 34

def handle_webhook(request, response)
  gem_info = JSON.parse(request.body.read)
  auth_header = request.env['HTTP_AUTHORIZATION']
  unless authentic_token?(auth_header, gem_info['name'], gem_info['version'], config.api_key)
    return handle_unauthentic_token(response)
  end
  target = Source.new(room: config.alert_channel)
  robot.send_messages(target, update_message(gem_info))
  response.status = 200
  response
end

#respond(response) ⇒ Object



30
31
32
# File 'lib/lita/handlers/rubygems_webhooks/webhook_handler.rb', line 30

def respond(response)
  response.reply index_message
end

#start_registrar(_payload) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/lita/handlers/rubygems_webhooks/webhook_handler.rb', line 46

def start_registrar(_payload)
  Registrar.configure do |configuration|
    configuration['api_key'] = config.api_key
    configuration['domain'] = config.domain
    configuration['hooks'] = config.gems
  end
  Registrar.configure_web_hooks
end