class Driftwood
Constants
- VERSION
Attributes
bigquery[R]
this allows other tools to register handlers and interact with the db
slack[R]
this allows other tools to register handlers and interact with the db
Public Class Methods
new(app=nil)
click to toggle source
Calls superclass method
# File lib/driftwood.rb, line 20 def initialize(app=nil) super(app) $logger.info "Starting Driftwood v#{Driftwood::VERSION}" @bigquery = Driftwood::Bigquery.new(settings.gcloud) @slack = Driftwood::Slack.new(settings.slack) @app_id = settings.slack[:client_id] @slack.authorize(cached_auth) @plugins = settings.plugins.map do |plugin, config| filename = plugin.snake_case begin require "driftwood/plugin/#{filename}" rescue LoadError require filename end Driftwood::Plugin::const_get(plugin).new(config, @slack, @bigquery) end # help handler @slack.register_handler('message') do |team_id, event_data| user = event_data['user'] text = event_data['text'] case text when /^help$/i @slack.send_response(team_id, user, "Usage for all plugins:") @plugins.each do |plugin| next unless plugin.usage @slack.send_response(team_id, user, plugin.usage) end when /^help (\w*)$/i name = $1 @slack.send_response(team_id, user, "Usage for #{name}:") @plugins.each do |plugin| next unless plugin.name = name.downcase @slack.send_response(team_id, user, plugin.usage) end end end end
Public Instance Methods
cached_auth()
click to toggle source
# File lib/driftwood.rb, line 102 def cached_auth @bigquery.get_auth_tokens(@app_id) end
save_auth_cache(auth)
click to toggle source
# File lib/driftwood.rb, line 106 def save_auth_cache(auth) @bigquery.insert_team(auth, @app_id) end