deadprogrammer-twitter 0.6.11 → 0.6.12

Sign up to get free protection for your applications and to get access to all the features.
data/examples/search.rb CHANGED
@@ -12,4 +12,5 @@ search.each { |result| pp result }
12
12
  puts '*'*50, 'Parameter Check', '*'*50
13
13
  pp Twitter::Search.new('#austineats').fetch().results.first
14
14
  pp Twitter::Search.new('#austineats').page(2).fetch().results.first
15
- pp Twitter::Search.new('#austineats').since(1412737343).fetch().results.first
15
+ pp Twitter::Search.new('#austineats').since(1412737343).fetch().results.first
16
+ pp Twitter::Search.new('#austineats').user_agent("Testing Twitter App").fetch().results.first
@@ -3,11 +3,13 @@ module Twitter
3
3
  include HTTParty
4
4
  include Enumerable
5
5
 
6
- attr_reader :result, :query, :user_agent
6
+ headers 'Accept' => 'text/json'
7
7
 
8
- def initialize(q=nil, agent="Twitter Ruby Gem")
8
+ attr_reader :result, :query
9
+
10
+ def initialize(q=nil, o={})
9
11
  clear
10
- @user_agent = agent
12
+ @user_agent = o[:user_agent] ? o[:user_agent] : "Twitter Ruby Gem"
11
13
  containing(q) if q && q.strip != ''
12
14
  end
13
15
 
@@ -86,7 +88,6 @@ module Twitter
86
88
  @fetch = nil
87
89
  @query = {}
88
90
  @query[:q] = []
89
- @user_agent = "Twitter Ruby Gem"
90
91
  self
91
92
  end
92
93
 
@@ -94,7 +95,7 @@ module Twitter
94
95
  if @fetch.nil? || force
95
96
  query = @query.dup
96
97
  query[:q] = query[:q].join(' ')
97
- response = self.class.get('http://search.twitter.com/search.json', :query => query, :format => :json, :headers => {'user-agent' => @user_agent})
98
+ response = self.class.get('http://search.twitter.com/search.json', {:query => query, :format => :json, :headers => {'user-agent' => @user_agent}})
98
99
  @fetch = Mash.new(response)
99
100
  end
100
101
 
@@ -104,5 +105,14 @@ module Twitter
104
105
  def each
105
106
  fetch()['results'].each { |r| yield r }
106
107
  end
108
+
109
+ def user_agent(agent=nil)
110
+ if agent.nil?
111
+ @user_agent
112
+ else
113
+ @user_agent = agent
114
+ self
115
+ end
116
+ end
107
117
  end
108
118
  end
@@ -92,6 +92,18 @@ class SearchTest < Test::Unit::TestCase
92
92
  @search.query[:geocode].should == '40.757929,-73.985506,25mi'
93
93
  end
94
94
 
95
+ should "should be able to use with default user-agent" do
96
+ Twitter::Search.new('httparty').user_agent.should == "Twitter Ruby Gem"
97
+ end
98
+
99
+ should "should be able to have custom user-agent" do
100
+ Twitter::Search.new('httparty').user_agent('My Twitter App').user_agent.should == "My Twitter App"
101
+ end
102
+
103
+ should "should be able to to initialize custom user-agent with options hash in constructor" do
104
+ Twitter::Search.new('httparty', :user_agent => 'My Twitter App').user_agent.should == "My Twitter App"
105
+ end
106
+
95
107
  context "fetching" do
96
108
  setup do
97
109
  stub_get('http://search.twitter.com:80/search.json?q=%40jnunemaker', 'search.json')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deadprogrammer-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