chatterbot 0.2.1 → 0.2.2

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.
data/examples/dsl_test.rb CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  require 'chatterbot/dsl'
4
4
 
5
- exclude ["foo", "bar"]
6
- search("foo") do |tweet|
7
- # # reply "@#{tweet['from_user']} I am serious, and don't call me Shirley!", tweet
5
+ exclude ["bar"]
6
+ search("foo", :lang => "en") do |tweet|
8
7
  puts tweet.inspect
9
8
  end
@@ -4,6 +4,7 @@
4
4
  #
5
5
  # require the dsl lib to include all the methods you see below.
6
6
  #
7
+ require 'rubygems'
7
8
  require 'chatterbot/dsl'
8
9
 
9
10
  puts "Loading echoes_bot.rb"
@@ -11,6 +11,7 @@ module Chatterbot
11
11
  # default options when querying twitter -- this could be extended
12
12
  # with a language, etc.
13
13
  def default_opts
14
+ return {} if since_id <= 0
14
15
  {
15
16
  :since_id => since_id
16
17
  }
@@ -44,7 +44,7 @@ module Chatterbot
44
44
  #
45
45
  # Should we run any config updates?
46
46
  def update_config?
47
- config[:dry_run] || true
47
+ config.has_key?(:dry_run) ? ! config[:dry_run] : true
48
48
  end
49
49
 
50
50
  #
@@ -69,7 +69,7 @@ module Chatterbot
69
69
  #
70
70
  # return the ID of the most recent tweet pulled up in searches
71
71
  def since_id
72
- config[:since_id] || 1
72
+ config[:since_id] || 0
73
73
  end
74
74
 
75
75
  #
@@ -72,8 +72,8 @@ module Chatterbot
72
72
 
73
73
  #
74
74
  # search twitter for the specified terms
75
- def search(query, &block)
76
- @bot.search(query, &block)
75
+ def search(query, opts = {}, &block)
76
+ @bot.search(query, opts, &block)
77
77
  end
78
78
 
79
79
  #
@@ -5,7 +5,7 @@ module Chatterbot
5
5
  module Search
6
6
 
7
7
  # internal search code
8
- def search(queries, &block)
8
+ def search(queries, opts = {}, &block)
9
9
  return unless init_client
10
10
 
11
11
  debug "check for tweets since #{since_id}"
@@ -18,7 +18,7 @@ module Chatterbot
18
18
  # search twitter
19
19
  #
20
20
  queries.each { |query|
21
- search = client.search(query, default_opts)
21
+ search = client.search(query, opts.merge(default_opts))
22
22
  update_since_id(search)
23
23
 
24
24
  if search != nil
@@ -1,3 +1,3 @@
1
1
  module Chatterbot
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -26,6 +26,16 @@ describe "Chatterbot::Config" do
26
26
  @bot.config[:custom].should == :value
27
27
  end
28
28
 
29
+ it "update_config? is true by default" do
30
+ @bot.update_config?.should == true
31
+ end
32
+
33
+ it "update_config? is false if this is a dry run" do
34
+ @bot.config[:dry_run] = true
35
+ @bot.update_config?.should == false
36
+ end
37
+
38
+
29
39
  it "returns a log dest" do
30
40
  @bot.should_receive(:load_config).and_return({:log_dest => :bar})
31
41
  @bot.config = nil
data/spec/dsl_spec.rb CHANGED
@@ -45,12 +45,12 @@ describe "Chatterbot::DSL" do
45
45
 
46
46
 
47
47
  it "#search passes along to bot object" do
48
- @bot.should_receive(:search).with("foo")
48
+ @bot.should_receive(:search).with("foo", { })
49
49
  search("foo")
50
50
  end
51
51
 
52
52
  it "#search passes along to bot object" do
53
- @bot.should_receive(:search).with(["foo","bar"])
53
+ @bot.should_receive(:search).with(["foo","bar"], { })
54
54
  search(["foo","bar"])
55
55
  end
56
56
 
data/spec/search_spec.rb CHANGED
@@ -27,17 +27,36 @@ describe "Chatterbot::Search" do
27
27
  #bot = Chatterbot::Bot.new
28
28
 
29
29
  bot.stub!(:client).and_return(fake_search(100))
30
- bot.client.should_receive(:search).with("foo", {:since_id => 1})
31
- bot.client.should_receive(:search).with("bar", {:since_id => 1})
30
+ bot.client.should_receive(:search).with("foo", {})
31
+ bot.client.should_receive(:search).with("bar", {})
32
32
 
33
33
  bot.search(["foo", "bar"])
34
34
  end
35
35
 
36
+ it "accepts extra params" do
37
+ bot = test_bot
38
+
39
+ bot.stub!(:client).and_return(fake_search(100))
40
+ bot.client.should_receive(:search).with("foo", {:lang => "en"})
41
+
42
+ bot.search("foo", :lang => "en")
43
+ end
44
+
36
45
  it "accepts a single search query" do
37
46
  bot = test_bot
38
47
 
39
48
  bot.stub!(:client).and_return(fake_search(100))
40
- bot.client.should_receive(:search).with("foo", {:since_id => 1})
49
+ bot.client.should_receive(:search).with("foo", {})
50
+
51
+ bot.search("foo")
52
+ end
53
+
54
+ it "passes along since_id" do
55
+ bot = test_bot
56
+ bot.stub!(:since_id).and_return(123)
57
+
58
+ bot.stub!(:client).and_return(fake_search(100))
59
+ bot.client.should_receive(:search).with("foo", {:since_id => 123})
41
60
 
42
61
  bot.search("foo")
43
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatterbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-25 00:00:00.000000000Z
12
+ date: 2011-05-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: twitter_oauth
16
- requirement: &16420860 !ruby/object:Gem::Requirement
16
+ requirement: &21124680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16420860
24
+ version_requirements: *21124680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &16420360 !ruby/object:Gem::Requirement
27
+ requirement: &21124180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *16420360
35
+ version_requirements: *21124180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &16419880 !ruby/object:Gem::Requirement
38
+ requirement: &21123700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16419880
46
+ version_requirements: *21123700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &16419400 !ruby/object:Gem::Requirement
49
+ requirement: &21123220 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *16419400
57
+ version_requirements: *21123220
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &16418920 !ruby/object:Gem::Requirement
60
+ requirement: &21122740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *16418920
68
+ version_requirements: *21122740
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rcov
71
- requirement: &16418440 !ruby/object:Gem::Requirement
71
+ requirement: &21122260 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *16418440
79
+ version_requirements: *21122260
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: watchr
82
- requirement: &16417960 !ruby/object:Gem::Requirement
82
+ requirement: &21121780 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *16417960
90
+ version_requirements: *21121780
91
91
  description: A framework for writing bots that run on Twitter. Comes with a simple
92
92
  DSL for easy coding.
93
93
  email: colin@muffinlabs.com