Class: Topsy::Client
- Inherits:
-
Object
- Object
- Topsy::Client
- Includes:
- HTTParty, Configurable
- Defined in:
- lib/topsy/client.rb
Constant Summary collapse
- @@windows =
{:all => 'a', :week => 'w', :day => 'd', :month => 'm', :hour => 'h', :realtime => 'realtime'}
Instance Attribute Summary
Attributes included from Configurable
Instance Method Summary collapse
-
#author_info(url) ⇒ Topsy::Author
Returns Profile information for an author (a twitter profile indexed by Topsy).
-
#credit ⇒ Topsy::RateLimitInfo
Returns info about API rate limiting.
-
#experts(q, options = {}) ⇒ Hashie::Mash
Returns list of authors that talk about the query.
- #get(path, opts = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#link_post_count(url, options = {}) ⇒ Topsy::LinkpostCount
Returns count of links posted by an author.
-
#link_posts(url, options = {}) ⇒ Topsy::Page
Returns list of URLs posted by an author.
-
#related(url, options = {}) ⇒ Topsy::Page
Returns list of URLs related to a given URL.
-
#search(q, options = {}) ⇒ Topsy::Page
Returns list of results for a query.
-
#search_count(q) ⇒ Topsy::SearchCounts
Returns count of results for a search query.
-
#search_histogram(q, count_method = 'target', slice = 86400, period = 30) ⇒ Object
Returns mention count data for the given query.
-
#stats(url, options = {}) ⇒ Topsy::Stats
Returns counts of tweets for a URL.
-
#tags(url, options = {}) ⇒ Topsy::Page
Returns list of tags for a URL.
-
#trackbacks(url, options = {}) ⇒ Topsy::Page
Returns list of tweets (trackbacks) that mention the query URL, most recent first.
-
#trending(options = {}) ⇒ Topsy::Page
Returns list of trending terms.
-
#url_info(url) ⇒ Topsy::UrlInfo
Returns info about a URL.
Methods included from Configurable
#cache_key, #configure, keys, #reset!
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 26 |
# File 'lib/topsy/client.rb', line 21 def initialize( = {} ) setup Topsy::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", [key] || instance_variable_get(:"@#{key}")) end end |
Instance Method Details
#author_info(url) ⇒ Topsy::Author
Returns Profile information for an author (a twitter profile indexed by Topsy). The response contains the name, description (biography) and the influence level of the author
39 40 41 42 |
# File 'lib/topsy/client.rb', line 39 def (url) = handle_response(get("/authorinfo.json", :query => {:url => url})) Topsy::Author.new() end |
#credit ⇒ Topsy::RateLimitInfo
Returns info about API rate limiting
31 32 33 |
# File 'lib/topsy/client.rb', line 31 def credit handle_response(get("/credit.json")) end |
#experts(q, options = {}) ⇒ Hashie::Mash
Returns list of authors that talk about the query. The list is sorted by frequency of posts and the influence of authors.
52 53 54 55 56 |
# File 'lib/topsy/client.rb', line 52 def experts(q, ={}) = set_window_or_default() result = handle_response(get("/experts.json", :query => {:q => q}.merge())) Topsy::Page.new(result, Topsy::Author) end |
#get(path, opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/topsy/client.rb', line 12 def get( path , opts = {} ) if @api_key.length > 0 # Handle appending the api key opts[:query] = {} unless opts.has_key?(:query) opts[:query].merge!( { :apikey => [:api_key] } ) end self.class.get( path , opts ) end |
#link_post_count(url, options = {}) ⇒ Topsy::LinkpostCount
Returns count of links posted by an author. This is the efficient, count-only version of /linkposts
77 78 79 80 |
# File 'lib/topsy/client.rb', line 77 def link_post_count(url, ={}) count = handle_response(get("/linkpostcount.json", :query => {:url => url}.merge())) Topsy::LinkpostCount.new(count) end |
#link_posts(url, options = {}) ⇒ Topsy::Page
Returns list of URLs posted by an author
66 67 68 69 |
# File 'lib/topsy/client.rb', line 66 def link_posts(url, ={}) linkposts = handle_response(get("/linkposts.json", :query => {:url => url}.merge())) Topsy::Page.new(linkposts,Topsy::Linkpost) end |
#related(url, options = {}) ⇒ Topsy::Page
Returns list of URLs related to a given URL
89 90 91 92 |
# File 'lib/topsy/client.rb', line 89 def (url, ={}) response = handle_response(get("/related.json", :query => {:url => url}.merge())) Topsy::Page.new(response,Topsy::LinkSearchResult) end |
#search(q, options = {}) ⇒ Topsy::Page
Returns list of results for a query.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/topsy/client.rb', line 103 def search(q, ={}) if q.is_a?(Hash) = q q = "site:#{.delete(:site)}" if [:site] else q += " site:#{.delete(:site)}" if [:site] end = set_window_or_default() results = handle_response(get("/search.json", :query => {:q => q}.merge())) Topsy::Page.new(results,Topsy::LinkSearchResult) end |
#search_count(q) ⇒ Topsy::SearchCounts
Returns count of results for a search query.
119 120 121 122 |
# File 'lib/topsy/client.rb', line 119 def search_count(q) counts = handle_response(get("/searchcount.json", :query => {:q => q})) Topsy::SearchCounts.new(counts) end |
#search_histogram(q, count_method = 'target', slice = 86400, period = 30) ⇒ Object
Returns mention count data for the given query
131 132 133 134 |
# File 'lib/topsy/client.rb', line 131 def search_histogram( q , count_method = 'target' , slice = 86400 , period = 30 ) response = handle_response(get("/searchhistogram.json" , :query => { :q => q , :slice => slice , :period => period , :count_method => count_method } )) Topsy::SearchHistogram.new(response) end |
#stats(url, options = {}) ⇒ Topsy::Stats
Returns counts of tweets for a URL
142 143 144 145 146 147 |
# File 'lib/topsy/client.rb', line 142 def stats(url, ={}) query = {:url => url} query.merge!() response = handle_response(get("/stats.json", :query => query)) Topsy::Stats.new(response) end |
#tags(url, options = {}) ⇒ Topsy::Page
Returns list of tags for a URL.
156 157 158 159 |
# File 'lib/topsy/client.rb', line 156 def (url, ={}) response = handle_response(get("/tags.json", :query => {:url => url}.merge())) Topsy::Page.new(response,Topsy::Tag) end |
#trackbacks(url, options = {}) ⇒ Topsy::Page
Returns list of tweets (trackbacks) that mention the query URL, most recent first.
170 171 172 173 174 175 176 |
# File 'lib/topsy/client.rb', line 170 def trackbacks(url, ={}) results = handle_response(get("/trackbacks.json", :query => {:url => url}.merge())) results.list.each do |trackback| trackback.date = Time.at(trackback.date) end Topsy::Page.new(results,Topsy::Tweet) end |
#trending(options = {}) ⇒ Topsy::Page
Returns list of trending terms
184 185 186 187 |
# File 'lib/topsy/client.rb', line 184 def trending(={}) response = handle_response(get("/trending.json", :query => )) Topsy::Page.new(response,Topsy::Trend) end |
#url_info(url) ⇒ Topsy::UrlInfo
Returns info about a URL
193 194 195 196 |
# File 'lib/topsy/client.rb', line 193 def url_info(url) response = handle_response(get("/urlinfo.json", :query => {:url => url})) Topsy::UrlInfo.new(response) end |