twitter_oauth 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/twitter_oauth/search.rb +9 -12
  2. metadata +1 -1
@@ -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
- response = open("http://search.twitter.com/search.json?q=#{URI.escape(q)}&page=#{options[:page]}&rpp=#{options[:per_page]}&since_id=#{options[:since_id]}")
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
- response = open("http://search.twitter.com/trends/current.json")
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
- response = open("http://search.twitter.com/trends/daily.json")
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
- response = open("http://search.twitter.com/trends/weekly.json")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Taylor