topsy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/.gitignore +4 -0
  2. data/.yardoc/checksums +14 -2
  3. data/.yardoc/objects/Topsy/Author/to_s_i.dat +0 -0
  4. data/.yardoc/objects/Topsy/Author/type_i.dat +0 -0
  5. data/.yardoc/objects/Topsy/Author.dat +0 -0
  6. data/.yardoc/objects/Topsy/Client/author_info_i.dat +0 -0
  7. data/.yardoc/objects/Topsy/Client/author_search_i.dat +0 -0
  8. data/.yardoc/objects/Topsy/Client/credit_i.dat +0 -0
  9. data/.yardoc/objects/Topsy/Client/get_rate_limit_status_i.dat +0 -0
  10. data/.yardoc/objects/Topsy/Client/handle_response_i.dat +0 -0
  11. data/.yardoc/objects/Topsy/Client/link_post_count_i.dat +0 -0
  12. data/.yardoc/objects/Topsy/Client/link_posts_i.dat +0 -0
  13. data/.yardoc/objects/Topsy/Client/mashup_i.dat +0 -0
  14. data/.yardoc/objects/Topsy/Client/profile_search_i.dat +0 -0
  15. data/.yardoc/objects/Topsy/Client/raise_errors_i.dat +0 -0
  16. data/.yardoc/objects/Topsy/Client/related_i.dat +0 -0
  17. data/.yardoc/objects/Topsy/Client/search_count_i.dat +0 -0
  18. data/.yardoc/objects/Topsy/Client/search_i.dat +0 -0
  19. data/.yardoc/objects/Topsy/Client/stats_i.dat +0 -0
  20. data/.yardoc/objects/Topsy/Client/tags_i.dat +0 -0
  21. data/.yardoc/objects/Topsy/Client/trackbacks_i.dat +0 -0
  22. data/.yardoc/objects/Topsy/Client/trending_i.dat +0 -0
  23. data/.yardoc/objects/Topsy/Client/url_info_i.dat +0 -0
  24. data/.yardoc/objects/Topsy/Client.dat +0 -0
  25. data/.yardoc/objects/Topsy/LinkSearchResult/to_s_i.dat +0 -0
  26. data/.yardoc/objects/Topsy/LinkSearchResult.dat +0 -0
  27. data/.yardoc/objects/Topsy/Linkpost/target_3D_i.dat +0 -0
  28. data/.yardoc/objects/Topsy/Linkpost/to_s_i.dat +0 -0
  29. data/.yardoc/objects/Topsy/Linkpost.dat +0 -0
  30. data/.yardoc/objects/Topsy/LinkpostCount/to_s_i.dat +0 -0
  31. data/.yardoc/objects/Topsy/LinkpostCount.dat +0 -0
  32. data/.yardoc/objects/Topsy/Page/initialize_i.dat +0 -0
  33. data/.yardoc/objects/Topsy/Page/list_3D_i.dat +0 -0
  34. data/.yardoc/objects/Topsy/Page/to_s_i.dat +0 -0
  35. data/.yardoc/objects/Topsy/Page.dat +0 -0
  36. data/.yardoc/objects/Topsy/RateLimitInfo/refresh_in_seconds_i.dat +0 -0
  37. data/.yardoc/objects/Topsy/RateLimitInfo/reset_i.dat +0 -0
  38. data/.yardoc/objects/Topsy/RateLimitInfo.dat +0 -0
  39. data/.yardoc/objects/Topsy/SearchCounts/all_time_i.dat +0 -0
  40. data/.yardoc/objects/Topsy/SearchCounts/hour_i.dat +0 -0
  41. data/.yardoc/objects/Topsy/SearchCounts/month_i.dat +0 -0
  42. data/.yardoc/objects/Topsy/SearchCounts/overall_i.dat +0 -0
  43. data/.yardoc/objects/Topsy/SearchCounts/this_hour_i.dat +0 -0
  44. data/.yardoc/objects/Topsy/SearchCounts/this_month_i.dat +0 -0
  45. data/.yardoc/objects/Topsy/SearchCounts/this_week_i.dat +0 -0
  46. data/.yardoc/objects/Topsy/SearchCounts/today_i.dat +0 -0
  47. data/.yardoc/objects/Topsy/SearchCounts/week_i.dat +0 -0
  48. data/.yardoc/objects/Topsy/SearchCounts.dat +0 -0
  49. data/.yardoc/objects/Topsy/Stats/to_s_i.dat +0 -0
  50. data/.yardoc/objects/Topsy/Stats.dat +0 -0
  51. data/.yardoc/objects/Topsy/Tag/to_s_i.dat +0 -0
  52. data/.yardoc/objects/Topsy/Tag.dat +0 -0
  53. data/.yardoc/objects/Topsy/Target/to_s_i.dat +0 -0
  54. data/.yardoc/objects/Topsy/Target.dat +0 -0
  55. data/.yardoc/objects/Topsy/Trend/to_s_i.dat +0 -0
  56. data/.yardoc/objects/Topsy/Trend.dat +0 -0
  57. data/.yardoc/objects/Topsy/Tweet/author_3D_i.dat +0 -0
  58. data/.yardoc/objects/Topsy/Tweet/target_3D_i.dat +0 -0
  59. data/.yardoc/objects/Topsy/Tweet/to_s_i.dat +0 -0
  60. data/.yardoc/objects/Topsy/Tweet.dat +0 -0
  61. data/.yardoc/objects/Topsy/UrlInfo/to_s_i.dat +0 -0
  62. data/.yardoc/objects/Topsy/UrlInfo.dat +0 -0
  63. data/.yardoc/objects/Topsy.dat +0 -0
  64. data/.yardoc/objects/root.dat +0 -0
  65. data/.yardoc/proxy_types +0 -0
  66. data/README.markdown +71 -6
  67. data/Rakefile +1 -1
  68. data/TODO +7 -0
  69. data/VERSION +1 -1
  70. data/doc/Topsy/Author.html +201 -0
  71. data/doc/Topsy/Client.html +2096 -0
  72. data/doc/Topsy/LinkSearchResult.html +152 -0
  73. data/doc/Topsy/Linkpost.html +209 -0
  74. data/doc/Topsy/LinkpostCount.html +152 -0
  75. data/doc/Topsy/Page.html +284 -0
  76. data/doc/Topsy/RateLimitInfo.html +201 -0
  77. data/doc/Topsy/SearchCounts.html +91 -0
  78. data/doc/Topsy/Stats.html +152 -0
  79. data/doc/Topsy/Tag.html +152 -0
  80. data/doc/Topsy/Target.html +152 -0
  81. data/doc/Topsy/Trend.html +152 -0
  82. data/doc/Topsy/Tweet.html +266 -0
  83. data/doc/Topsy/UrlInfo.html +152 -0
  84. data/doc/Topsy.html +112 -0
  85. data/doc/_index.html +245 -0
  86. data/doc/class_list.html +177 -0
  87. data/doc/css/common.css +1 -0
  88. data/doc/css/full_list.css +23 -0
  89. data/doc/css/style.css +263 -0
  90. data/doc/file.README.html +151 -0
  91. data/doc/file_list.html +29 -0
  92. data/doc/index.html +151 -0
  93. data/doc/js/app.js +91 -0
  94. data/doc/js/full_list.js +39 -0
  95. data/doc/js/jquery.js +19 -0
  96. data/doc/method_list.html +352 -0
  97. data/doc/top-level-namespace.html +79 -0
  98. data/lib/topsy/author.rb +23 -0
  99. data/lib/topsy/client.rb +48 -21
  100. data/lib/topsy/link_search_result.rb +24 -0
  101. data/lib/topsy/linkpost.rb +33 -0
  102. data/lib/topsy/linkpost_count.rb +15 -0
  103. data/lib/topsy/page.rb +40 -0
  104. data/lib/topsy/rate_limit_info.rb +18 -0
  105. data/lib/topsy/search_counts.rb +9 -30
  106. data/lib/topsy/stats.rb +18 -0
  107. data/lib/topsy/tag.rb +16 -0
  108. data/lib/topsy/target.rb +18 -0
  109. data/lib/topsy/trend.rb +16 -0
  110. data/lib/topsy/tweet.rb +44 -0
  111. data/lib/topsy/url_info.rb +21 -0
  112. data/lib/topsy.rb +36 -4
  113. data/script/console +10 -0
  114. data/script/destroy +14 -0
  115. data/script/generate +14 -0
  116. data/test/fixtures/credit.json +15 -0
  117. data/test/fixtures/urlinfo.json +2 -2
  118. data/test/helper.rb +9 -4
  119. data/test/test_topsy.rb +92 -11
  120. data/topsy.gemspec +194 -0
  121. metadata +86 -5
  122. data/.yardoc/objects/Topsy/SearchCounts/last_hour_i.dat +0 -0
  123. data/.yardoc/objects/Topsy/SearchCounts/last_month_i.dat +0 -0
  124. data/.yardoc/objects/Topsy/SearchCounts/last_week_i.dat +0 -0
@@ -0,0 +1,15 @@
1
+ # This is the linkpost_count class for the topsy library.
2
+ # A LinkpostCount has the following attributes:
3
+ # "contains" : 0,
4
+ # "all" : 46
5
+ #
6
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources?tm=6#/linkpostcount
7
+ #
8
+ module Topsy
9
+
10
+ class LinkpostCount < Hashie::Mash
11
+ def to_s
12
+ "Topsy LinkpostCount: #{all}"
13
+ end
14
+ end
15
+ end
data/lib/topsy/page.rb ADDED
@@ -0,0 +1,40 @@
1
+ # This is the page class for the topsy library.
2
+ # A Page has the following attributes:
3
+ # "page" : 1,
4
+ # "total" : "1139",
5
+ # "perpage" : 15,
6
+ # "list" : Array of Author instances
7
+ #
8
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources?tm=6#/authorsearch
9
+ #
10
+ module Topsy
11
+
12
+ class Page < Hashie::Dash
13
+ property :total
14
+ property :list
15
+ property :page
16
+ property :perpage
17
+ property :window
18
+ property :topsy_trackback_url
19
+
20
+ def to_s
21
+ "Topsy Page: #{page} of #{total}, #{list.size} authors"
22
+ end
23
+
24
+ def initialize(content, klass)
25
+ @klass = klass
26
+ super(content)
27
+ end
28
+
29
+ def list=(value)
30
+ result = []
31
+ if value
32
+ value.each{ |x| result << @klass.new(x) }
33
+ self[:list] = result
34
+ else
35
+ self[:list] = value
36
+ end
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,18 @@
1
+ module Topsy
2
+
3
+ class RateLimitInfo < Hashie::Dash
4
+
5
+ property :reset
6
+ property :limit
7
+ property :remaining
8
+
9
+ def refresh_in_seconds
10
+ Time.at(reset) - Time.now
11
+ end
12
+
13
+ def reset
14
+ Time.at(self[:reset]) unless self[:reset].respond_to?(:year)
15
+ end
16
+ end
17
+
18
+ end
@@ -6,41 +6,20 @@ module Topsy
6
6
  property :m, :default => 0
7
7
  property :a, :default => 0
8
8
 
9
- def last_hour
10
- h
11
- end
9
+ alias :hour :h
10
+ alias :this_hour :h
12
11
 
13
- def this_hour
14
- h
15
- end
12
+ alias :today :d
16
13
 
17
- def today
18
- d
19
- end
14
+ alias :week :w
15
+ alias :this_week :w
20
16
 
21
- def last_week
22
- w
23
- end
17
+ alias :month :m
18
+ alias :this_month :m
24
19
 
25
- def this_week
26
- w
27
- end
20
+ alias :overall :a
21
+ alias :all_time :a
28
22
 
29
- def last_month
30
- m
31
- end
32
-
33
- def this_month
34
- m
35
- end
36
-
37
- def all_time
38
- a
39
- end
40
-
41
- def overall
42
- a
43
- end
44
23
 
45
24
  end
46
25
  end
@@ -0,0 +1,18 @@
1
+ # This is the stats class for the topsy library.
2
+ # A Stats instance has the following attributes:
3
+ # "topsy_trackback_url" : "http://topsy.com/tb/etagwerker.com/",
4
+ # "contains" : "1931",
5
+ # "influential" : "874",
6
+ # "all" : "1931"
7
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources?tm=6#/stats
8
+ #
9
+ module Topsy
10
+
11
+ class Stats < Hashie::Mash
12
+
13
+ def to_s
14
+ "Topsy Stats: #{topsy_trackback_url}"
15
+ end
16
+
17
+ end
18
+ end
data/lib/topsy/tag.rb ADDED
@@ -0,0 +1,16 @@
1
+ # This is the tag class for the topsy library.
2
+ # A Tag instance has the following attributes:
3
+ # "url" : "http://topsy.com/s?q=current",
4
+ # "name" : "current"
5
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources?tm=6#/tags
6
+ #
7
+ module Topsy
8
+
9
+ class Tag < Hashie::Mash
10
+
11
+ def to_s
12
+ "Topsy Tag: #{name}"
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # This is the target class for the topsy library.
2
+ # A Target has the following attributes:
3
+ # "topsy_trackback_url" : "http://topsy.com/tb/my.barackobama.com/page/community/post/obamaforamerica/gGMPVm",
4
+ # "url" : "http://my.barackobama.com/page/community/post/obamaforamerica/gGMPVm",
5
+ # "trackback_total" : "43"
6
+ #
7
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources?tm=6#/linkposts
8
+ #
9
+ module Topsy
10
+
11
+ class Target < Hashie::Mash
12
+
13
+ def to_s
14
+ "Topsy Target: #{url}"
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # This is the trend class for the topsy library.
2
+ # A Trend instance has the following attributes:
3
+ # "url" : "http://topsy.com/s?q=dominick",
4
+ # "term" : "dominick"
5
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources?tm=6#/trending
6
+ #
7
+ module Topsy
8
+
9
+ class Trend < Hashie::Mash
10
+
11
+ def to_s
12
+ "Topsy Trend: #{term}"
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ # This is the tweet class for the topsy library.
2
+ # A Tweet instance has the following attributes:
3
+ # "permalink_url" : "http://twitter.com/etagwerker/status/3565855201",
4
+ # "date" : "1251324809",
5
+ # "content" : "TOPSY - A search engine powered by tweets: http://topsy.com (this Search Engine can
6
+ # be powerful for sifting through Twitter- love it)!",
7
+ # "type" : "tweet",
8
+ # "author" : author instance
9
+ # "date_alpha" : "6 hours ago"
10
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources?tm=6#/trackbacks
11
+ #
12
+ module Topsy
13
+
14
+ class Tweet < Hashie::Dash
15
+ property :permalink_url
16
+ property :date
17
+ property :content
18
+ property :type
19
+ property :author
20
+ property :date_alpha
21
+ property :target
22
+
23
+ def to_s
24
+ "Topsy Tweet: #{permalink_url}, #{content}"
25
+ end
26
+
27
+ def author=(value)
28
+ if value
29
+ self[:author] = Topsy::Author.new(value)
30
+ else
31
+ self[:author] = value
32
+ end
33
+ end
34
+
35
+ def target=(value)
36
+ if value
37
+ self[:target] = Topsy::Target.new(value)
38
+ else
39
+ self[:target] = value
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ # This is the url_info class for the topsy library.
2
+ # An UrlInfo has the following attributes:
3
+ # "topsy_trackback_url" : "http://topsy.com/tb/twitter.com/",
4
+ # "oneforty" : "Twitter: What are you doing? http://twurl.nl/pd8k44",
5
+ # "url" : "http://etagwerker.com/",
6
+ # "title" : "Tech Notes From The Trenches",
7
+ # "trackback_total" : "24152",
8
+ # "description" : "Social networking and microblogging service utilising instant messaging, SMS or a web interface.",
9
+ # "description_attribution" : "From DMOZ"
10
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources?tm=6#/urlinfo
11
+ #
12
+ module Topsy
13
+
14
+ class UrlInfo < Hashie::Mash
15
+
16
+ def to_s
17
+ "Topsy UrlInfo: #{url}, @#{topsy_trackback_url}, #{trackback_total} total"
18
+ end
19
+
20
+ end
21
+ end
data/lib/topsy.rb CHANGED
@@ -45,9 +45,10 @@ module Topsy
45
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
46
  # @option options [Integer] :page page number of the result set. (default: 1, max: 10)
47
47
  # @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
48
- # @return [Hashie::Mash]
48
+ # @return [Topsy::Page]
49
49
  def self.author_search(q, options={})
50
- Topsy::Client.new.author_search(q, options)
50
+ result = Topsy::Client.new.author_search(q, options)
51
+ Topsy::Page.new(result, Topsy::Author)
51
52
  end
52
53
 
53
54
  # Returns list of URLs posted by an author
@@ -67,9 +68,10 @@ module Topsy
67
68
  # @param [String] url URL string for the author.
68
69
  # @param [Hash] options method options
69
70
  # @option options [String] :contains Query string to filter results
70
- # @return [Hashie::Mash]
71
+ # @return [Topsy::LinkpostCount]
71
72
  def self.link_post_count(url, options={})
72
- Topsy::Client.new.link_post_count(url, options={})
73
+ response = Topsy::Client.new.link_post_count(url, options={})
74
+ Topsy::LinkpostCount.new(response)
73
75
  end
74
76
 
75
77
  # 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.
@@ -166,9 +168,39 @@ module Topsy
166
168
  def self.url_info(url)
167
169
  Topsy::Client.new.url_info(url)
168
170
  end
171
+
172
+ # Returns info about API rate limiting
173
+ #
174
+ # @return [RateLimitInfo]
175
+ def self.credit
176
+ Topsy::Client.new.credit
177
+ end
178
+
179
+
180
+ def self.rate_limit
181
+ self.credit if @rate_limit_info.nil?
182
+ @rate_limit_info
183
+ end
184
+
185
+ def self.rate_limit=(info)
186
+ @rate_limit_info = Topsy::RateLimitInfo.new(info)
187
+ end
169
188
 
170
189
 
171
190
  end
172
191
 
192
+ require File.join(directory, 'topsy', 'rate_limit_info')
193
+ require File.join(directory, 'topsy', 'author')
194
+ require File.join(directory, 'topsy', 'linkpost')
195
+ require File.join(directory, 'topsy', 'link_search_result')
196
+ require File.join(directory, 'topsy', 'linkpost_count')
197
+ require File.join(directory, 'topsy', 'page')
173
198
  require File.join(directory, 'topsy', 'search_counts')
199
+ require File.join(directory, 'topsy', 'stats')
200
+ require File.join(directory, 'topsy', 'target')
201
+ require File.join(directory, 'topsy', 'tag')
202
+ require File.join(directory, 'topsy', 'trend')
203
+ require File.join(directory, 'topsy', 'tweet')
204
+ require File.join(directory, 'topsy', 'url_info')
205
+
174
206
  require File.join(directory, 'topsy', 'client')
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/topsy.rb'}"
9
+ puts "Loading topsy gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,15 @@
1
+ {
2
+ "request": {
3
+ "response_type": "json",
4
+ "resource": "credit",
5
+ "parameters": {},
6
+ "url": "http://button.topsy.com/credit.json"
7
+ },
8
+ "response": {
9
+ "remaining": 10000,
10
+ "reset": 1262707200,
11
+ "limit": 10000,
12
+ "refresh_in_secs": 1503
13
+ }
14
+ }
15
+
@@ -9,10 +9,10 @@
9
9
  },
10
10
  "response": {
11
11
  "oneforty": "trending topics - -amp09 right up there past the president today! :) http://tiny.cc/3yNbv",
12
- "description": "",
12
+ "description": "Social networking",
13
13
  "trackback_total": 39379,
14
14
  "topsy_trackback_url": "http://topsy.com/tb/twitter.com/",
15
- "description_attribution": "",
15
+ "description_attribution": "From DMOZ",
16
16
  "url": "http://twitter.com/",
17
17
  "title": "trending topics - -amp09 right up there past the president today! :)"
18
18
  }
data/test/helper.rb CHANGED
@@ -32,11 +32,16 @@ def topsy_url(url)
32
32
  url =~ /^http/ ? url : "http://otter.topsy.com#{url}"
33
33
  end
34
34
 
35
- def stub_get(url, filename, status=nil)
36
- options = {:body => fixture_file(filename)}
37
- options.merge!({:status => status}) unless status.nil?
35
+ def stub_get(url, filename, options={})
36
+ opts = {:body => fixture_file(filename)}.merge(options)
38
37
 
39
- FakeWeb.register_uri(:get, topsy_url(url), options)
38
+ headers = {
39
+ 'x-ratelimit-remaining' => '9998',
40
+ 'x-ratelimit-limit' => '10000',
41
+ 'x-ratelimit-reset' => '1262707200'
42
+ }
43
+
44
+ FakeWeb.register_uri(:get, topsy_url(url), headers.merge(opts))
40
45
  end
41
46
 
42
47
  def stub_post(url, filename)
data/test/test_topsy.rb CHANGED
@@ -4,95 +4,176 @@ class TestTopsy < Test::Unit::TestCase
4
4
 
5
5
  context "when hitting the Otter API" do
6
6
 
7
+ should "return rate limit information when calling credit" do
8
+ stub_get("/credit.json", "credit.json")
9
+ Topsy.rate_limit.limit.should == 10000
10
+ Topsy.rate_limit.remaining.should == 9998
11
+ Topsy.rate_limit.reset.should == Time.at(1262707200)
12
+ end
13
+
14
+ should "return rate limit information with every request" do
15
+
16
+ # FakeWeb.register_uri(:get, "http://otter.topsy.com/authorinfo.json?url=http%3A%2F%2Ftwitter.com%2Fpengwynn", headers)
17
+ stub_get("/authorinfo.json?url=http%3A%2F%2Ftwitter.com%2Fpengwynn", "authorinfo.json")
18
+
19
+ info = Topsy.author_info("http://twitter.com/pengwynn")
20
+
21
+ Topsy.rate_limit.limit.should == 10000
22
+ Topsy.rate_limit.remaining.should == 9998
23
+ Topsy.rate_limit.reset.should == Time.at(1262707200)
24
+ end
25
+
7
26
  should "return author info for a profile url" do
8
27
  stub_get("/authorinfo.json?url=http%3A%2F%2Ftwitter.com%2Fpengwynn", "authorinfo.json")
9
28
  info = Topsy.author_info("http://twitter.com/pengwynn")
29
+ info.class.should == Topsy::Author
10
30
  info.nick.should == 'pengwynn'
11
31
  info.influence_level.should == 10
32
+ assert info.description.include? "Ruby"
33
+ info.name.should == "Wynn Netherland"
34
+ info.url.should == "http://twitter.com/pengwynn"
35
+ info.topsy_author_url.should == "http://topsy.com/twitter/pengwynn"
36
+ info.type.should == 'twitter'
12
37
  end
13
38
 
14
- should "return search for authors" do
39
+ should "return a page with a list of authors for the search" do
15
40
  stub_get("/authorsearch.json?q=pengwynn", "authorsearch.json")
16
41
  results = Topsy.author_search("pengwynn")
42
+ results.class.should == Topsy::Page
17
43
  results.total.should == 491
44
+ results.list.first.class.should == Topsy::Author
18
45
  results.list.first.nick.should == 'bradleyjoyce'
19
46
  end
20
47
 
21
- should "list of urls posted by an author" do
48
+ should "return a page with a list of urls posted by an author" do
22
49
  stub_get("/linkposts.json?url=http%3A%2F%2Ftwitter.com%2Fpengwynn", "linkposts.json")
23
50
  results = Topsy.link_posts("http://twitter.com/pengwynn")
51
+ results.class.should == Topsy::Page
24
52
  results.total.should == 1004
53
+ results.list.first.class.should == Topsy::Linkpost
25
54
  results.list.first.content.should == 'For auld lang syne, my dear: http://en.wikipedia.org/wiki/Auld_Lang_Syne#Lyrics'
55
+ results.list.first.permalink_url.should == 'http://twitter.com/pengwynn/status/7253938349'
56
+ results.list.first.target.class.should == Topsy::Target
57
+ results.list.first.date.should == 1262307998
58
+ results.list.first.date_alpha.should == '16 hours ago'
26
59
  end
27
60
 
28
61
  should "return count of links posted by an author" do
29
62
  stub_get("/linkpostcount.json?url=http%3A%2F%2Ftwitter.com%2Fpengwynn", "linkpostcount.json")
30
63
  counts = Topsy.link_post_count("http://twitter.com/pengwynn")
64
+ counts.class.should == Topsy::LinkpostCount
31
65
  counts.all.should == 1004
32
66
  counts.contains.should == 0
33
67
  end
34
68
 
35
- should "return a list of author profiles that match the query." do
69
+ should "return a page with a list of authors that match the query." do
36
70
  stub_get("/profilesearch.json?q=pengwynn", "profilesearch.json")
37
71
  results = Topsy.profile_search("pengwynn")
72
+ results.class.should == Topsy::Page
38
73
  results.total.should == 1
74
+ results.list.first.class.should == Topsy::Author
39
75
  results.list.first.influence_level.should == 10
40
76
  end
41
77
 
42
- should "return a list of URLs related to a given URL" do
78
+ should "return a page with a list of URLs related to a given URL" do
43
79
  stub_get("/related.json?url=http%3A%2F%2Fgemcutter.org", "related.json")
44
80
  results = Topsy.related("http://gemcutter.org")
81
+ results.class.should == Topsy::Page
45
82
  results.total.should == 17
83
+ results.list.first.class.should == Topsy::LinkSearchResult
46
84
  results.list.first.title.should == 'the update | gemcutter | awesome gem hosting'
85
+ results.list.first.trackback_total.should == 17
86
+ results.list.first.topsy_trackback_url.should == "http://topsy.com/tb/update.gemcutter.org/"
87
+ results.list.first.url.should == "http://update.gemcutter.org/"
47
88
  end
48
89
 
49
- should "return a list of results for a query" do
90
+ should "return a page with a list of link search results for a query" do
50
91
  stub_get("/search.json?q=NYE", "search.json")
51
92
  results = Topsy.search("NYE")
93
+ results.class.should == Topsy::Page
52
94
  results.total.should == 117731
95
+ results.page.should == 1
96
+ results.perpage.should == 10
97
+ results.window.should == "a"
98
+ results.list.first.class.should == Topsy::LinkSearchResult
53
99
  results.list.first.score.should == 4.70643044
100
+ results.list.first.trackback_permalink.should == "http://twitter.com/spin/status/5164154014"
101
+ results.list.first.hits.should == 397
102
+ results.list.first.trackback_total.should == 2268
103
+ results.list.first.topsy_trackback_url.should == "http://topsy.com/trackback?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXGK84Poeynk"
104
+ results.list.first.url.should == "http://www.youtube.com/watch?v=XGK84Poeynk"
105
+ results.list.first.content.should == "Science, autotuned, with Sagan, Bill Nye, Tyson, Feynman http://bit.ly/2tDk4y win!"
106
+ results.list.first.title.should == "YouTube - Symphony of Science - 'We Are All Connected' (ft. Sagan, Feynman, deGrasse Tyson & Bill Nye)"
107
+ results.list.first.highlight.should == "Science, autotuned, with Sagan, Bill <span class=\"highlight-term\">Nye</span>, Tyson, Feynman http://bit.ly/2tDk4y win! "
54
108
  end
55
109
 
56
110
  should "return search counts for a term" do
57
111
  stub_get("/searchcount.json?q=Balloon%20Boy", "searchcount.json")
58
112
  counts = Topsy.search_count('Balloon Boy')
59
- counts.last_hour.should == 0
60
- counts.last_month.should == 3659
113
+ counts.class.should == Topsy::SearchCounts
114
+ counts.this_hour.should == 0
115
+ counts.this_month.should == 3659
61
116
  counts.all_time.should == 42289
62
117
  end
63
118
 
64
- should "return count of tweets for a url" do
119
+ should "return a stats object for a url" do
65
120
  stub_get("/stats.json?url=http%3A%2F%2Fgithub.com%2Fpengwynn%2Flinkedin", "stats.json")
66
121
  stats = Topsy.stats("http://github.com/pengwynn/linkedin")
122
+ stats.class.should == Topsy::Stats
123
+ stats.topsy_trackback_url.should == "http://topsy.com/tb/github.com/pengwynn/linkedin"
124
+ stats.contains.should == 0
67
125
  stats.all.should == 11
68
126
  stats.influential.should == 3
69
127
  end
70
128
 
71
- should "return a list of tags associated with a url" do
129
+ should "return a page with a list of tags associated with a url" do
72
130
  stub_get("/tags.json?url=http%3A%2F%2Fgemcutter.org", "tags.json")
73
131
  results = Topsy.tags("http://gemcutter.org")
132
+ results.class.should == Topsy::Page
74
133
  results.total.should == 9
134
+ results.list.first.class.should == Topsy::Tag
75
135
  assert results.list.map{|t| t.name}.include?("ruby")
136
+ results.list.first.url.should == "http://topsy.com/s?q=itunesu"
137
+ results.list.first.name.should == "itunesu"
76
138
  end
77
139
 
78
- should "return a list of tweets (trackbacks) that mention the query URL" do
140
+ should "return a page with a list of tweets (trackbacks) that mention the query URL" do
79
141
  stub_get("/trackbacks.json?url=http%3A%2F%2Forrka.com", "trackbacks.json")
80
142
  results = Topsy.trackbacks("http://orrka.com")
143
+ results.class.should == Topsy::Page
81
144
  results.total.should == 3
145
+ results.list.first.class.should == Topsy::Tweet
82
146
  results.list.first.date.year.should == 2009
147
+ results.list.first.permalink_url.should == "http://twitter.com/orrka/status/6435248067"
148
+ results.list.first.date.should == Time.at(1260204073)
149
+ results.list.first.content.should == "Just added some portfolio entries to http://orrka.com/"
150
+ results.list.first.type.should == "tweet"
151
+ results.list.first.author.class.should == Topsy::Author
152
+ results.list.first.date_alpha.should == "25 days ago"
83
153
  end
84
154
 
85
- should "return a list of trending terms" do
155
+ should "return a page with a list of trending terms" do
86
156
  stub_get("/trending.json", "trending.json")
87
157
  results = Topsy.trending
158
+ results.class.should == Topsy::Page
88
159
  results.total.should == 1379
160
+ results.list.first.class.should == Topsy::Trend
89
161
  assert results.list.map{|t| t.term}.flatten.include?("auld lang syne")
162
+ results.list.first.url.should == "http://topsy.com/s?q=photoshop+photoshop"
163
+ results.list.first.term.should == "photoshop photoshop"
90
164
  end
91
165
 
92
166
  should "return info about a url" do
93
167
  stub_get("/urlinfo.json?url=http%3A%2F%2Fwynnnetherland.com", 'urlinfo.json')
94
168
  results = Topsy.url_info('http://wynnnetherland.com')
169
+ results.class.should == Topsy::UrlInfo
95
170
  results.trackback_total.should == 39379
171
+ results.topsy_trackback_url.should == "http://topsy.com/tb/twitter.com/"
172
+ results.oneforty.should == "trending topics - -amp09 right up there past the president today! :) http://tiny.cc/3yNbv"
173
+ results.url.should == "http://twitter.com/"
174
+ results.title.should == "trending topics - -amp09 right up there past the president today! :)"
175
+ results.description.should == "Social networking"
176
+ results.description_attribution.should == "From DMOZ"
96
177
  end
97
178
  end
98
179