chatterbot 2.0.2 → 2.0.3

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: dd3b277547610b8d5e0ec0993a5952d015cab80b
4
- data.tar.gz: 114e6d11f506a6bbb331081b66395613346e3a12
3
+ metadata.gz: 3d88eeab29e199d49fb99f081f90d483263c57d9
4
+ data.tar.gz: 92dbfd810dc21b7c638bc6ff22903194881734e3
5
5
  SHA512:
6
- metadata.gz: 92c72bf9e9ab384e2a5a00756d78af0128998efd1dd7d1eba9ac069b8fe427042e5ea73aeed03e2ae9dd30a140833382f9e239090b6c835794fe9207073e6d98
7
- data.tar.gz: 3d6c202746806977bd602b9ad2f196cec49ef4dd091582ce38711906b1e7ddb9fd93be34b517b6aadeb7492e024e07784c12c4002d74e0220247bd623616fea6
6
+ metadata.gz: f33ae22b7f5ebf4d3e774aa95a9761cb4ec8c8970e670ca89181fdf64507814d034fecd206fc52aa0469f3d6c4c854a69395be31a0de4fcde04bfc4f05f181c4
7
+ data.tar.gz: 5ab5abed1989ef5963b7d2b7b422b433cb7581aa7cd24ccbaee63fc07b9153aaaf9f3cf9c406ef46568844d4140c048402a0bc4e59dc82ebf0607e09e275b69d
@@ -79,8 +79,9 @@ Or you can write a bot using more traditional ruby classes, extend it if needed,
79
79
  ```
80
80
  class MyBot < Chatterbot::Bot
81
81
  def do_stuff
82
- search("'surely you must be joking'") do |tweet|
83
- reply "@#{tweet_user(tweet)} I am serious, and don't call me Shirley!", tweet
82
+ home_timeline do |tweet|
83
+ puts "I like to favorite things"
84
+ favorite tweet
84
85
  end
85
86
  end
86
87
  end
@@ -85,7 +85,6 @@ module Chatterbot
85
85
  }
86
86
  end
87
87
 
88
-
89
88
  streaming_client.send(method, args) do |object|
90
89
  handle_streaming_object(object)
91
90
  end
@@ -113,8 +113,13 @@ module Chatterbot
113
113
  # send a tweet
114
114
  #
115
115
  # @param [String] txt the text you want to tweet
116
- # @param [Hash] params opts for the tweet
117
- # @see http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
116
+ # @param [Hash] params options for the tweet. You can get an idea
117
+ # of possible values you can send here from the underlying Twitter
118
+ # gem docs: http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
119
+ # @option params [String,File] :media Optional file object to send
120
+ # with the tweet. Must be an image or video that will be accepted by
121
+ # Twitter. You can pass a File object, or the path to a file
122
+ # @see http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
118
123
  # @param [Tweet] original if this is a reply, the original tweet. this will
119
124
  # be used for variable substitution, and for logging
120
125
  def tweet(txt, params = {}, original = nil)
@@ -141,8 +146,15 @@ module Chatterbot
141
146
  #
142
147
  # @param [String] txt the text you want to tweet
143
148
  # @param [Tweet] source the original tweet you are replying to
144
- def reply(txt, source)
145
- bot.reply(txt, source)
149
+ # @param [Hash] params options for the tweet. You can get an idea
150
+ # of possible values you can send here from the underlying Twitter
151
+ # gem docs: http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
152
+ # @option params [String,File] :media Optional file object to send with the
153
+ # tweet. Must be an image or video that will be accepted by
154
+ # Twitter. You can pass a File object, or the path to a file
155
+ # @see http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
156
+ def reply(txt, source, params={})
157
+ bot.reply(txt, source, params)
146
158
  end
147
159
 
148
160
  #
@@ -13,7 +13,16 @@ module Chatterbot
13
13
  debug "I'm in debug mode, otherwise I would tweet: #{txt}"
14
14
  else
15
15
  debug txt
16
- client.update txt, params
16
+ if params.has_key?(:media)
17
+ file = params.delete(:media)
18
+ if ! file.is_a?(File)
19
+ file = File.new(file)
20
+ end
21
+
22
+ client.update_with_media txt, file, params
23
+ else
24
+ client.update txt, params
25
+ end
17
26
  end
18
27
  rescue Twitter::Error::Forbidden => e
19
28
  #:nocov:
@@ -24,9 +33,10 @@ module Chatterbot
24
33
 
25
34
 
26
35
  # reply to a tweet
27
- def reply(txt, source)
36
+ def reply(txt, source, params = {})
28
37
  debug txt
29
- tweet txt, {:in_reply_to_status_id => source.id}, source
38
+ params = {:in_reply_to_status_id => source.id}.merge(params)
39
+ tweet txt, params, source
30
40
  end
31
41
  end
32
42
  end
@@ -13,7 +13,6 @@ module Chatterbot
13
13
  puts str.colorize(:red)
14
14
  end
15
15
 
16
- #:nocov:
17
16
  def green(str)
18
17
  puts str.colorize(:green)
19
18
  end
@@ -1,3 +1,3 @@
1
1
  module Chatterbot
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
@@ -187,10 +187,17 @@ describe "Chatterbot::DSL" do
187
187
  end
188
188
 
189
189
  it "#reply passes along to bot object" do
190
- expect(@bot).to receive(:reply).with("hello sailor!", { :source => "source "})
191
- reply "hello sailor!", { :source => "source "}
190
+ source = double(Twitter::Tweet)
191
+ expect(@bot).to receive(:reply).with("hello sailor!", source, {})
192
+ reply "hello sailor!", source
192
193
  end
193
194
 
195
+ it "#reply passes along to bot object with media" do
196
+ source = double(Twitter::Tweet)
197
+ expect(@bot).to receive(:reply).with("hello sailor!", source, {media:"/tmp/foo.jpg"})
198
+ reply "hello sailor!", source, media:"/tmp/foo.jpg"
199
+ end
200
+
194
201
  describe "#direct_message" do
195
202
  it "passes along to bot object" do
196
203
  expect(@bot).to receive(:direct_message).with("hello sailor!", nil)
@@ -11,29 +11,48 @@ describe "Chatterbot::Tweet" do
11
11
  @bot.tweet "tweet test!"
12
12
  end
13
13
 
14
- it "calls client.update with the right values" do
15
- bot = test_bot
14
+ context "when authenticated" do
15
+ let(:bot) { test_bot }
16
+ before(:each) do
17
+ expect(bot).to receive(:require_login).and_return(true)
18
+ allow(bot).to receive(:client).and_return(double(Twitter::Client))
19
+ end
20
+
21
+ it "calls client.update with the right values" do
22
+ allow(bot).to receive(:debug_mode?).and_return(false)
16
23
 
17
- expect(bot).to receive(:require_login).and_return(true)
18
- allow(bot).to receive(:client).and_return(double(Twitter::Client))
24
+ test_str = "test!"
25
+ expect(bot.client).to receive(:update).with(test_str, {})
26
+ bot.tweet test_str
27
+ end
19
28
 
20
- allow(bot).to receive(:debug_mode?).and_return(false)
29
+ it "calls client.update_with_media if media file is specified" do
30
+ allow(bot).to receive(:debug_mode?).and_return(false)
21
31
 
22
- test_str = "test!"
23
- expect(bot.client).to receive(:update).with(test_str, {})
24
- bot.tweet test_str
25
- end
32
+ test_str = "test!"
33
+ path = File.join(File.dirname(__FILE__), "fixtures", "update_with_media.png")
34
+ media = File.new(path)
35
+ expect(bot.client).to receive(:update_with_media).with(test_str, media, {})
36
+ bot.tweet test_str, media:media
37
+ end
26
38
 
27
- it "doesn't tweet when debug_mode? is set" do
28
- bot = test_bot
29
-
30
- expect(bot).to receive(:require_login).and_return(true)
31
- allow(bot).to receive(:client).and_return(double(Twitter::Client))
39
+ it "calls client.update_with_media if media file path is specified" do
40
+ allow(bot).to receive(:debug_mode?).and_return(false)
32
41
 
33
- allow(bot).to receive(:debug_mode?).and_return(true)
42
+ test_str = "test!"
43
+ path = File.join(File.dirname(__FILE__), "fixtures", "update_with_media.png")
34
44
 
35
- expect(bot.client).not_to receive(:update)
36
- bot.tweet "no tweet!"
45
+ expect(bot.client).to receive(:update_with_media).with(test_str, an_instance_of(File), {})
46
+ bot.tweet test_str, media:path
47
+ end
48
+
49
+
50
+ it "doesn't tweet when debug_mode? is set" do
51
+ allow(bot).to receive(:debug_mode?).and_return(true)
52
+
53
+ expect(bot.client).not_to receive(:update)
54
+ bot.tweet "no tweet!"
55
+ end
37
56
  end
38
57
  end
39
58
 
@@ -44,30 +63,51 @@ describe "Chatterbot::Tweet" do
44
63
  bot.reply "reply test!", fake_tweet(100)
45
64
  end
46
65
 
47
- it "calls client.update with the right values" do
48
- bot = test_bot
49
- expect(bot).to receive(:require_login).and_return(true)
50
- allow(bot).to receive(:client).and_return(double(Twitter::Client))
66
+ context "when authenticated" do
67
+ let(:bot) { test_bot }
68
+ before(:each) do
69
+ expect(bot).to receive(:require_login).and_return(true)
70
+ allow(bot).to receive(:client).and_return(double(Twitter::Client))
71
+ end
51
72
 
52
- allow(bot).to receive(:debug_mode?).and_return(false)
73
+
74
+ it "calls client.update with the right values" do
75
+ allow(bot).to receive(:debug_mode?).and_return(false)
53
76
 
54
- test_str = "test!"
77
+ test_str = "test!"
55
78
 
56
- expect(bot.client).to receive(:update).with(test_str, {:in_reply_to_status_id => 100})
57
- bot.reply test_str, fake_tweet(100, 100)
58
- end
79
+ expect(bot.client).to receive(:update).with(test_str, {:in_reply_to_status_id => 100})
80
+ bot.reply test_str, fake_tweet(100, 100)
81
+ end
59
82
 
83
+ it "calls client.update_with_media if media file is specified" do
84
+ allow(bot).to receive(:debug_mode?).and_return(false)
60
85
 
61
- it "doesn't reply when debug_mode? is set" do
62
- bot = test_bot
63
- expect(bot).to receive(:require_login).and_return(true)
64
- allow(bot).to receive(:client).and_return(double(Twitter::Client))
86
+ test_str = "test!"
87
+ path = File.join(File.dirname(__FILE__), "fixtures", "update_with_media.png")
88
+ media = File.new(path)
89
+
90
+ expect(bot.client).to receive(:update_with_media).with(test_str, media, {:in_reply_to_status_id => 100})
91
+ bot.reply test_str, fake_tweet(100, 100), media:media
92
+ end
65
93
 
66
- allow(bot).to receive(:debug_mode?).and_return(true)
94
+ it "calls client.update_with_media if media file path is specified" do
95
+ allow(bot).to receive(:debug_mode?).and_return(false)
67
96
 
68
- expect(bot.client).not_to receive(:update)
69
- bot.reply "no reply test!", fake_tweet(100)
97
+ test_str = "test!"
98
+ path = File.join(File.dirname(__FILE__), "fixtures", "update_with_media.png")
99
+
100
+ expect(bot.client).to receive(:update_with_media).with(test_str, an_instance_of(File), {:in_reply_to_status_id => 100})
101
+ bot.reply test_str, fake_tweet(100, 100), media:path
102
+ end
103
+
104
+ it "doesn't reply when debug_mode? is set" do
105
+ allow(bot).to receive(:debug_mode?).and_return(true)
106
+
107
+ expect(bot.client).not_to receive(:update_with_media)
108
+ bot.reply "no reply test!", fake_tweet(100)
109
+ end
70
110
  end
71
111
  end
72
-
112
+
73
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatterbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Mitchell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-10 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -249,6 +249,7 @@ files:
249
249
  - spec/direct_messages_spec.rb
250
250
  - spec/dsl_spec.rb
251
251
  - spec/favorite_spec.rb
252
+ - spec/fixtures/update_with_media.png
252
253
  - spec/followers_spec.rb
253
254
  - spec/handler_spec.rb
254
255
  - spec/helpers_spec.rb
@@ -299,6 +300,7 @@ test_files:
299
300
  - spec/direct_messages_spec.rb
300
301
  - spec/dsl_spec.rb
301
302
  - spec/favorite_spec.rb
303
+ - spec/fixtures/update_with_media.png
302
304
  - spec/followers_spec.rb
303
305
  - spec/handler_spec.rb
304
306
  - spec/helpers_spec.rb