Class: Topsy::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/topsy/client.rb

Constant Summary collapse

@@windows =
{:all => 'a', :auto => 'auto', :week => 'w', :day => 'd', :month => 'm', :hour => 'h', :realtime => 'realtime'}

Instance Method Summary collapse

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

Parameters:

  • url (String)

    URL string for the author.

Returns:



19
20
21
22
# File 'lib/topsy/client.rb', line 19

def author_info(url)
  authorinfo = handle_response(self.class.get("/authorinfo.json", :query => {:url => url}))
  Topsy::Author.new(authorinfo)
end

#author_search(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.

Parameters:

  • q (String)

    the search query string

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :window (Symbol)

    Time window for results. (default: :auto) Options: :auto - automatically pick the most recent and relevant window. :hour last hour, :day last day, :week last week, :month last month, :all all time

  • :page (Integer)

    page number of the result set. (default: 1, max: 10)

  • :perpage (Integer)

    limit number of results per page. (default: 10, max: 50)

Returns:

  • (Hashie::Mash)


32
33
34
35
# File 'lib/topsy/client.rb', line 32

def author_search(q, options={})
  options[:window] = @@windows[options[:window]] if options[:window]
  handle_response(self.class.get("/authorsearch.json", :query => {:q => q}.merge(options)))
end

#creditTopsy::RateLimitInfo

Returns info about API rate limiting



11
12
13
# File 'lib/topsy/client.rb', line 11

def credit
  handle_response(self.class.get("/credit.json"))
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

Parameters:

  • url (String)

    URL string for the author.

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :contains (String)

    Query string to filter results

Returns:



56
57
58
59
# File 'lib/topsy/client.rb', line 56

def link_post_count(url, options={})
  count = handle_response(self.class.get("/linkpostcount.json", :query => {:url => url}.merge(options)))
  Topsy::LinkpostCount.new(count)
end

Returns list of URLs posted by an author

Parameters:

  • url (String)

    URL string for the author.

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :contains (String)

    Query string to filter results

  • :page (Integer)

    page number of the result set. (default: 1, max: 10)

  • :perpage (Integer)

    limit number of results per page. (default: 10, max: 50)

Returns:



45
46
47
48
# File 'lib/topsy/client.rb', line 45

def link_posts(url, options={})
  linkposts = handle_response(self.class.get("/linkposts.json", :query => {:url => url}.merge(options)))
  Topsy::Page.new(linkposts,Topsy::Linkpost)
end

#profile_search(q, options = {}) ⇒ Topsy::Page

Returns list list of author profiles that match the query.

The query is matched against the nick, name and biography 
information and the results are sorted by closeness of match and the influence of authors.

Parameters:

  • q (String)

    the search query string

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :page (Integer)

    page number of the result set. (default: 1, max: 10)

  • :perpage (Integer)

    limit number of results per page. (default: 10, max: 50)

Returns:



70
71
72
73
# File 'lib/topsy/client.rb', line 70

def profile_search(q, options={})
  results = handle_response(self.class.get("/profilesearch.json", :query => {:q => q}.merge(options)))
  Topsy::Page.new(results,Topsy::Author)
end

Returns list of URLs related to a given URL

Parameters:

  • url (String)

    URL string for the author.

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :page (Integer)

    page number of the result set. (default: 1, max: 10)

  • :perpage (Integer)

    limit number of results per page. (default: 10, max: 50)

Returns:



82
83
84
85
# File 'lib/topsy/client.rb', line 82

def related(url, options={})
  response = handle_response(self.class.get("/related.json", :query => {:url => url}.merge(options)))
  Topsy::Page.new(response,Topsy::LinkSearchResult)
end

#search(q, options = {}) ⇒ Topsy::Page

Returns list of results for a query.

Parameters:

  • q (String)

    the search query string

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :window (Symbol)

    Time window for results. (default: :auto) Options: :auto - automatically pick the most recent and relevant window. :hour last hour, :day last day, :week last week, :month last month, :all all time

  • :page (Integer)

    page number of the result set. (default: 1, max: 10)

  • :perpage (Integer)

    limit number of results per page. (default: 10, max: 50)

  • :site (String)

    narrow results to a domain

Returns:



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/topsy/client.rb', line 96

def search(q, options={})
  if q.is_a?(Hash)
    options = q
    q = "site:#{options.delete(:site)}" if options[:site]
  else
    q += " site:#{options.delete(:site)}" if options[:site]
  end
  options[:window] = @@windows[options[:window]] if options[:window]
  results = handle_response(self.class.get("/search.json", :query => {:q => q}.merge(options)))
  Topsy::Page.new(results,Topsy::LinkSearchResult)
end

#search_count(q) ⇒ Topsy::SearchCounts

Returns count of results for a search query.

Parameters:

  • q (String)

    the search query string

Returns:



112
113
114
115
# File 'lib/topsy/client.rb', line 112

def search_count(q)
  counts = handle_response(self.class.get("/searchcount.json", :query => {:q => q}))
  Topsy::SearchCounts.new(counts)
end

#stats(url, options = {}) ⇒ Topsy::Stats

Returns counts of tweets for a URL

Parameters:

  • url (String)

    the url to look up

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :contains (String)

    Query string to filter results

Returns:



123
124
125
126
127
128
# File 'lib/topsy/client.rb', line 123

def stats(url, options={})
  query = {:url => url}
  query.merge!(options)
  response = handle_response(self.class.get("/stats.json", :query => query))
  Topsy::Stats.new(response)
end

#tags(url, options = {}) ⇒ Topsy::Page

Returns list of tags for a URL.

Parameters:

  • url (String)

    the search query string

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :page (Integer)

    page number of the result set. (default: 1, max: 10)

  • :perpage (Integer)

    limit number of results per page. (default: 10, max: 50)

Returns:



137
138
139
140
# File 'lib/topsy/client.rb', line 137

def tags(url, options={})
  response = handle_response(self.class.get("/tags.json", :query => {:url => url}.merge(options)))
  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.

Parameters:

  • url (String)

    URL string for the author.

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :contains (String)

    Query string to filter results

  • :infonly (Boolean)

    filters trackbacks to influential only (default 0)

  • :page (Integer)

    page number of the result set. (default: 1, max: 10)

  • :perpage (Integer)

    limit number of results per page. (default: 10, max: 50)

Returns:



151
152
153
154
155
156
157
# File 'lib/topsy/client.rb', line 151

def trackbacks(url, options={})
  results = handle_response(self.class.get("/trackbacks.json", :query => {:url => url}.merge(options)))
  results.list.each do |trackback|
    trackback.date = Time.at(trackback.date)
  end
  Topsy::Page.new(results,Topsy::Tweet)
end

Returns list of trending terms

Parameters:

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :page (Integer)

    page number of the result set. (default: 1, max: 10)

  • :perpage (Integer)

    limit number of results per page. (default: 10, max: 50)

Returns:



165
166
167
168
# File 'lib/topsy/client.rb', line 165

def trending(options={})
  response = handle_response(self.class.get("/trending.json", :query => options))
  Topsy::Page.new(response,Topsy::Trend)
end

#url_info(url) ⇒ Topsy::UrlInfo

Returns info about a URL

Parameters:

  • url (String)

    the url to look up

Returns:



174
175
176
177
# File 'lib/topsy/client.rb', line 174

def url_info(url)
  response = handle_response(self.class.get("/urlinfo.json", :query => {:url => url}))
  Topsy::UrlInfo.new(response)
end