socrates 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73a8be96fc0b04e14a3137c1ad12ab9a7bcecd88
4
- data.tar.gz: 1b55c1e1a2422ce84e3a60d2317b44876862cfbb
3
+ metadata.gz: 67a86f6c23427a17a1271fc44b51b656b7e3e8c6
4
+ data.tar.gz: 331e7f16f68d78ca66490fc985861418cc891bf0
5
5
  SHA512:
6
- metadata.gz: f4049f03b482773651d22cc6fa3dfb29d055fc1762d35a99b4fb7592fd8c1567240e6d552cb11712988df4e6173d73004ddee39b47470cfad32dd33a88c5f99c
7
- data.tar.gz: 1dcaca7bed84ac8fb3219959ecf7fbec8fe5d52c66749842012d7252d64074a521fff2f9a972fcab92cf99e009a3e022f3f7d43bac5ef2c40effde5c6bb51923
6
+ metadata.gz: c8445176b8a001cbe6957e23f9e4f4909f376439d9cc0aa045a5f23ecfbeccd850331c1f31313f8a12987222ab8f70900d2bf0a2fd472b6b62b0c0c63a0aeee2
7
+ data.tar.gz: ff3aeced1731694a2fe660658c83c24f2e21db08755531a64639046e66ab39ad2190c0796d27af612547a5793646ce0345f0441fb15c4d2070437f911c8b0907
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
 
13
13
  # rspec failure tracking
14
14
  .rspec_status
15
+ SCRATCH.md
data/README.md CHANGED
@@ -153,11 +153,12 @@ restarting the bot. Use the `-d` flag for debugging log information.
153
153
 
154
154
  ## Core Concepts
155
155
 
156
- * Dispatcher
157
- * Adapter (Slack, Console, Memory)
158
- * Storage (Memory, Redis)
159
- * State
160
- * Helpers
156
+ * Dispatcher - Kicks off conversations, responds to input, and provides general state managements.
157
+ * Session - Buffers messages to channels, until flushed by an Adapter.
158
+ * Adapter (Slack, Console, Memory) - Captures service specific functionality.
159
+ * Storage (Memory, Redis) - Handles persisting conversational state.
160
+ * State - Represents a state of a conversation, provides helpers for state implementations.
161
+ * Helpers - Simple helpers.
161
162
 
162
163
  TODO: Expand descriptions. Include a diagram.
163
164
 
@@ -3,11 +3,16 @@ require "socrates/adapters/stubs"
3
3
  module Socrates
4
4
  module Adapters
5
5
  module Adapter
6
- def client_id_from(_context: nil, _user: nil)
6
+ # Many of the methods in the Adapter module serve as an interface for Adapter implementations to
7
+ # implement. We want to serve as an example, even if we don't provide implementations here. Therefor,
8
+ # we're disabling this cop to avoid its warnings.
9
+ # rubocop:disable Lint/UnusedMethodArgument
10
+
11
+ def client_id_from(context: nil, user: nil)
7
12
  raise NotImplementedError
8
13
  end
9
14
 
10
- def channel_from(_context: nil, _user: nil)
15
+ def channel_from(context: nil, user: nil)
11
16
  raise NotImplementedError
12
17
  end
13
18
 
@@ -21,7 +26,7 @@ module Socrates
21
26
 
22
27
  def queue_direct_message(session, message, recipient)
23
28
  raise ArgumentError, "recipient is required" unless recipient.present?
24
- raise ArgumentError, "recipient.if is required" unless recipient.id.present?
29
+ raise ArgumentError, "recipient.id is required" unless recipient.id.present?
25
30
 
26
31
  dm_channel = channel_from(user: recipient)
27
32
 
@@ -35,29 +40,27 @@ module Socrates
35
40
  end
36
41
  end
37
42
 
38
- def send_message(_channel, _message)
43
+ def send_message(channel, message)
39
44
  raise NotImplementedError
40
45
  end
41
46
 
42
- def user_from(_context:)
47
+ def users(include_deleted: false, include_bots: false)
43
48
  raise NotImplementedError
44
49
  end
45
50
 
46
- def users_list(*)
51
+ def user_from(context:)
47
52
  raise NotImplementedError
48
53
  end
49
54
 
50
- def lookup_user(_email:)
51
- raise NotImplementedError
55
+ def lookup_user(email:)
56
+ users.members.find { |user| email == user.profile&.email }
52
57
  end
53
58
 
54
59
  def lookup_email(*)
55
60
  raise NotImplementedError
56
61
  end
57
62
 
58
- def users_channel(_user)
59
- raise NotImplementedError
60
- end
63
+ # rubocop:enable Lint/UnusedMethodArgument
61
64
  end
62
65
  end
63
66
  end
@@ -27,18 +27,18 @@ module Socrates
27
27
  raise ArgumentError, "Expected context to respond to :channel" unless context.respond_to?(:channel)
28
28
  return context.channel
29
29
  end
30
- return lookup_im_channel(user) unless user.nil?
30
+ return lookup_dm_channel(user) unless user.nil?
31
31
 
32
32
  raise ArgumentError, "Must provide one of context or user"
33
33
  end
34
34
 
35
- def users_list(include_deleted: false, include_bots: false)
35
+ def users(include_deleted: false, include_bots: false)
36
36
  client = @real_time_client.web_client
37
37
 
38
- client.users_list.tap do |response|
38
+ client.users_list.tap { |response|
39
39
  response.members.reject!(&:deleted?) unless include_deleted
40
40
  response.members.reject!(&:is_bot?) unless include_bots
41
- end
41
+ }.members
42
42
  end
43
43
 
44
44
  def user_from(context:)
@@ -50,11 +50,6 @@ module Socrates
50
50
  info.present? ? info.user : nil
51
51
  end
52
52
 
53
- # Note: this triggers a call to the Slack API which makes it ill-suited for use within a loop.
54
- def lookup_user(email:)
55
- users_list.members.find { |user| email == user.profile&.email }
56
- end
57
-
58
53
  def lookup_email(context:)
59
54
  raise ArgumentError, "Expected context to respond to :user" unless context.respond_to?(:user)
60
55
 
@@ -69,7 +64,7 @@ module Socrates
69
64
  @real_time_client.message(text: message, channel: channel)
70
65
  end
71
66
 
72
- def lookup_im_channel(user)
67
+ def lookup_dm_channel(user)
73
68
  im = @real_time_client.ims.values.find { |i| i.user == user }
74
69
 
75
70
  return im if im.present?
@@ -1,10 +1,8 @@
1
1
  module Socrates
2
2
  module Adapters
3
3
  #
4
- # Response, User, Profile are POROs that represent keys concepts that exist in Slack (or other chat systems).
4
+ # User, Profile are POROs that represent keys concepts that exist in Slack (or other chat systems).
5
5
  #
6
- Response = Struct.new(:members)
7
-
8
6
  User = Struct.new(:id, :name, :tz_offset, :profile) do
9
7
  def real_name
10
8
  return "" if profile.nil?
@@ -20,7 +18,7 @@ module Socrates
20
18
  # to be used by the stubbed versions of adapters (like Console and Memory).
21
19
  #
22
20
  module StubUserDirectory
23
- attr_accessor :default_user, :users
21
+ attr_accessor :default_user
24
22
 
25
23
  def initialize
26
24
  @users = []
@@ -34,16 +32,12 @@ module Socrates
34
32
  end
35
33
  # rubocop:enable Metrics/ParameterLists
36
34
 
37
- def user_from(*)
38
- @default_user
35
+ def users(*)
36
+ @users
39
37
  end
40
38
 
41
- def users_list(*)
42
- Response.new(@users)
43
- end
44
-
45
- def lookup_user(email:)
46
- @users.find { |user| email == user.profile&.email }
39
+ def user_from(*)
40
+ @default_user
47
41
  end
48
42
 
49
43
  def lookup_email(*)
@@ -51,7 +51,7 @@ module Socrates
51
51
  @adapter.queue_message(@session, message, send_now: send_now)
52
52
  end
53
53
 
54
- def send_message(to:, message:) # TODO: direct_message? send_dm?
54
+ def send_message(to:, message:)
55
55
  displayable_to = to.respond_to?(:id) ? to.id : to
56
56
 
57
57
  @logger.info %Q(#{@session.channel} send direct to #{displayable_to}: "#{format_for_logging(message)}")
@@ -178,7 +178,7 @@ module Socrates
178
178
  end
179
179
 
180
180
  def listen(message)
181
- users = @adapter.users_list.members.sample(2)
181
+ users = @adapter.users.sample(2)
182
182
 
183
183
  users.each do |user|
184
184
  send_message(to: user, message: "Message: #{message}")
@@ -1,3 +1,3 @@
1
1
  module Socrates
2
- VERSION = "0.1.17"
2
+ VERSION = "0.1.18"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socrates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Nelson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-10 00:00:00.000000000 Z
11
+ date: 2017-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler