topsy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/.yardoc/checksums +2 -0
- data/.yardoc/objects/Topsy.dat +0 -0
- data/.yardoc/objects/Topsy/Client.dat +0 -0
- data/.yardoc/objects/Topsy/Client/author_info_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/author_search_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/handle_response_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/link_post_count_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/link_posts_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/mashup_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/profile_search_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/raise_errors_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/related_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/search_count_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/search_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/stats_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/tags_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/trackbacks_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/trending_i.dat +0 -0
- data/.yardoc/objects/Topsy/Client/url_info_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/all_time_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/last_hour_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/last_month_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/last_week_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/overall_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/this_hour_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/this_month_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/this_week_i.dat +0 -0
- data/.yardoc/objects/Topsy/SearchCounts/today_i.dat +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/LICENSE +20 -0
- data/README.markdown +34 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/changelog.markdown +5 -0
- data/lib/topsy.rb +174 -0
- data/lib/topsy/client.rb +180 -0
- data/lib/topsy/search_counts.rb +46 -0
- data/test/fixtures/authorinfo.json +19 -0
- data/test/fixtures/authorsearch.json +165 -0
- data/test/fixtures/linkpostcount.json +14 -0
- data/test/fixtures/linkposts.json +135 -0
- data/test/fixtures/profilesearch.json +23 -0
- data/test/fixtures/related.json +75 -0
- data/test/fixtures/search.json +126 -0
- data/test/fixtures/searchcount.json +17 -0
- data/test/fixtures/stats.json +16 -0
- data/test/fixtures/tags.json +51 -0
- data/test/fixtures/trackbacks.json +56 -0
- data/test/fixtures/trending.json +53 -0
- data/test/fixtures/urlinfo.json +19 -0
- data/test/helper.rb +45 -0
- data/test/test_topsy.rb +99 -0
- metadata +170 -0
data/.gitignore
ADDED
data/.yardoc/checksums
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/.yardoc/proxy_types
ADDED
Binary file
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Wynn Netherland
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Topsy
|
2
|
+
|
3
|
+
Simple Ruby wrapper for the Topsy.com Otter API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
sudo gem install topsy
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
# Fetch search results for the query "gemcutter"
|
12
|
+
results = Topsy.search("gemcutter")
|
13
|
+
|
14
|
+
# Fetch search counts for the query "gemcutter"
|
15
|
+
counts = Topsy.search_count("gemcutter")
|
16
|
+
counts.this_week
|
17
|
+
=> 19
|
18
|
+
|
19
|
+
Check the [full gem documentation](http://yardoc.org/docs/pengwynn-topsy) and [API docs](http://code.google.com/p/otterapi/wiki/Resources) for more info.
|
20
|
+
|
21
|
+
## Note on Patches/Pull Requests
|
22
|
+
|
23
|
+
* Fork the project.
|
24
|
+
* Make your feature addition or bug fix.
|
25
|
+
* Add tests for it. This is important so I don't break it in a
|
26
|
+
future version unintentionally.
|
27
|
+
* Commit, do not mess with rakefile, version, or history.
|
28
|
+
(if you want to have your own version, that is fine but
|
29
|
+
bump version in a commit by itself I can ignore when I pull)
|
30
|
+
* Send me a pull request. Bonus points for topic branches.
|
31
|
+
|
32
|
+
## Copyright
|
33
|
+
|
34
|
+
Copyright (c) 2010 Wynn Netherland. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "topsy"
|
8
|
+
gem.summary = %Q{Ruby wrapper for the Topsy otterapi}
|
9
|
+
gem.description = %Q{Ruby wrapper for the Topsy otterapi}
|
10
|
+
gem.email = "wynn.netherland@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/pengwynn/topsy"
|
12
|
+
gem.authors = ["Wynn Netherland"]
|
13
|
+
|
14
|
+
gem.add_dependency('hashie', '~> 0.1.3')
|
15
|
+
gem.add_dependency('httparty', '~> 0.4.5')
|
16
|
+
|
17
|
+
gem.add_development_dependency('thoughtbot-shoulda', '>= 2.10.1')
|
18
|
+
gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
|
19
|
+
gem.add_development_dependency('mocha', '0.9.4')
|
20
|
+
gem.add_development_dependency('fakeweb', '>= 1.2.5')
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
end
|
41
|
+
rescue LoadError
|
42
|
+
task :rcov do
|
43
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
task :test => :check_dependencies
|
48
|
+
|
49
|
+
task :default => :test
|
50
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/changelog.markdown
ADDED
data/lib/topsy.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'hashie', '~> 0.1.3'
|
4
|
+
require 'hashie'
|
5
|
+
|
6
|
+
gem 'httparty', '~> 0.4.5'
|
7
|
+
require 'httparty'
|
8
|
+
|
9
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
10
|
+
|
11
|
+
Hash.send :include, Hashie::HashExtensions
|
12
|
+
|
13
|
+
|
14
|
+
module Topsy
|
15
|
+
class TopsyError < StandardError
|
16
|
+
attr_reader :data
|
17
|
+
|
18
|
+
def initialize(data)
|
19
|
+
@data = data
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class RateLimitExceeded < StandardError; end
|
25
|
+
class Unauthorized < StandardError; end
|
26
|
+
class General < TopsyError; end
|
27
|
+
|
28
|
+
class Unavailable < StandardError; end
|
29
|
+
class InformTopsy < StandardError; end
|
30
|
+
class NotFound < StandardError; end
|
31
|
+
|
32
|
+
# 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
|
33
|
+
#
|
34
|
+
# @param [String] url URL string for the author.
|
35
|
+
# @return [Hashie::Mash]
|
36
|
+
def self.author_info(url)
|
37
|
+
Topsy::Client.new.author_info(url)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Returns list of authors that talk about the query. The list is sorted by frequency of posts and the influence of authors.
|
42
|
+
#
|
43
|
+
# @param [String] q the search query string
|
44
|
+
# @param [Hash] options method options
|
45
|
+
# @option options [String] :window Time window for results. (default: 'a') Options: auto - automatically pick the most recent and relevant window. h last hour, d last day, w last week, m last month, a all time
|
46
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
47
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
48
|
+
# @return [Hashie::Mash]
|
49
|
+
def self.author_search(q, options={})
|
50
|
+
Topsy::Client.new.author_search(q, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns list of URLs posted by an author
|
54
|
+
#
|
55
|
+
# @param [String] url URL string for the author.
|
56
|
+
# @param [Hash] options method options
|
57
|
+
# @option options [String] :contains Query string to filter results
|
58
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
59
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
60
|
+
# @return [Hashie::Mash]
|
61
|
+
def self.link_posts(url, options={})
|
62
|
+
Topsy::Client.new.link_posts(url, options={})
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns count of links posted by an author. This is the efficient, count-only version of /linkposts
|
66
|
+
#
|
67
|
+
# @param [String] url URL string for the author.
|
68
|
+
# @param [Hash] options method options
|
69
|
+
# @option options [String] :contains Query string to filter results
|
70
|
+
# @return [Hashie::Mash]
|
71
|
+
def self.link_post_count(url, options={})
|
72
|
+
Topsy::Client.new.link_post_count(url, options={})
|
73
|
+
end
|
74
|
+
|
75
|
+
# 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.
|
76
|
+
#
|
77
|
+
# @param [String] q the search query string
|
78
|
+
# @param [Hash] options method options
|
79
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
80
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
81
|
+
# @return [Hashie::Mash]
|
82
|
+
def self.profile_search(q, options={})
|
83
|
+
Topsy::Client.new.profile_search(q, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns list of URLs related to a given URL
|
87
|
+
#
|
88
|
+
# @param [String] url URL string for the author.
|
89
|
+
# @param [Hash] options method options
|
90
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
91
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
92
|
+
# @return [Hashie::Mash]
|
93
|
+
def self.related(url, options={})
|
94
|
+
Topsy::Client.new.related(url, options)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns list of results for a query.
|
98
|
+
#
|
99
|
+
# @param [String] q the search query string
|
100
|
+
# @param [Hash] options method options
|
101
|
+
# @option options [String] :window Time window for results. (default: 'a') Options: auto - automatically pick the most recent and relevant window. h last hour, d last day, w last week, m last month, a all time
|
102
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
103
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
104
|
+
# @return [Hashie::Mash]
|
105
|
+
def self.search(q, options={})
|
106
|
+
Topsy::Client.new.search(q, options)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Returns count of results for a search query.
|
110
|
+
#
|
111
|
+
# @param [String] q the search query string
|
112
|
+
# @return [Topsy::SearchCounts]
|
113
|
+
def self.search_count(q)
|
114
|
+
Topsy::Client.new.search_count(q)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Returns counts of tweets for a URL
|
118
|
+
#
|
119
|
+
# @param [String] url the url to look up
|
120
|
+
# @param [Hash] options method options
|
121
|
+
# @option options [String] :contains Query string to filter results
|
122
|
+
# @return [Hashie::Mash]
|
123
|
+
def self.stats(url, options={})
|
124
|
+
Topsy::Client.new.stats(url, options)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns list of tags for a URL.
|
128
|
+
#
|
129
|
+
# @param [String] url the search query string
|
130
|
+
# @param [Hash] options method options
|
131
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
132
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
133
|
+
# @return [Hashie::Mash]
|
134
|
+
def self.tags(url, options={})
|
135
|
+
Topsy::Client.new.tags(url, options)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Returns list of tweets (trackbacks) that mention the query URL, most recent first.
|
139
|
+
#
|
140
|
+
# @param [String] url URL string for the author.
|
141
|
+
# @param [Hash] options method options
|
142
|
+
# @option options [String] :contains Query string to filter results
|
143
|
+
# @option options [Boolean] :infonly filters trackbacks to influential only (default 0)
|
144
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
145
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
146
|
+
# @return [Hashie::Mash]
|
147
|
+
def self.trackbacks(url, options={})
|
148
|
+
Topsy::Client.new.trackbacks(url, options)
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
# Returns list of trending terms
|
153
|
+
#
|
154
|
+
# @param [Hash] options method options
|
155
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
156
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
157
|
+
# @return [Hashie::Mash]
|
158
|
+
def self.trending(options={})
|
159
|
+
Topsy::Client.new.trending(options)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns info about a URL
|
163
|
+
#
|
164
|
+
# @param [String] url the url to look up
|
165
|
+
# @return [Hashie::Mash]
|
166
|
+
def self.url_info(url)
|
167
|
+
Topsy::Client.new.url_info(url)
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
require File.join(directory, 'topsy', 'search_counts')
|
174
|
+
require File.join(directory, 'topsy', 'client')
|
data/lib/topsy/client.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
module Topsy
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
format :json
|
5
|
+
base_uri "http://otter.topsy.com"
|
6
|
+
|
7
|
+
# 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
|
8
|
+
#
|
9
|
+
# @param [String] url URL string for the author.
|
10
|
+
# @return [Hashie::Mash]
|
11
|
+
def author_info(url)
|
12
|
+
handle_response(self.class.get("/authorinfo.json", :query => {:url => url}))
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns list of authors that talk about the query. The list is sorted by frequency of posts and the influence of authors.
|
16
|
+
#
|
17
|
+
# @param [String] q the search query string
|
18
|
+
# @param [Hash] options method options
|
19
|
+
# @option options [String] :window Time window for results. (default: 'a') Options: auto - automatically pick the most recent and relevant window. h last hour, d last day, w last week, m last month, a all time
|
20
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
21
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
22
|
+
# @return [Hashie::Mash]
|
23
|
+
def author_search(q, options={})
|
24
|
+
handle_response(self.class.get("/authorsearch.json", :query => {:q => q}.merge(options)))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns list of URLs posted by an author
|
28
|
+
#
|
29
|
+
# @param [String] url URL string for the author.
|
30
|
+
# @param [Hash] options method options
|
31
|
+
# @option options [String] :contains Query string to filter results
|
32
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
33
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
34
|
+
# @return [Hashie::Mash]
|
35
|
+
def link_posts(url, options={})
|
36
|
+
query = {:url => url}
|
37
|
+
query.merge!(options)
|
38
|
+
handle_response(self.class.get("/linkposts.json", :query => query))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns count of links posted by an author. This is the efficient, count-only version of /linkposts
|
42
|
+
#
|
43
|
+
# @param [String] url URL string for the author.
|
44
|
+
# @param [Hash] options method options
|
45
|
+
# @option options [String] :contains Query string to filter results
|
46
|
+
# @return [Hashie::Mash]
|
47
|
+
def link_post_count(url, options={})
|
48
|
+
handle_response(self.class.get("/linkpostcount.json", :query => {:url => url}.merge(options)))
|
49
|
+
end
|
50
|
+
|
51
|
+
# 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.
|
52
|
+
#
|
53
|
+
# @param [String] q the search query string
|
54
|
+
# @param [Hash] options method options
|
55
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
56
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
57
|
+
# @return [Hashie::Mash]
|
58
|
+
def profile_search(q, options={})
|
59
|
+
handle_response(self.class.get("/profilesearch.json", :query => {:q => q}.merge(options)))
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns list of URLs related to a given URL
|
63
|
+
#
|
64
|
+
# @param [String] url URL string for the author.
|
65
|
+
# @param [Hash] options method options
|
66
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
67
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
68
|
+
# @return [Hashie::Mash]
|
69
|
+
def related(url, options={})
|
70
|
+
handle_response(self.class.get("/related.json", :query => {:url => url}.merge(options)))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns list of results for a query.
|
74
|
+
#
|
75
|
+
# @param [String] q the search query string
|
76
|
+
# @param [Hash] options method options
|
77
|
+
# @option options [String] :window Time window for results. (default: 'a') Options: auto - automatically pick the most recent and relevant window. h last hour, d last day, w last week, m last month, a all time
|
78
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
79
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
80
|
+
# @return [Hashie::Mash]
|
81
|
+
def search(q, options={})
|
82
|
+
handle_response(self.class.get("/search.json", :query => {:q => q}.merge(options)))
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns count of results for a search query.
|
86
|
+
#
|
87
|
+
# @param [String] q the search query string
|
88
|
+
# @return [Topsy::SearchCounts]
|
89
|
+
def search_count(q)
|
90
|
+
counts = handle_response(self.class.get("/searchcount.json", :query => {:q => q}))
|
91
|
+
Topsy::SearchCounts.new(counts)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns counts of tweets for a URL
|
95
|
+
#
|
96
|
+
# @param [String] url the url to look up
|
97
|
+
# @param [Hash] options method options
|
98
|
+
# @option options [String] :contains Query string to filter results
|
99
|
+
# @return [Hashie::Mash]
|
100
|
+
def stats(url, options={})
|
101
|
+
query = {:url => url}
|
102
|
+
query.merge!(options)
|
103
|
+
handle_response(self.class.get("/stats.json", :query => query))
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns list of tags for a URL.
|
107
|
+
#
|
108
|
+
# @param [String] url the search query string
|
109
|
+
# @param [Hash] options method options
|
110
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
111
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
112
|
+
# @return [Hashie::Mash]
|
113
|
+
def tags(url, options={})
|
114
|
+
handle_response(self.class.get("/tags.json", :query => {:url => url}.merge(options)))
|
115
|
+
end
|
116
|
+
|
117
|
+
# Returns list of tweets (trackbacks) that mention the query URL, most recent first.
|
118
|
+
#
|
119
|
+
# @param [String] url URL string for the author.
|
120
|
+
# @param [Hash] options method options
|
121
|
+
# @option options [String] :contains Query string to filter results
|
122
|
+
# @option options [Boolean] :infonly filters trackbacks to influential only (default 0)
|
123
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
124
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
125
|
+
# @return [Hashie::Mash]
|
126
|
+
def trackbacks(url, options={})
|
127
|
+
results = handle_response(self.class.get("/trackbacks.json", :query => {:url => url}.merge(options)))
|
128
|
+
results.list.each do |trackback|
|
129
|
+
trackback.date = Time.at(trackback.date)
|
130
|
+
end
|
131
|
+
results
|
132
|
+
end
|
133
|
+
|
134
|
+
# Returns list of trending terms
|
135
|
+
#
|
136
|
+
# @param [Hash] options method options
|
137
|
+
# @option options [Integer] :page page number of the result set. (default: 1, max: 10)
|
138
|
+
# @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
|
139
|
+
# @return [Hashie::Mash]
|
140
|
+
def trending(options={})
|
141
|
+
handle_response(self.class.get("/trending.json", :query => options))
|
142
|
+
end
|
143
|
+
|
144
|
+
# Returns info about a URL
|
145
|
+
#
|
146
|
+
# @param [String] url the url to look up
|
147
|
+
# @return [Hashie::Mash]
|
148
|
+
def url_info(url)
|
149
|
+
handle_response(self.class.get("/urlinfo.json", :query => {:url => url}))
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
def handle_response(response)
|
155
|
+
raise_errors(response)
|
156
|
+
mashup(response)
|
157
|
+
end
|
158
|
+
|
159
|
+
def raise_errors(response)
|
160
|
+
code = response.code.to_i
|
161
|
+
case code
|
162
|
+
when 400
|
163
|
+
raise Topsy::General.new("Parameter check failed. This error indicates that a required parameter is missing or a parameter has a value that is out of bounds.")
|
164
|
+
when 403
|
165
|
+
raise Topsy::Unauthorized.new
|
166
|
+
when 404
|
167
|
+
raise Topsy::NotFound.new
|
168
|
+
when 500
|
169
|
+
raise Topsy::InformTopsy.new
|
170
|
+
when 503
|
171
|
+
raise Topsy::Unavailable.new
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def mashup(response)
|
176
|
+
Hashie::Mash.new(response).response
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
end
|