jnunemaker-twitter 0.6.11 → 0.6.12

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/History CHANGED
@@ -1,3 +1,8 @@
1
+ 0.6.12 - June 26, 2009
2
+ * 2 minor additions
3
+ * fixed fakeweb test issue (obie fernandez)
4
+ * added user agent option to searches
5
+
1
6
  0.6.11 - May 18, 2009
2
7
  * 1 minor addition
3
8
  * Added the ability to sign in with twitter instead of authorizing
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 6
4
- :patch: 11
4
+ :patch: 12
@@ -5,11 +5,16 @@ module Twitter
5
5
 
6
6
  attr_reader :result, :query
7
7
 
8
- def initialize(q=nil)
8
+ def initialize(q=nil, options={})
9
+ @options = options
9
10
  clear
10
11
  containing(q) if q && q.strip != ''
11
12
  end
12
13
 
14
+ def user_agent
15
+ @options[:user_agent] || 'Ruby Twitter Gem'
16
+ end
17
+
13
18
  def from(user)
14
19
  @query[:q] << "from:#{user}"
15
20
  self
@@ -92,7 +97,7 @@ module Twitter
92
97
  if @fetch.nil? || force
93
98
  query = @query.dup
94
99
  query[:q] = query[:q].join(' ')
95
- response = self.class.get('http://search.twitter.com/search.json', :query => query, :format => :json)
100
+ response = self.class.get('http://search.twitter.com/search.json', :query => query, :format => :json, :headers => {'User-Agent' => user_agent})
96
101
  @fetch = Mash.new(response)
97
102
  end
98
103
 
@@ -41,7 +41,7 @@ class HTTPAuthTest < Test::Unit::TestCase
41
41
  end
42
42
 
43
43
  should "be able to get" do
44
- stub_get('http://twitter.com:80/statuses/user_timeline.json', 'user_timeline.json')
44
+ stub_get('http://username:password@twitter.com:80/statuses/user_timeline.json', 'user_timeline.json')
45
45
  response = @twitter.get('/statuses/user_timeline.json')
46
46
  response.should == fixture_file('user_timeline.json')
47
47
  end
@@ -57,7 +57,7 @@ class HTTPAuthTest < Test::Unit::TestCase
57
57
  end
58
58
 
59
59
  should "be able to post" do
60
- stub_post('http://twitter.com:80/statuses/update.json', 'status.json')
60
+ stub_post('http://username:password@twitter.com:80/statuses/update.json', 'status.json')
61
61
  response = @twitter.post('/statuses/update.json', :text => 'My update.')
62
62
  response.should == fixture_file('status.json')
63
63
  end
@@ -9,6 +9,21 @@ class SearchTest < Test::Unit::TestCase
9
9
  should "should be able to initialize with a search term" do
10
10
  Twitter::Search.new('httparty').query[:q].should include('httparty')
11
11
  end
12
+
13
+ should "default user agent to Ruby Twitter Gem" do
14
+ search = Twitter::Search.new('foo')
15
+ search.user_agent.should == 'Ruby Twitter Gem'
16
+ end
17
+
18
+ should "allow overriding default user agent" do
19
+ search = Twitter::Search.new('foo', :user_agent => 'Foobar')
20
+ search.user_agent.should == 'Foobar'
21
+ end
22
+
23
+ should "pass user agent along with headers when making request" do
24
+ Twitter::Search.expects(:get).with('http://search.twitter.com/search.json', {:format => :json, :query => {:q => 'foo'}, :headers => {'User-Agent' => 'Foobar'}})
25
+ Twitter::Search.new('foo', :user_agent => 'Foobar').fetch()
26
+ end
12
27
 
13
28
  should "should be able to specify from" do
14
29
  @search.from('jnunemaker').query[:q].should include('from:jnunemaker')
@@ -44,37 +59,37 @@ class SearchTest < Test::Unit::TestCase
44
59
 
45
60
  should "should be able to specify the language" do
46
61
  @search.lang('en')
47
- @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:lang => 'en', :q => ''}, :format => :json).returns({'foo' => 'bar'})
62
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:lang => 'en', :q => ''}, :format => :json, :headers => {'User-Agent' => 'Ruby Twitter Gem'}).returns({'foo' => 'bar'})
48
63
  @search.fetch()
49
64
  end
50
65
 
51
66
  should "should be able to specify the number of results per page" do
52
67
  @search.per_page(25)
53
- @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:rpp => 25, :q => ''}, :format => :json).returns({'foo' => 'bar'})
68
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:rpp => 25, :q => ''}, :format => :json, :headers => {'User-Agent' => 'Ruby Twitter Gem'}).returns({'foo' => 'bar'})
54
69
  @search.fetch()
55
70
  end
56
71
 
57
72
  should "should be able to specify the page number" do
58
73
  @search.page(20)
59
- @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:page => 20, :q => ''}, :format => :json).returns({'foo' => 'bar'})
74
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:page => 20, :q => ''}, :format => :json, :headers => {'User-Agent' => 'Ruby Twitter Gem'}).returns({'foo' => 'bar'})
60
75
  @search.fetch()
61
76
  end
62
77
 
63
78
  should "should be able to specify only returning results greater than an id" do
64
79
  @search.since(1234)
65
- @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:since_id => 1234, :q => ''}, :format => :json).returns({'foo' => 'bar'})
80
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:since_id => 1234, :q => ''}, :format => :json, :headers => {'User-Agent' => 'Ruby Twitter Gem'}).returns({'foo' => 'bar'})
66
81
  @search.fetch()
67
82
  end
68
83
 
69
84
  should "should be able to specify geo coordinates" do
70
85
  @search.geocode('40.757929', '-73.985506', '25mi')
71
- @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:geocode => '40.757929,-73.985506,25mi', :q => ''}, :format => :json).returns({'foo' => 'bar'})
86
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:geocode => '40.757929,-73.985506,25mi', :q => ''}, :format => :json, :headers => {'User-Agent' => 'Ruby Twitter Gem'}).returns({'foo' => 'bar'})
72
87
  @search.fetch()
73
88
  end
74
89
 
75
90
  should "should be able to specify max id" do
76
91
  @search.max(1234)
77
- @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:max_id => 1234, :q => ''}, :format => :json).returns({'foo' => 'bar'})
92
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:max_id => 1234, :q => ''}, :format => :json, :headers => {'User-Agent' => 'Ruby Twitter Gem'}).returns({'foo' => 'bar'})
78
93
  @search.fetch()
79
94
  end
80
95
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.11
4
+ version: 0.6.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-18 00:00:00 -07:00
12
+ date: 2009-06-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency