chatterbot 2.0.4 → 2.0.5

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: 291622b1f2a0cbb3b3c7eefd3b3cdee644cec193
4
- data.tar.gz: db6c7840161544af76021b4e6f86f347c1f74919
3
+ metadata.gz: fd1f15ba5a3ff9b93011fd3da19223859262e10e
4
+ data.tar.gz: a535d7da9c4107fb810d8e838e99f2d3feb5eeca
5
5
  SHA512:
6
- metadata.gz: d2c631c18d4c99ed808ad43668a9a2f00915404185e275f62a830cd3d685113f8b0289622b2832c03acc3d9ddf489488b5798bff10793a424d38a847ca0af5b5
7
- data.tar.gz: 249cd8b6ad2be5921b60b32c5d39ac2bd54f19aace9c0c6db9332dbe696b8cf6145796e318bab047c5345e0f9818c3783f67788dd320172ca3a2d5903bf9fe77
6
+ metadata.gz: 6f18198504ee50b9ba3015d7f45ea46061c14a55e4d02be568ef738d4e13567e9d7118473ff0c942a49a8fc0789cdda46f2d84acf69f35828f55da8283443774
7
+ data.tar.gz: c57548daa22ef87724d6f101f2c3fee9922c7b7e953a62e395eb4b207ad3d86cf25602484dbf850a55de0b26a91c9e128dc2d3e797e390130b65c84a53d92297
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.extensions << 'ext/mkrf_conf.rb'
28
28
 
29
29
  s.add_runtime_dependency(%q<oauth>, ["~> 0.4.7"])
30
- s.add_runtime_dependency(%q<twitter>, ["~> 6.1.0"])
30
+ s.add_runtime_dependency(%q<twitter>, ["~> 6.2.0"])
31
31
  s.add_runtime_dependency(%q<launchy>, [">= 2.4.2"])
32
32
  s.add_runtime_dependency(%q<colorize>, [">= 0.7.3"])
33
33
 
@@ -14,6 +14,10 @@ module Chatterbot
14
14
  #
15
15
  # search twitter for the specified terms, then pass any matches to
16
16
  # the block.
17
+ # NOTE: by default, search terms are wrapped in quotes so the
18
+ # Twitter API will return tweets that include your exact query.
19
+ # You can disable this by passing exact:false as an option
20
+ #
17
21
  # @param args [Hash] options. these will be passed directly to
18
22
  # Twitter via the twitter gem. You can see the possible arguments
19
23
  # at http://www.rubydoc.info/gems/twitter/Twitter/REST/Search#search-instance_method
@@ -24,25 +24,47 @@ module Chatterbot
24
24
  @skip_retweets = false
25
25
  end
26
26
 
27
-
27
+
28
28
  #
29
29
  # check if this is a retweet that we want to skip
30
30
  #
31
31
  def skippable_retweet?(t)
32
32
  @skip_retweets && t.retweeted_status?
33
33
  end
34
+
35
+ def wrap_search_query(q)
36
+ if q =~ / /
37
+ ['"', q.gsub(/^"/, '').gsub(/"$/, ''), '"'].join("")
38
+ else
39
+ q
40
+ end
41
+ end
34
42
 
35
43
  # internal search code
36
44
  def search(queries, opts = {}, &block)
37
45
  debug "check for tweets since #{since_id}"
38
46
 
39
47
  max_tweets = opts.delete(:limit) || MAX_SEARCH_TWEETS
48
+ exact_match = if opts.key?(:exact)
49
+ opts.delete(:exact)
50
+ else
51
+ true
52
+ end
53
+
40
54
 
41
55
  if queries.is_a?(String)
42
- queries = [queries]
56
+ queries = [
57
+ queries
58
+ ]
43
59
  end
44
60
 
45
- query = queries.join(" OR ")
61
+ query = queries.map { |q|
62
+ if exact_match == true
63
+ q = wrap_search_query(q)
64
+ end
65
+
66
+ q
67
+ }.join(" OR ")
46
68
 
47
69
  #
48
70
  # search twitter
@@ -50,6 +72,7 @@ module Chatterbot
50
72
 
51
73
  debug "search: #{query} #{default_opts.merge(opts)}"
52
74
  @current_tweet = nil
75
+
53
76
  client.search( query, default_opts.merge(opts) ).take(max_tweets).each { |s|
54
77
  update_since_id(s)
55
78
  debug s.text
@@ -1,3 +1,3 @@
1
1
  module Chatterbot
2
- VERSION = "2.0.4"
2
+ VERSION = "2.0.5"
3
3
  end
@@ -7,7 +7,6 @@ describe "Chatterbot::Search" do
7
7
  bot.search("foo")
8
8
  end
9
9
 
10
-
11
10
  it "calls update_since_id" do
12
11
  bot = test_bot
13
12
 
@@ -32,6 +31,46 @@ describe "Chatterbot::Search" do
32
31
  bot.search(["foo", "bar"])
33
32
  end
34
33
 
34
+ it "encloses search queries in quotes" do
35
+ bot = test_bot
36
+
37
+ allow(bot).to receive(:client).and_return(fake_search(100, 1))
38
+ expect(bot.client).to receive(:search).
39
+ with("\"foo bar baz\"", {
40
+ :result_type=>"recent",
41
+ :since_id => 1,
42
+ :since_id_reply => 1
43
+ })
44
+
45
+ bot.search("foo bar baz")
46
+ end
47
+
48
+ it "doesn't enclose search queries in quotes if not exact" do
49
+ bot = test_bot
50
+
51
+ allow(bot).to receive(:client).and_return(fake_search(100, 1))
52
+ expect(bot.client).to receive(:search).
53
+ with("foo bar baz", {
54
+ :result_type=>"recent",
55
+ :since_id => 1,
56
+ :since_id_reply => 1
57
+ })
58
+
59
+ bot.search("foo bar baz", exact:false)
60
+ end
61
+
62
+ it "passes along since_id" do
63
+ bot = test_bot
64
+ allow(bot).to receive(:since_id).and_return(123)
65
+ allow(bot).to receive(:since_id_reply).and_return(456)
66
+
67
+ allow(bot).to receive(:client).and_return(fake_search(100, 1))
68
+ expect(bot.client).to receive(:search).with("foo", {:since_id => 123, :result_type => "recent", :since_id_reply => 456})
69
+
70
+ bot.search("foo")
71
+ end
72
+
73
+
35
74
  it "accepts extra params" do
36
75
  bot = test_bot
37
76
 
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.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Mitchell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-16 00:00:00.000000000 Z
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 6.1.0
33
+ version: 6.2.0
34
34
  type: :runtime
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: 6.1.0
40
+ version: 6.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: launchy
43
43
  requirement: !ruby/object:Gem::Requirement