Module: Socrates::Adapters::Adapter

Included in:
Console, Memory, Slack
Defined in:
lib/socrates/adapters/adapter.rb

Instance Method Summary collapse

Instance Method Details

#channel_from(context: nil, user: nil) ⇒ Object

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/socrates/adapters/adapter.rb', line 13

def channel_from(context: nil, user: nil)
  raise NotImplementedError
end

#client_id_from(context: nil, user: nil) ⇒ Object

Many of the methods in the Adapter module serve as an interface for Adapter implementations to implement. We want to serve as an example, even if we don’t provide implementations here.

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/socrates/adapters/adapter.rb', line 9

def client_id_from(context: nil, user: nil)
  raise NotImplementedError
end

#flush_session(session, channel: nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/socrates/adapters/adapter.rb', line 34

def flush_session(session, channel: nil)
  session.messages.select { |c, _| channel.nil? || channel == c }.each do |c, messages|
    send_message(c, messages.join("\n\n"))
    messages.clear
  end
end

#lookup_emailObject

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/socrates/adapters/adapter.rb', line 57

def lookup_email(*)
  raise NotImplementedError
end

#lookup_user(email:) ⇒ Object



53
54
55
# File 'lib/socrates/adapters/adapter.rb', line 53

def lookup_user(email:)
  users.members.find { |user| email == user.profile&.email }
end

#queue_direct_message(session, message, recipient) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
# File 'lib/socrates/adapters/adapter.rb', line 25

def queue_direct_message(session, message, recipient)
  raise ArgumentError, "recipient is required" unless recipient.present?
  raise ArgumentError, "recipient.id is required" unless recipient.id.present?

  dm_channel = channel_from(user: recipient)

  session.messages[dm_channel] << message
end

#queue_message(session, message, send_now: false) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/socrates/adapters/adapter.rb', line 17

def queue_message(session, message, send_now: false)
  raise ArgumentError, "session is required" unless session.present?
  raise ArgumentError, "session.channel is required" unless session.channel.present?

  session.messages[session.channel] << message
  flush_session(session, channel: session.channel) if send_now
end

#send_message(channel, message) ⇒ Object

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/socrates/adapters/adapter.rb', line 41

def send_message(channel, message)
  raise NotImplementedError
end

#user_from(context:) ⇒ Object

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/socrates/adapters/adapter.rb', line 49

def user_from(context:)
  raise NotImplementedError
end

#users(include_deleted: false, include_bots: false) ⇒ Object

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/socrates/adapters/adapter.rb', line 45

def users(include_deleted: false, include_bots: false)
  raise NotImplementedError
end