-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Twitter API versioning support for trends methods
- Loading branch information
Showing
2 changed files
with
18 additions
and
18 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 |
---|---|---|
@@ -1,37 +1,37 @@ | ||
module Twitter | ||
class Trends | ||
include HTTParty | ||
base_uri 'search.twitter.com/trends' | ||
base_uri "api.twitter.com/1/trends" | ||
format :json | ||
|
||
# :exclude => 'hashtags' to exclude hashtags | ||
def self.current(options={}) | ||
mashup(get('/current.json', :query => options)) | ||
mashup(get("/current.json", :query => options)) | ||
end | ||
|
||
# :exclude => 'hashtags' to exclude hashtags | ||
# :date => yyyy-mm-dd for specific date | ||
def self.daily(options={}) | ||
mashup(get('/daily.json', :query => options)) | ||
mashup(get("/daily.json", :query => options)) | ||
end | ||
|
||
# :exclude => 'hashtags' to exclude hashtags | ||
# :date => yyyy-mm-dd for specific date | ||
def self.weekly(options={}) | ||
mashup(get('/weekly.json', :query => options)) | ||
mashup(get("/weekly.json", :query => options)) | ||
end | ||
|
||
def self.available(query={}) | ||
locations = get('http://api.twitter.com/1/trends/available.json', :query => query).map{|location| Hashie::Mash.new(location)} | ||
locations = get("http://api.twitter.com/#{API_VERSION}/trends/available.json", :query => query).map{|location| Hashie::Mash.new(location)} | ||
end | ||
|
||
def self.for_location(woeid) | ||
get("http://api.twitter.com/1/trends/#{woeid}.json").map{|location| Hashie::Mash.new(location)} | ||
get("http://api.twitter.com/#{API_VERSION}/trends/#{woeid}.json").map{|location| Hashie::Mash.new(location)} | ||
end | ||
|
||
private | ||
def self.mashup(response) | ||
response['trends'].values.flatten.map { |t| Hashie::Mash.new(t) } | ||
response["trends"].values.flatten.map { |t| Hashie::Mash.new(t) } | ||
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