forked from dbrown/twitter-search
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pulling in Matt Sanford's trends addition
- Loading branch information
Dan Croak
committed
May 15, 2009
1 parent
0a129bd
commit eb2d1b1
Showing
9 changed files
with
141 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.swp | ||
*.swo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module TwitterSearch | ||
class Trend | ||
VARS = [ :query, :name ] | ||
attr_reader *VARS | ||
attr_reader :exclude_hashtags | ||
|
||
def initialize(opts) | ||
@exclude_hashtags = !!opts['exclude_hashtags'] | ||
VARS.each { |each| instance_variable_set "@#{each}", opts[each.to_s] } | ||
end | ||
end | ||
|
||
class Trends | ||
VARS = [:date] | ||
attr_reader *VARS | ||
|
||
include Enumerable | ||
|
||
def initialize(opts) | ||
@trends = opts['trends'].first.collect { |each| Trend.new(each) } | ||
VARS.each { |each| instance_variable_set "@#{each}", opts[each.to_s] } | ||
end | ||
|
||
def each(&block) | ||
@trends.each(&block) | ||
end | ||
|
||
def size | ||
@trends.size | ||
end | ||
|
||
def [](index) | ||
@trends[index] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module TwitterSearch | ||
class Tweet | ||
VARS = [:text, :from_user, :to_user, :to_user_id, :id, :iso_language_code, :from_user_id, :created_at, :profile_image_url, :source ] | ||
attr_reader *VARS | ||
attr_reader :language | ||
|
||
def initialize(opts) | ||
@language = opts['iso_language_code'] | ||
VARS.each { |each| instance_variable_set "@#{each}", opts[each.to_s] } | ||
end | ||
end | ||
|
||
class Tweets | ||
VARS = [:since_id, :max_id, :results_per_page, :page, :query, :next_page] | ||
attr_reader *VARS | ||
|
||
include Enumerable | ||
|
||
def initialize(opts) | ||
@results = opts['results'].collect { |each| Tweet.new(each) } | ||
VARS.each { |each| instance_variable_set "@#{each}", opts[each.to_s] } | ||
end | ||
|
||
def each(&block) | ||
@results.each(&block) | ||
end | ||
|
||
def size | ||
@results.size | ||
end | ||
|
||
def [](index) | ||
@results[index] | ||
end | ||
|
||
def has_next_page? | ||
! @next_page.nil? | ||
end | ||
|
||
def get_next_page | ||
client = Client.new | ||
return client.query( CGI.parse( @next_page[1..-1] ) ) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# coding: utf-8 | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
require 'fake_web' | ||
|
||
FakeWeb.allow_net_connect = false # an insurance policy against hitting http://twitter.com | ||
|
||
class TwitterSearchTrendsTest < Test::Unit::TestCase # :nodoc: | ||
context "@client.trends" do | ||
setup do | ||
@trends = read_yaml :file => 'trends' | ||
end | ||
|
||
should 'find a single trend' do | ||
assert_equal 1, @trends.size | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- !ruby/object:TwitterSearch::Trends | ||
as_of: 1242339160 | ||
trends: | ||
"2009-05-14 22:12:40": | ||
- !ruby/object:TwitterSearch::Trend | ||
name: trend1 | ||
query: trend1 |