socrates 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9bb99fd80afa2c0115599cf6deb59a48689aa48
4
- data.tar.gz: 7af67f0f859c82ff79fc2e59208b768dc41a9d16
3
+ metadata.gz: 1f0032b63152e0394fa4fd937f32f4c5bdfdfacb
4
+ data.tar.gz: bbe5c6deb6223862b6d3dc2d31f9645837b25352
5
5
  SHA512:
6
- metadata.gz: 1da101c9c7d1bb8ab6d77320a96038e7b83f0cc3d491bada410e11e315b7346aa1699abc2063cf52b300c4fff4d31da29d6172b4110dd25663e36dc872984186
7
- data.tar.gz: dcbcafde4c22bc45e2e1a0d0b08228e3c5dcf64c1d83150e78b8803720b2a3beb30ae73089cfac72e460d926037459b8e4862fd1eb5677e4b768b6c3c4da6890
6
+ metadata.gz: d278b58e1e84f5f2c72ea64197db4bfe6058bd8714810bcc1a84b1ae613dea7cd267345098d716005b681c561ba697b96963a403513e343cb42510605fd2b16d
7
+ data.tar.gz: d9fc427ba56a46e1ba8acdea37b82db4598325bdb53a267ba3a263d7f558993faaee359a639c6714ee48b81034e6cf6bbb54f4d58943d1c6c4ef724fc7e07a2d
data/exe/socrates CHANGED
@@ -38,9 +38,9 @@ def run_command(options)
38
38
  storage =
39
39
  case options[:storage]
40
40
  when "redis"
41
- Socrates::Storage::RedisStorage.new(url: ENV.fetch("REDIS_URL", "redis://localhost"))
41
+ Socrates::Storage::Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost"))
42
42
  else
43
- Socrates::Storage::MemoryStorage.new
43
+ Socrates::Storage::Memory.new
44
44
  end
45
45
 
46
46
  Socrates.configure do |config|
@@ -54,9 +54,9 @@ def run_command(options)
54
54
 
55
55
  case (adapter = options[:adapter])
56
56
  when "console"
57
- Socrates::Bots::CLIBot.new(state_factory: Socrates::SampleStates::StateFactory.new).start
57
+ Socrates::Bots::CLI.new(state_factory: Socrates::SampleStates::StateFactory.new).start
58
58
  when "slack"
59
- Socrates::Bots::SlackBot.new(state_factory: Socrates::SampleStates::StateFactory.new).start
59
+ Socrates::Bots::Slack.new(state_factory: Socrates::SampleStates::StateFactory.new).start
60
60
  else
61
61
  puts "Unknown adapter '#{adapter}'"
62
62
  exit 1
@@ -1,6 +1,8 @@
1
+ require "socrates/adapters/stubs"
2
+
1
3
  module Socrates
2
4
  module Adapters
3
- class ConsoleAdapter
5
+ class Console
4
6
  CLIENT_ID = "CONSOLE"
5
7
 
6
8
  attr_accessor :email, :users
@@ -1,6 +1,8 @@
1
+ require "socrates/adapters/stubs"
2
+
1
3
  module Socrates
2
4
  module Adapters
3
- class MemoryAdapter
5
+ class Memory
4
6
  CLIENT_ID = "MEMORY"
5
7
 
6
8
  attr_reader :history, :dms
@@ -1,6 +1,8 @@
1
+ require "active_support/core_ext/object"
2
+
1
3
  module Socrates
2
4
  module Adapters
3
- class SlackAdapter
5
+ class Slack
4
6
  def initialize(real_time_client)
5
7
  @real_time_client = real_time_client
6
8
  end
@@ -1,8 +1,11 @@
1
+ require "socrates/adapters/console"
2
+ require "socrates/core/dispatcher"
3
+
1
4
  module Socrates
2
5
  module Bots
3
- class CLIBot
6
+ class CLI
4
7
  def initialize(adapter: nil, state_factory:)
5
- @adapter = adapter || Adapters::ConsoleAdapter.new
8
+ @adapter = adapter || Adapters::Console.new
6
9
  @dispatcher = Core::Dispatcher.new(adapter: @adapter, state_factory: state_factory)
7
10
  end
8
11
 
@@ -1,10 +1,13 @@
1
1
  require "slack-ruby-client"
2
2
 
3
+ require "socrates/adapters/slack"
4
+ require "socrates/core/dispatcher"
5
+
3
6
  module Socrates
4
7
  module Bots
5
- class SlackBot
8
+ class Slack
6
9
  def initialize(state_factory:)
7
- Slack.configure do |config|
10
+ ::Slack.configure do |config|
8
11
  config.token = ENV["SLACK_API_TOKEN"]
9
12
  config.logger = Logger.new(STDOUT)
10
13
  config.logger.level = Logger::INFO
@@ -12,8 +15,8 @@ module Socrates
12
15
  raise "Missing ENV['SLACK_API_TOKEN']!" unless config.token
13
16
  end
14
17
 
15
- @slack_client = Slack::RealTime::Client.new
16
- @adapter = Adapters::SlackAdapter.new(@slack_client)
18
+ @slack_client = ::Slack::RealTime::Client.new
19
+ @adapter = Adapters::Slack.new(@slack_client)
17
20
  @dispatcher = Core::Dispatcher.new(adapter: @adapter, state_factory: state_factory)
18
21
  end
19
22
 
@@ -0,0 +1,27 @@
1
+ require "socrates/logger"
2
+ require "socrates/storage/memory"
3
+
4
+ module Socrates
5
+ def self.config
6
+ @config ||= Configuration.new
7
+ end
8
+
9
+ def self.configure
10
+ yield(config)
11
+ end
12
+
13
+ class Configuration
14
+ attr_accessor :view_path
15
+ attr_accessor :storage
16
+ attr_accessor :error_message
17
+ attr_accessor :expired_timeout # seconds
18
+ attr_accessor :logger
19
+
20
+ def initialize
21
+ @storage = Storage::Memory.new
22
+ @error_message = "Sorry, something went wrong. We'll have to start over..."
23
+ @expired_timeout = 30.minutes
24
+ @logger = Socrates::Logger.default
25
+ end
26
+ end
27
+ end
@@ -1,8 +1,11 @@
1
1
  require "hashie"
2
+ require "active_support/all"
2
3
 
4
+ require "socrates/configuration"
3
5
  require "socrates/logger"
4
6
  require "socrates/string_helpers"
5
- require "socrates/storage/storage"
7
+ require "socrates/storage/memory"
8
+ require "socrates/core/state"
6
9
  require "socrates/core/state_data"
7
10
 
8
11
  module Socrates
@@ -11,10 +14,10 @@ module Socrates
11
14
  def initialize(adapter:, state_factory:, storage: nil)
12
15
  @adapter = adapter
13
16
  @state_factory = state_factory
14
- @storage = storage || Socrates::Config.storage || Storage::MemoryStorage.new
17
+ @storage = storage || Socrates.config.storage
15
18
 
16
- @logger = Socrates::Config.logger || Socrates::Logger.default
17
- @error_message = Socrates::Config.error_message || DEFAULT_ERROR_MESSAGE
19
+ @logger = Socrates.config.logger
20
+ @error_message = Socrates.config.error_message || DEFAULT_ERROR_MESSAGE
18
21
  end
19
22
 
20
23
  # rubocop:disable Metrics/AbcSize
@@ -105,7 +108,7 @@ module Socrates
105
108
  def state_data_expired?(state_data)
106
109
  return unless state_data.timestamp.present?
107
110
 
108
- state_data.elapsed_time > (Config.expired_timeout || 30.minutes)
111
+ state_data.elapsed_time > (Socrates.config.expired_timeout || 30.minutes)
109
112
  end
110
113
 
111
114
  def instantiate_state(state_data, context)
@@ -1,6 +1,11 @@
1
1
  require "hashie"
2
2
  require "erb"
3
3
 
4
+ require "socrates/configuration"
5
+ require "socrates/logger"
6
+ require "socrates/string_helpers"
7
+ require "socrates/core/state_data"
8
+
4
9
  module Socrates
5
10
  module Core
6
11
  module State
@@ -12,7 +17,7 @@ module Socrates
12
17
  @context = context
13
18
  @next_state_id = nil
14
19
  @next_state_action = nil
15
- @logger = Socrates::Config.logger || Socrates::Logger.default
20
+ @logger = Socrates.config.logger || Socrates::Logger.default
16
21
  end
17
22
 
18
23
  def next_state_id
@@ -1,7 +1,7 @@
1
1
  require "hashie"
2
2
  require "json"
3
- require "set"
4
3
  require "yaml"
4
+ require "active_support/core_ext/time"
5
5
 
6
6
  module Socrates
7
7
  module Core
@@ -13,7 +13,7 @@ module Socrates
13
13
  @state_action = state_action
14
14
  @timestamp = Time.current
15
15
  @data = data
16
- @temporary_keys = Set.new(temporary_keys)
16
+ @temporary_keys = temporary_keys
17
17
  end
18
18
 
19
19
  def elapsed_time
@@ -33,8 +33,7 @@ module Socrates
33
33
  end
34
34
 
35
35
  def has_temporary_key?(key)
36
- # The !! turns nils into false, which shouldn"t be necessary, but seems to be after the set is loaded from yaml.
37
- @temporary_keys.include?(key) == true
36
+ @temporary_keys.include?(key)
38
37
  end
39
38
 
40
39
  def get(key, clear: false)
@@ -1,5 +1,6 @@
1
1
  require "date"
2
2
 
3
+ require "socrates/string_helpers"
3
4
  require "socrates/core/state"
4
5
 
5
6
  module Socrates
@@ -0,0 +1,25 @@
1
+ module Socrates
2
+ module Storage
3
+ class Memory
4
+ def initialize
5
+ @memory = {}
6
+ end
7
+
8
+ def has_key?(key)
9
+ @memory.has_key?(key)
10
+ end
11
+
12
+ def clear(key)
13
+ @memory.delete(key)
14
+ end
15
+
16
+ def get(key)
17
+ @memory[key]
18
+ end
19
+
20
+ def put(key, value)
21
+ @memory[key] = value
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require "redis"
2
+
3
+ module Socrates
4
+ module Storage
5
+ class Redis
6
+ def initialize(url: "redis://localhost")
7
+ @redis = Redis.new(url: url)
8
+ end
9
+
10
+ def has_key?(key)
11
+ @redis.exists(key)
12
+ end
13
+
14
+ def clear(key)
15
+ @redis.del(key)
16
+ end
17
+
18
+ def get(key)
19
+ @redis.get(key)
20
+ end
21
+
22
+ def put(key, value)
23
+ @redis.set(key, value)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Socrates
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/socrates.rb CHANGED
@@ -1,20 +1,19 @@
1
1
  # Socrates
2
2
  require "socrates/version"
3
- require "socrates/config"
3
+ require "socrates/configuration"
4
4
  require "socrates/logger"
5
5
  require "socrates/string_helpers"
6
- require "socrates/adapters/console_adapter"
7
- require "socrates/adapters/memory_adapter"
8
- require "socrates/adapters/slack_adapter"
6
+ require "socrates/adapters/console"
7
+ require "socrates/adapters/memory"
8
+ require "socrates/adapters/slack"
9
9
  require "socrates/adapters/stubs"
10
- require "socrates/storage/storage"
10
+ require "socrates/storage/memory"
11
+ require "socrates/storage/redis"
11
12
  require "socrates/core/state_data"
12
13
  require "socrates/core/state"
13
14
  require "socrates/core/dispatcher"
14
-
15
- # Bot implementations
16
- require "socrates/bots/cli_bot"
17
- require "socrates/bots/slack_bot"
15
+ require "socrates/bots/cli"
16
+ require "socrates/bots/slack"
18
17
 
19
18
  module Socrates
20
19
  end
data/socrates.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.required_ruby_version = ">= 2.3.0"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.14"
29
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rake", "~> 10.5"
30
30
  spec.add_development_dependency "rspec", "~> 3.5"
31
31
  spec.add_development_dependency "rubocop", "~> 0.48.1"
32
32
  spec.add_development_dependency "timecop", "~> 0.8.1"
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "celluloid-io", ">= 0.17.3"
36
36
  spec.add_dependency "hashie", ">= 3.5.5"
37
37
  spec.add_dependency "redis", ">= 3.3.3"
38
- spec.add_dependency "slack-ruby-client", ">= 0.8.0"
38
+ spec.add_dependency "slack-ruby-client", ">= 0.8.1"
39
39
  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.7
4
+ version: 0.1.8
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-05-01 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '10.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '10.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: 0.8.0
145
+ version: 0.8.1
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: 0.8.0
152
+ version: 0.8.1
153
153
  description:
154
154
  email:
155
155
  - christian@carbonfive.com
@@ -170,19 +170,20 @@ files:
170
170
  - circle.yml
171
171
  - exe/socrates
172
172
  - lib/socrates.rb
173
- - lib/socrates/adapters/console_adapter.rb
174
- - lib/socrates/adapters/memory_adapter.rb
175
- - lib/socrates/adapters/slack_adapter.rb
173
+ - lib/socrates/adapters/console.rb
174
+ - lib/socrates/adapters/memory.rb
175
+ - lib/socrates/adapters/slack.rb
176
176
  - lib/socrates/adapters/stubs.rb
177
- - lib/socrates/bots/cli_bot.rb
178
- - lib/socrates/bots/slack_bot.rb
179
- - lib/socrates/config.rb
177
+ - lib/socrates/bots/cli.rb
178
+ - lib/socrates/bots/slack.rb
179
+ - lib/socrates/configuration.rb
180
180
  - lib/socrates/core/dispatcher.rb
181
181
  - lib/socrates/core/state.rb
182
182
  - lib/socrates/core/state_data.rb
183
183
  - lib/socrates/logger.rb
184
184
  - lib/socrates/sample_states.rb
185
- - lib/socrates/storage/storage.rb
185
+ - lib/socrates/storage/memory.rb
186
+ - lib/socrates/storage/redis.rb
186
187
  - lib/socrates/string_helpers.rb
187
188
  - lib/socrates/version.rb
188
189
  - sample-conversation-console.gif
@@ -1,21 +0,0 @@
1
- module Socrates
2
- module Config
3
- extend self
4
-
5
- attr_accessor :view_path
6
- attr_accessor :storage
7
- attr_accessor :error_message
8
- attr_accessor :expired_timeout # seconds
9
- attr_accessor :logger
10
- end
11
-
12
- class << self
13
- def configure
14
- block_given? ? yield(Config) : Config
15
- end
16
-
17
- def config
18
- Config
19
- end
20
- end
21
- end
@@ -1,50 +0,0 @@
1
- require "redis"
2
- require "json"
3
-
4
- module Socrates
5
- module Storage
6
- class MemoryStorage
7
- def initialize
8
- @storage = {}
9
- end
10
-
11
- def has_key?(key)
12
- @storage.has_key? key
13
- end
14
-
15
- def clear(key)
16
- @storage.delete key
17
- end
18
-
19
- def get(key)
20
- @storage[key]
21
- end
22
-
23
- def put(key, value)
24
- @storage[key] = value
25
- end
26
- end
27
-
28
- class RedisStorage
29
- def initialize(url: "redis://localhost")
30
- @redis = Redis.new(url: url)
31
- end
32
-
33
- def has_key?(key)
34
- @redis.exists(key)
35
- end
36
-
37
- def clear(key)
38
- @redis.del key
39
- end
40
-
41
- def get(key)
42
- @redis.get(key)
43
- end
44
-
45
- def put(key, value)
46
- @redis.set(key, value)
47
- end
48
- end
49
- end
50
- end