rubotnik 0.2.1 → 0.2.2

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
  SHA256:
3
- metadata.gz: dfec0763c4edd0680ea995ab6d4de3f8c18ab2bfb15f4e267068b546c9e39390
4
- data.tar.gz: 06d5e0d7d702ccb63ba4a173f705da25f64c76e189ef35d1bc59994257005734
3
+ metadata.gz: 3475118db8de10d630af79b5d676766f8a13b1a51ac858495a5ca605960c8bcf
4
+ data.tar.gz: 52bd2b44ae5c5c781f65498418b99d5b49b50e4d3e7ae3661cf99daaf113792c
5
5
  SHA512:
6
- metadata.gz: af0c8bad43c4a19c71ef3cffd0e9dd94f5bb07ae23245c3038738da56b3fede8bb98d8e642544265c6def6ec0760c86eca6216d31614188ee335094a0b6a9366
7
- data.tar.gz: 8047dfa3db4aaf51a102cf29100b818030ef1a4c93cbe48f9126af83f601eaebcdee839bacd9beed0791e31c7ea55cd200b03c4e06b14a96312ee83594282f60
6
+ metadata.gz: 770c79520f2bb61efce31f3c3f8666e6ce49d98cd6918d07ef166141b9615ada1e75bb6b6080b55b581bd5f81c73f7fc1e496e5d39230281980076480433b8e5
7
+ data.tar.gz: c8ce2a56f8ce8d4e5ea187fc96d0aaccdd720034da437cdd32bfc0626fa61f02ee2123733f5285fd48989f3ce51a960ea13e760a2fc5bf688332d28f55731d0f
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ .ruby-version
data/README.md CHANGED
@@ -408,9 +408,7 @@ Now don't forget to go back to your Facebook developer console and change the ad
408
408
 
409
409
  ## Coming next
410
410
 
411
- * Proper implementation of logging (for now it's just `p` and `puts` statements sprinkled around the code) with ability to choose a logging level.
412
-
413
- * More powerful DSL for parsing user input and binding it to commands.
411
+ * More powerful DSL for parsing user input and binding it to commands.
414
412
 
415
413
  * NLP integration with Wit.AI (that allow for more things then the built-in NLP capabilities of Messenger platform, including a wrapper around Wit's interactive learning methods) is in the works and will be added to the gem some time in 2018...
416
414
 
data/lib/rubotnik.rb CHANGED
@@ -15,31 +15,43 @@ require 'ui/image_attachment'
15
15
  require 'ui/quick_replies'
16
16
  require 'sinatra'
17
17
  require 'facebook/messenger'
18
+ require 'logger'
19
+
18
20
  include Facebook::Messenger
19
21
 
20
22
  module Rubotnik
21
- def self.subscribe(token)
22
- Facebook::Messenger::Subscriptions.subscribe(access_token: token)
23
- end
23
+ class << self
24
+ attr_writer :logger
25
+
26
+ def logger
27
+ @logger ||= Logger.new($stdout).tap do |log|
28
+ log.progname = self.name
29
+ end
30
+ end
24
31
 
25
- def self.route(event, &block)
26
- if [:message, :postback].include?(event)
27
- Bot.on event do |e|
28
- case e
29
- when Facebook::Messenger::Incoming::Message
30
- Rubotnik::MessageDispatch.new(e).route(&block)
31
- when Facebook::Messenger::Incoming::Postback
32
- Rubotnik::PostbackDispatch.new(e).route(&block)
32
+ def route(event, &block)
33
+ if [:message, :postback].include?(event)
34
+ Bot.on event do |e|
35
+ case e
36
+ when Facebook::Messenger::Incoming::Message
37
+ Rubotnik::MessageDispatch.new(e).route(&block)
38
+ when Facebook::Messenger::Incoming::Postback
39
+ Rubotnik::PostbackDispatch.new(e).route(&block)
40
+ end
33
41
  end
42
+ else
43
+ Bot.on(event, &block)
34
44
  end
35
- else
36
- Bot.on(event, &block)
37
45
  end
38
- end
39
46
 
40
- def self.set_profile(*payloads)
41
- payloads.each do |payload|
42
- Facebook::Messenger::Profile.set(payload, access_token: ENV['ACCESS_TOKEN'])
47
+ def subscribe(token)
48
+ Facebook::Messenger::Subscriptions.subscribe(access_token: token)
49
+ end
50
+
51
+ def set_profile(*payloads)
52
+ payloads.each do |payload|
53
+ Facebook::Messenger::Profile.set(payload, access_token: ENV['ACCESS_TOKEN'])
54
+ end
43
55
  end
44
56
  end
45
57
  end
@@ -63,10 +63,10 @@ module Rubotnik
63
63
  @message.typing_off
64
64
  case response.code
65
65
  when 200
66
- puts "Data received from Graph API: #{response.body}" # logging
66
+ Rubotnik.logger.info "Data received from Graph API: #{response.body}" # logging
67
67
  return JSON.parse(response.body, symbolize_names: true)
68
68
  else
69
- puts "Request failed: #{response.body}"
69
+ Rubotnik.logger.info "Request failed: #{response.body}"
70
70
  return false
71
71
  end
72
72
  end
@@ -20,7 +20,7 @@ module Rubotnik
20
20
  if @user.current_command
21
21
  command = @user.current_command
22
22
  execute(command)
23
- puts "Command #{command} is executed for user #{@user.id}"
23
+ Rubotnik.logger.info "Command #{command} is executed for user #{@user.id}"
24
24
  else
25
25
  bind_commands(&block)
26
26
  end
@@ -54,20 +54,20 @@ module Rubotnik
54
54
 
55
55
  def handle_command(to, reply_with)
56
56
  if reply_with.empty?
57
- puts "Command #{to} is executed for user #{@user.id}"
57
+ Rubotnik.logger.info "Command #{to} is executed for user #{@user.id}"
58
58
  execute(to)
59
59
  @user.reset_command
60
- puts "Command is reset for user #{@user.id}"
60
+ Rubotnik.logger.info "Command is reset for user #{@user.id}"
61
61
  else
62
62
  say(reply_with[:text], quick_replies: reply_with[:quick_replies])
63
63
  @user.assign_command(to)
64
- puts "Command #{to} is set for user #{@user.id}"
64
+ Rubotnik.logger.info "Command #{to} is set for user #{@user.id}"
65
65
  end
66
66
  end
67
67
 
68
68
  def default
69
69
  return if @matched
70
- puts 'None of the commands were recognized' # log
70
+ Rubotnik.logger.info 'None of the commands were recognized'
71
71
  yield
72
72
  @user.reset_command
73
73
  end
@@ -31,7 +31,7 @@ module Rubotnik
31
31
  return unless @postback.payload == regex_string.upcase
32
32
  clear_user_state
33
33
  @matched = true
34
- puts "Matched #{regex_string} to #{to.nil? ? 'block' : to}"
34
+ Rubotnik.logger.info "Matched #{regex_string} to #{to.nil? ? 'block' : to}"
35
35
  if block_given?
36
36
  yield
37
37
  return
@@ -42,13 +42,13 @@ module Rubotnik
42
42
  def handle_command(to, reply_with)
43
43
  if reply_with.empty?
44
44
  execute(to)
45
- puts "Command #{to} is executed for user #{@user.id}"
45
+ Rubotnik.logger.info "Command #{to} is executed for user #{@user.id}"
46
46
  @user.reset_command
47
- puts "Command is reset for user #{@user.id}"
47
+ Rubotnik.logger.info "Command is reset for user #{@user.id}"
48
48
  else
49
49
  say(reply_with[:message], quick_replies: reply_with[:quick_replies])
50
50
  @user.assign_command(to)
51
- puts "Command #{to} is set for user #{@user.id}"
51
+ Rubotnik.logger.info "Command #{to} is set for user #{@user.id}"
52
52
  end
53
53
  end
54
54
 
@@ -17,18 +17,18 @@ class Rubotnik::UserStore
17
17
  @users << user
18
18
  user = @users.last
19
19
  if user
20
- p "user #{user.inspect} added to store"
21
- p "we got #{@users.count} users: #{@users}"
20
+ Rubotnik.logger.info "user #{user.inspect} added to store"
21
+ Rubotnik.logger.info "we got #{@users.count} users: #{@users}"
22
22
  else
23
- p 'user not found in store yet'
23
+ Rubotnik.logger.info 'user not found in store yet'
24
24
  end
25
25
  user
26
26
  end
27
27
 
28
28
  def find(id)
29
29
  user = @users.find { |u| u.id == id }
30
- p "user #{user} found in store" if user
31
- p "we got #{@users.count} users: #{@users}" if user
30
+ Rubotnik.logger.info "user #{user} found in store" if user
31
+ Rubotnik.logger.info "we got #{@users.count} users: #{@users}" if user
32
32
  user
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module Rubotnik
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubotnik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Barnov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-07 00:00:00.000000000 Z
11
+ date: 2018-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facebook-messenger