Class: Topsy::API
Overview
provides all methods to the Topsy API
Class Method Summary collapse
-
.authorinfo(twitter_nick) ⇒ Object
returns the author info object according to the twitter url author_handle: eg.
-
.authorsearch(query = '', window = 'a', page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Author instances that talk about the query parameter who talk most about the query parameter (see: code.google.com/p/otterapi/wiki/QuerySyntax).
-
.get_response(api_request) ⇒ Object
performs a HTTParty get returns the response hash.
-
.linkpostcount(twitter_nick = '') ⇒ Object
returns a LinkpostCount for a nick twitter_nick: eg.
-
.linkposts(twitter_nick = '', page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Linkpost instances twitter_nick: eg.
-
.normalize_url(url) ⇒ Object
adds a trailing ‘/’ to the string if necessary.
-
.profilesearch(query = '', page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Author instances that match the nick, name and biography info parameter query eg.
-
.related(url = '', page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of LinkSearchResult if url is nil or empty, returns nil if url doesn’t end with ‘/’ (eg. www.google.com) it adds it to the end to normalize the url.
-
.search(query = '', window = :auto, page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of LinkSearchResult returns nil if the window parameter is not correct.
-
.searchcount(query = '') ⇒ Object
returns a SearchCount instance initialized with the response.
-
.stats(url) ⇒ Object
returns a Stats instance for a certain url url: eg.
-
.tags(url, page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Tag.
-
.trackbacks(url = '', tracktype = 'tweet', contains = '', infonly = 0, page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Tweet.
-
.trending(page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Trend.
-
.urlinfo(url) ⇒ Object
returns a UrlInfo instance for a certain url url: eg.
Class Method Details
.authorinfo(twitter_nick) ⇒ Object
returns the author info object according to the twitter url author_handle: eg. barackobama
26 27 28 29 |
# File 'lib/rtopsy/api.rb', line 26 def self.(twitter_nick) resp = get_response("/authorinfo.json?url=http://twitter.com/#{twitter_nick}") Author.new(resp) end |
.authorsearch(query = '', window = 'a', page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Author instances that talk about the query parameter who talk most about the query parameter (see: code.google.com/p/otterapi/wiki/QuerySyntax)
40 41 42 43 |
# File 'lib/rtopsy/api.rb', line 40 def self.(query = '', window = 'a', page = 1, perpage = 10) resp = get_response("/authorsearch.json?q=#{query}&window=#{window}&page=#{page}&perpage=#{perpage}") Page.new(resp, :author) end |
.get_response(api_request) ⇒ Object
performs a HTTParty get returns the response hash
19 20 21 22 |
# File 'lib/rtopsy/api.rb', line 19 def self.get_response(api_request) hash = get(api_request) return hash["response"] end |
.linkpostcount(twitter_nick = '') ⇒ Object
returns a LinkpostCount for a nick twitter_nick: eg. barackobama
56 57 58 59 |
# File 'lib/rtopsy/api.rb', line 56 def self.linkpostcount(twitter_nick = '') resp = get_response("/linkpostcount.json?url=http://twitter.com/#{twitter_nick}") LinkpostCount.new(resp) end |
.linkposts(twitter_nick = '', page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Linkpost instances twitter_nick: eg. barackobama page: eg. 1 perpage: eg. 12
49 50 51 52 |
# File 'lib/rtopsy/api.rb', line 49 def self.linkposts(twitter_nick = '', page = 1, perpage = 10) resp = get_response("/linkposts.json?url=http://twitter.com/#{twitter_nick}&page=#{page}&perpage=#{perpage}") Page.new(resp, :link_post) end |
.normalize_url(url) ⇒ Object
adds a trailing ‘/’ to the string if necessary
83 84 85 86 87 88 |
# File 'lib/rtopsy/api.rb', line 83 def self.normalize_url(url) if url[url.length-1, url.length] != '/' url = url + "/" end return url end |
.profilesearch(query = '', page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Author instances that match the nick, name and biography info parameter query eg. Barack+Obama (see: code.google.com/p/otterapi/wiki/QuerySyntax)
33 34 35 36 |
# File 'lib/rtopsy/api.rb', line 33 def self.profilesearch(query = '', page = 1, perpage = 10) resp = get_response("/profilesearch.json?q=#{query}&page=#{page}&perpage=#{perpage}") Page.new(resp, :author) end |
.related(url = '', page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of LinkSearchResult if url is nil or empty, returns nil if url doesn’t end with ‘/’ (eg. www.google.com) it adds it to the end to normalize the url
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rtopsy/api.rb', line 71 def self.(url = '', page = 1, perpage = 10) if !url return nil end url = normalize_url(url) resp = get_response("/related.json?url=#{url}&page=#{page}&perpage=#{perpage}") Page.new(resp, :link_search_result) end |
.search(query = '', window = :auto, page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of LinkSearchResult returns nil if the window parameter is not correct
98 99 100 101 102 103 104 105 |
# File 'lib/rtopsy/api.rb', line 98 def self.search(query = '', window = :auto, page = 1, perpage = 10) if [:auto, :h, :d, :w, :m, :a].include? window resp = get_response("/search.json?q=#{query}&window=#{window}&page=#{page}&perpage=#{perpage}") Page.new(resp, :link_search_result) else nil end end |
.searchcount(query = '') ⇒ Object
returns a SearchCount instance initialized with the response
91 92 93 94 |
# File 'lib/rtopsy/api.rb', line 91 def self.searchcount(query = '') resp = get_response("/searchcount.json?q=#{query}") SearchCount.new(resp) end |
.stats(url) ⇒ Object
returns a Stats instance for a certain url url: eg. aycron.com
109 110 111 112 |
# File 'lib/rtopsy/api.rb', line 109 def self.stats(url) resp = get_response("/stats.json?url=#{url}") Stats.new(resp) end |
.tags(url, page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Tag
115 116 117 118 119 |
# File 'lib/rtopsy/api.rb', line 115 def self.(url, page = 1, perpage = 10) url = normalize_url(url) resp = get_response("/tags.json?url=#{url}&page=#{page}&perpage=#{perpage}") Page.new(resp, :tag) end |
.trackbacks(url = '', tracktype = 'tweet', contains = '', infonly = 0, page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Tweet
122 123 124 125 126 |
# File 'lib/rtopsy/api.rb', line 122 def self.trackbacks(url = '', tracktype = 'tweet', contains = '', infonly = 0, page = 1, perpage = 10) url = normalize_url(url) resp = get_response("/trackbacks.json?url=#{url}&tracktype=#{tracktype}&infonly=#{infonly}&contains=#{contains}&page=#{page}&perpage=#{perpage}") Page.new(resp, :tweet) end |
.trending(page = 1, perpage = 10) ⇒ Object
returns a Page of results with a list of Trend
129 130 131 132 |
# File 'lib/rtopsy/api.rb', line 129 def self.trending(page = 1, perpage = 10) resp = get_response("/trending.json?page=#{page}&perpage=#{perpage}") Page.new(resp, :trend) end |
.urlinfo(url) ⇒ Object
returns a UrlInfo instance for a certain url url: eg. aycron.com
63 64 65 66 |
# File 'lib/rtopsy/api.rb', line 63 def self.urlinfo(url) resp = get_response("/urlinfo.json?url=#{url}") UrlInfo.new(resp) end |