bot 0.0.28 → 0.0.29

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: 199bd38056860b8c29af868d60901ea40b670d88
4
- data.tar.gz: fa4f7acd8c0e28280782922a3e84a8a1521668bb
3
+ metadata.gz: 3ccf186eafc433707ebd2f1d0c01baf5f7df80f0
4
+ data.tar.gz: 6282e89eb93a1d0a846a6c5e452630495b4ad989
5
5
  SHA512:
6
- metadata.gz: 7055c2da1c9e56ee031c9f686d99673cb6a27754d83095167d2ec7a5fd9e71b95c7465e6671a73ddfc0e9092f9ed6bb31b69e53b0cc4698daf467c6c3a14c9b4
7
- data.tar.gz: b168ce104af5601224016fd62ee4c4a9927e06a1b884e6e6273251d12b3ecea90869d1e70ad809f2e2435497a311e5bbc8005ec458d03b3081bfb275770328b8
6
+ metadata.gz: cd7d122593fb198370ebffb9beaeceb08192abd8c4caab112e12b01c2b001525ca337fe428a3ba28f3864dac8dd3cdb0fc1c6b07f384a0fb826d2c0095f3a2dd
7
+ data.tar.gz: db8eff5f04113b0133bac6f9e49898a6644ca53a20fd94e4817fc91e72cbe6bb5e10dbf75cb250d2e33839a04735d067ec21fe3d59dcb258dea587c09ba3d9b9
data/lib/bot.rb CHANGED
@@ -4,6 +4,7 @@ require "bot/responder"
4
4
  require "bot/route_extensions"
5
5
  require "bot/adapter"
6
6
  require "bot/configuration"
7
+ require "bot/context"
7
8
  require "bot/responder_chain"
8
9
  require "bot/rspec.rb"
9
10
 
@@ -16,6 +16,6 @@ module Bot
16
16
  end
17
17
 
18
18
  class Configuration
19
- attr_accessor :adapter
19
+ attr_accessor :adapter, :redis
20
20
  end
21
21
  end
@@ -0,0 +1,42 @@
1
+ module Bot
2
+ class Context
3
+ attr_accessor :redis_client, :user
4
+
5
+ def initialize(user, redis_client)
6
+ @redis_client = redis_client
7
+ @user = user
8
+ end
9
+
10
+ def method_missing(m, *args, &block)
11
+ if m =~ /.+=/
12
+ self.add(m.to_s.gsub('=', ''), *args)
13
+ else
14
+ self.get(m)
15
+ end
16
+ end
17
+
18
+ def get(field)
19
+ data = $redis.hget(context_key, field)
20
+ JSON.parse(data) if data.present?
21
+ rescue JSON::ParserError
22
+ data
23
+ end
24
+
25
+ def set(context)
26
+ self.clear
27
+ $redis.hmset(context_key, context.map { |k, v| [k, v] }.flatten)
28
+ end
29
+
30
+ def add(field, content)
31
+ $redis.hset context_key, field, content
32
+ end
33
+
34
+ def clear
35
+ $redis.del context_key
36
+ end
37
+
38
+ def context_key
39
+ "bot:context:#{user.id}"
40
+ end
41
+ end
42
+ end
@@ -15,8 +15,9 @@ module Bot
15
15
  end
16
16
 
17
17
  def execute_chain(message, responses, user)
18
+ context = Bot::Context.new(user, Bot.configuration.redis)
18
19
  responder_chain.responders.each do |responder|
19
- responder = responder.new(message, user, responses, self)
20
+ responder = responder.new(message, user, responses, self, context)
20
21
  if responder.can_respond_to_type?(message['type']) && responder.can_handle?
21
22
  responses << responder.handle
22
23
  break
@@ -5,7 +5,7 @@ module Bot
5
5
 
6
6
  class_attribute :respond_to_types
7
7
 
8
- attr_reader :message, :user, :responses, :handler
8
+ attr_reader :message, :user, :responses, :handler, :context
9
9
 
10
10
  def self.respond_to(*types)
11
11
  new_types = (respond_to_types || []).dup
@@ -13,11 +13,12 @@ module Bot
13
13
  self.respond_to_types = new_types.freeze
14
14
  end
15
15
 
16
- def initialize(message, user, responses, handler)
16
+ def initialize(message, user, responses, handler, context)
17
17
  @message = message
18
18
  @user = user
19
19
  @responses = responses
20
20
  @handler = handler
21
+ @context = context
21
22
  end
22
23
 
23
24
  def can_respond_to_type?(type)
@@ -1,3 +1,3 @@
1
1
  module Bot
2
- VERSION = "0.0.28"
2
+ VERSION = "0.0.29"
3
3
  end
@@ -2902,6 +2902,49 @@ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2902
2902
  NavigationTest: test_notify_special_types
2903
2903
  -----------------------------------------
2904
2904
  Started POST "/bot/notify" for 127.0.0.1 at 2016-04-21 14:45:54 -0400
2905
+ Processing by Bot::BotController#notify as HTML
2906
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2907
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2908
+  (0.1ms) rollback transaction
2909
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
2910
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
2911
+  (0.1ms) select sqlite_version(*)
2912
+  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
2913
+  (0.1ms) SELECT version FROM "schema_migrations"
2914
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
2915
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2916
+  (0.1ms) begin transaction
2917
+ -------------------
2918
+ BotTest: test_truth
2919
+ -------------------
2920
+  (0.0ms) rollback transaction
2921
+  (0.0ms) begin transaction
2922
+ ---------------------------------------
2923
+ NavigationTest: test_notify_multi_types
2924
+ ---------------------------------------
2925
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-27 21:12:56 -0400
2926
+ Processing by Bot::BotController#notify as HTML
2927
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2928
+ Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms)
2929
+  (0.1ms) rollback transaction
2930
+  (0.1ms) begin transaction
2931
+ ---------------------------
2932
+ NavigationTest: test_notify
2933
+ ---------------------------
2934
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-27 21:12:56 -0400
2935
+ Processing by Bot::BotController#notify as HTML
2936
+ Parameters: {"bot"=>ApplicationHandler}
2937
+ Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
2938
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-27 21:12:56 -0400
2939
+ Processing by Bot::BotController#notify as HTML
2940
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2941
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2942
+  (0.1ms) rollback transaction
2943
+  (0.1ms) begin transaction
2944
+ -----------------------------------------
2945
+ NavigationTest: test_notify_special_types
2946
+ -----------------------------------------
2947
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-27 21:12:56 -0400
2905
2948
  Processing by Bot::BotController#notify as HTML
2906
2949
  Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2907
2950
  Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Morris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-21 00:00:00.000000000 Z
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +109,7 @@ files:
95
109
  - lib/bot/adapters/kik.rb
96
110
  - lib/bot/adapters/test.rb
97
111
  - lib/bot/configuration.rb
112
+ - lib/bot/context.rb
98
113
  - lib/bot/engine.rb
99
114
  - lib/bot/handler.rb
100
115
  - lib/bot/responder.rb