lib/socrates/adapters/console.rb in socrates-0.1.10 vs lib/socrates/adapters/console.rb in socrates-0.1.11

- old
+ new

@@ -1,49 +1,50 @@ require "socrates/adapters/stubs" module Socrates module Adapters class Console + include StubUserDirectory + CLIENT_ID = "CONSOLE" + CHANNEL = "C1" - attr_accessor :email, :users - def initialize(name: "@socrates") - @name = name - @users = [] + super() + @name = name end - def client_id_from_context(_context) + def client_id_from(context: nil, user: nil) + raise ArgumentError, "Must provide one of :context or :user" if context.nil? && user.nil? + CLIENT_ID end - def send_message(message, *) + def channel_from(context: nil, user: nil) + raise ArgumentError, "Must provide one of :context or :user" if context.nil? && user.nil? + + CHANNEL + end + + def send_message(message, channel) + raise ArgumentError, "Channel is required" unless channel.present? + puts "\n#{colorize(@name, "32;1")}: #{message}" end - def send_direct_message(message, user, *) + def send_direct_message(message, user) + raise ArgumentError, "User is required" unless user.present? + name = if user.respond_to?(:name) user.name elsif user.respond_to?(:id) user.id else user end puts "\n[DM] #{colorize(name, "34;1")}: #{message}" - end - - def add_user(id: nil, name: nil, first: nil, last: nil, email: nil) - users << User.new(id, name, Profile.new(first, last, email)) - end - - def users_list(*) - Response.new(users) - end - - def lookup_email(*) - email end private def colorize(str, color_code)