twitter_oauth 0.3.0 → 0.3.1
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/lib/twitter_oauth/search.rb +9 -12
- metadata +1 -1
data/lib/twitter_oauth/search.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'open-uri'
|
2
|
-
require 'ostruct'
|
3
2
|
|
4
3
|
module TwitterOAuth
|
5
4
|
class Client
|
@@ -7,30 +6,28 @@ module TwitterOAuth
|
|
7
6
|
def search(q, options={})
|
8
7
|
options[:page] ||= 1
|
9
8
|
options[:per_page] ||= 20
|
10
|
-
|
11
|
-
search_result = JSON.parse(response.read)
|
12
|
-
search_result = OpenStruct.new(search_result)
|
13
|
-
search_result.results = search_result.results.collect{|x| OpenStruct.new(x)}
|
14
|
-
search_result
|
9
|
+
search_get("http://search.twitter.com/search.json?q=#{URI.escape(q)}&page=#{options[:page]}&rpp=#{options[:per_page]}&since_id=#{options[:since_id]}")
|
15
10
|
end
|
16
11
|
|
17
12
|
# Returns the current top 10 trending topics on Twitter.
|
18
13
|
def current_trends
|
19
|
-
|
20
|
-
JSON.parse(response.read)
|
14
|
+
search_get("http://search.twitter.com/trends/current.json")
|
21
15
|
end
|
22
16
|
|
23
17
|
# Returns the top 20 trending topics for each hour in a given day.
|
24
18
|
def daily_trends
|
25
|
-
|
26
|
-
JSON.parse(response.read)
|
19
|
+
search_get("http://search.twitter.com/trends/daily.json")
|
27
20
|
end
|
28
21
|
|
29
22
|
# Returns the top 30 trending topics for each day in a given week.
|
30
23
|
def weekly_trends
|
31
|
-
|
32
|
-
JSON.parse(response.read)
|
24
|
+
search_get("http://search.twitter.com/trends/weekly.json")
|
33
25
|
end
|
34
26
|
|
27
|
+
private
|
28
|
+
def search_get(url)
|
29
|
+
response = open(url, 'User-Agent' => 'github.com/moomerman/twitter_outh')
|
30
|
+
JSON.parse(response.read)
|
31
|
+
end
|
35
32
|
end
|
36
33
|
end
|