topsy 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,4 @@
1
- require 'rubygems'
2
-
3
- gem 'hashie', '~> 0.1.3'
4
1
  require 'hashie'
5
-
6
- gem 'httparty', '~> 0.4.5'
7
2
  require 'httparty'
8
3
 
9
4
  directory = File.expand_path(File.dirname(__FILE__))
@@ -12,6 +7,9 @@ Hash.send :include, Hashie::HashExtensions
12
7
 
13
8
 
14
9
  module Topsy
10
+
11
+ VERSION = "0.3.1"
12
+
15
13
  class TopsyError < StandardError
16
14
  attr_reader :data
17
15
 
@@ -58,7 +58,9 @@ module Topsy
58
58
  Topsy::LinkpostCount.new(count)
59
59
  end
60
60
 
61
- # 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.
61
+ # Returns list list of author profiles that match the query.
62
+ # The query is matched against the nick, name and biography
63
+ # information and the results are sorted by closeness of match and the influence of authors.
62
64
  #
63
65
  # @param [String] q the search query string
64
66
  # @param [Hash] options method options
@@ -89,8 +91,15 @@ module Topsy
89
91
  # @option options [Symbol] :window 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
90
92
  # @option options [Integer] :page page number of the result set. (default: 1, max: 10)
91
93
  # @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
94
+ # @option options [String] :site narrow results to a domain
92
95
  # @return [Topsy::Page]
93
96
  def search(q, options={})
97
+ if q.is_a?(Hash)
98
+ options = q
99
+ q = "site:#{options.delete(:site)}" if options[:site]
100
+ else
101
+ q += " site:#{options.delete(:site)}" if options[:site]
102
+ end
94
103
  options[:window] = @@windows[options[:window]] if options[:window]
95
104
  results = handle_response(self.class.get("/search.json", :query => {:q => q}.merge(options)))
96
105
  Topsy::Page.new(results,Topsy::LinkSearchResult)
@@ -18,6 +18,9 @@ module Topsy
18
18
  property :perpage
19
19
  property :window
20
20
  property :topsy_trackback_url
21
+ property :last_offset
22
+ property :offset
23
+ property :hidden
21
24
 
22
25
  @@windows = {'a' => :all, 'auto' => :auto, 'w' => :week, 'd' => :day, 'm' => :month, 'h' => :hour}
23
26
 
@@ -11,6 +11,7 @@ require 'shoulda'
11
11
  require 'matchy'
12
12
  require 'mocha'
13
13
  require 'fakeweb'
14
+ require 'redgreen'
14
15
 
15
16
 
16
17
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -106,25 +106,46 @@ class TestTopsy < Test::Unit::TestCase
106
106
  results.list.first.url.should == "http://update.gemcutter.org/"
107
107
  end
108
108
 
109
- should "return a page with a list of link search results for a query" do
110
- stub_get("/search.json?q=NYE&window=m", "search.json")
111
- results = Topsy.search("NYE", :window => :month)
112
- results.class.should == Topsy::Page
113
- results.total.should == 117731
114
- results.page.should == 1
115
- results.perpage.should == 10
116
- results.window.should == :month
117
- results.list.first.class.should == Topsy::LinkSearchResult
118
- results.list.first.score.should == 4.70643044
119
- results.list.first.trackback_permalink.should == "http://twitter.com/spin/status/5164154014"
120
- results.list.first.hits.should == 397
121
- results.list.first.trackback_total.should == 2268
122
- results.list.first.topsy_trackback_url.should == "http://topsy.com/trackback?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXGK84Poeynk"
123
- results.list.first.url.should == "http://www.youtube.com/watch?v=XGK84Poeynk"
124
- results.list.first.content.should == "Science, autotuned, with Sagan, Bill Nye, Tyson, Feynman http://bit.ly/2tDk4y win!"
125
- results.list.first.title.should == "YouTube - Symphony of Science - 'We Are All Connected' (ft. Sagan, Feynman, deGrasse Tyson & Bill Nye)"
126
- results.list.first.highlight.should == "Science, autotuned, with Sagan, Bill <span class=\"highlight-term\">Nye</span>, Tyson, Feynman http://bit.ly/2tDk4y win! "
109
+ context "when searching" do
110
+
111
+ should "handle string queries" do
112
+ stub_get("/search.json?q=NYE&window=m", "search.json")
113
+ results = Topsy.search("NYE", :window => :month)
114
+ end
115
+
116
+ should "handle hash queries" do
117
+ stub_get("/search.json?q=site%3Athechangelog.com&window=h", "search.json")
118
+ results = Topsy.search(:site => 'thechangelog.com', :window => :hour)
119
+ end
120
+
121
+ should "handle combined queries" do
122
+ stub_get("/search.json?q=riak%20site%3Athechangelog.com&window=h", "search.json")
123
+ results = Topsy.search('riak', :site => 'thechangelog.com', :window => :hour)
124
+ end
125
+
126
+ should "return a page with a list of link search results for a query" do
127
+ stub_get("/search.json?q=NYE&window=m", "search.json")
128
+ results = Topsy.search("NYE", :window => :month)
129
+ results.class.should == Topsy::Page
130
+ results.total.should == 117731
131
+ results.page.should == 1
132
+ results.perpage.should == 10
133
+ results.window.should == :month
134
+ results.list.first.class.should == Topsy::LinkSearchResult
135
+ results.list.first.score.should == 4.70643044
136
+ results.list.first.trackback_permalink.should == "http://twitter.com/spin/status/5164154014"
137
+ results.list.first.hits.should == 397
138
+ results.list.first.trackback_total.should == 2268
139
+ results.list.first.topsy_trackback_url.should == "http://topsy.com/trackback?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXGK84Poeynk"
140
+ results.list.first.url.should == "http://www.youtube.com/watch?v=XGK84Poeynk"
141
+ results.list.first.content.should == "Science, autotuned, with Sagan, Bill Nye, Tyson, Feynman http://bit.ly/2tDk4y win!"
142
+ results.list.first.title.should == "YouTube - Symphony of Science - 'We Are All Connected' (ft. Sagan, Feynman, deGrasse Tyson & Bill Nye)"
143
+ results.list.first.highlight.should == "Science, autotuned, with Sagan, Bill <span class=\"highlight-term\">Nye</span>, Tyson, Feynman http://bit.ly/2tDk4y win! "
144
+ end
127
145
  end
146
+
147
+
148
+
128
149
 
129
150
  should "return search counts for a term" do
130
151
  stub_get("/searchcount.json?q=Balloon%20Boy", "searchcount.json")
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 1
9
+ version: 0.3.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Wynn Netherland
@@ -10,88 +15,112 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-01-11 00:00:00 -05:00
18
+ date: 2010-07-27 00:00:00 -05:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
- name: hashie
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
21
23
  requirements:
22
- - - ~>
24
+ - - ">="
23
25
  - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ - 1
29
+ - 3
24
30
  version: 0.1.3
25
- version:
26
- - !ruby/object:Gem::Dependency
27
- name: httparty
31
+ name: hashie
32
+ prerelease: false
33
+ requirement: *id001
28
34
  type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
31
37
  requirements:
32
- - - ~>
38
+ - - ">="
33
39
  - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ - 4
43
+ - 5
34
44
  version: 0.4.5
35
- version:
45
+ name: httparty
46
+ prerelease: false
47
+ requirement: *id002
48
+ type: :runtime
36
49
  - !ruby/object:Gem::Dependency
37
- name: thoughtbot-shoulda
38
- type: :development
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
41
51
  requirements:
42
52
  - - ">="
43
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 2
56
+ - 10
57
+ - 1
44
58
  version: 2.10.1
45
- version:
46
- - !ruby/object:Gem::Dependency
47
- name: jnunemaker-matchy
59
+ name: shoulda
60
+ prerelease: false
61
+ requirement: *id003
48
62
  type: :development
49
- version_requirement:
50
- version_requirements: !ruby/object:Gem::Requirement
63
+ - !ruby/object:Gem::Dependency
64
+ version_requirements: &id004 !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "="
53
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ - 4
71
+ - 0
54
72
  version: 0.4.0
55
- version:
56
- - !ruby/object:Gem::Dependency
57
- name: mocha
73
+ name: jnunemaker-matchy
74
+ prerelease: false
75
+ requirement: *id004
58
76
  type: :development
59
- version_requirement:
60
- version_requirements: !ruby/object:Gem::Requirement
77
+ - !ruby/object:Gem::Dependency
78
+ version_requirements: &id005 !ruby/object:Gem::Requirement
61
79
  requirements:
62
- - - "="
80
+ - - ">="
63
81
  - !ruby/object:Gem::Version
64
- version: 0.9.4
65
- version:
66
- - !ruby/object:Gem::Dependency
82
+ segments:
83
+ - 1
84
+ - 2
85
+ - 5
86
+ version: 1.2.5
67
87
  name: fakeweb
88
+ prerelease: false
89
+ requirement: *id005
68
90
  type: :development
69
- version_requirement:
70
- version_requirements: !ruby/object:Gem::Requirement
91
+ - !ruby/object:Gem::Dependency
92
+ version_requirements: &id006 !ruby/object:Gem::Requirement
71
93
  requirements:
72
94
  - - ">="
73
95
  - !ruby/object:Gem::Version
74
- version: 1.2.5
75
- version:
76
- description: Ruby wrapper for the Topsy otterapi
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ name: yard
100
+ prerelease: false
101
+ requirement: *id006
102
+ type: :development
103
+ - !ruby/object:Gem::Dependency
104
+ version_requirements: &id007 !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ name: redgreen
112
+ prerelease: false
113
+ requirement: *id007
114
+ type: :development
115
+ description: Wrapper for the Topsy API
77
116
  email: wynn.netherland@gmail.com
78
117
  executables: []
79
118
 
80
119
  extensions: []
81
120
 
82
- extra_rdoc_files:
83
- - LICENSE
84
- - README.markdown
85
- - TODO
121
+ extra_rdoc_files: []
122
+
86
123
  files:
87
- - .gitignore
88
- - LICENSE
89
- - README.markdown
90
- - Rakefile
91
- - TODO
92
- - VERSION
93
- - changelog.markdown
94
- - lib/topsy.rb
95
124
  - lib/topsy/author.rb
96
125
  - lib/topsy/client.rb
97
126
  - lib/topsy/link_search_result.rb
@@ -106,56 +135,39 @@ files:
106
135
  - lib/topsy/trend.rb
107
136
  - lib/topsy/tweet.rb
108
137
  - lib/topsy/url_info.rb
109
- - script/console
110
- - script/destroy
111
- - script/generate
112
- - test/fixtures/authorinfo.json
113
- - test/fixtures/authorsearch-page2.json
114
- - test/fixtures/authorsearch.json
115
- - test/fixtures/credit.json
116
- - test/fixtures/linkpostcount.json
117
- - test/fixtures/linkposts-page2.json
118
- - test/fixtures/linkposts.json
119
- - test/fixtures/profilesearch.json
120
- - test/fixtures/related.json
121
- - test/fixtures/search.json
122
- - test/fixtures/searchcount.json
123
- - test/fixtures/stats.json
124
- - test/fixtures/tags.json
125
- - test/fixtures/trackbacks.json
126
- - test/fixtures/trending.json
127
- - test/fixtures/urlinfo.json
128
- - test/helper.rb
129
- - test/test_topsy.rb
130
- - topsy.gemspec
138
+ - lib/topsy.rb
131
139
  has_rdoc: true
132
- homepage: http://github.com/pengwynn/topsy
140
+ homepage: http://wynnnetherland.com/projects/topsy/
133
141
  licenses: []
134
142
 
135
143
  post_install_message:
136
- rdoc_options:
137
- - --charset=UTF-8
144
+ rdoc_options: []
145
+
138
146
  require_paths:
139
147
  - lib
140
148
  required_ruby_version: !ruby/object:Gem::Requirement
141
149
  requirements:
142
150
  - - ">="
143
151
  - !ruby/object:Gem::Version
152
+ segments:
153
+ - 0
144
154
  version: "0"
145
- version:
146
155
  required_rubygems_version: !ruby/object:Gem::Requirement
147
156
  requirements:
148
157
  - - ">="
149
158
  - !ruby/object:Gem::Version
150
- version: "0"
151
- version:
159
+ segments:
160
+ - 1
161
+ - 3
162
+ - 6
163
+ version: 1.3.6
152
164
  requirements: []
153
165
 
154
166
  rubyforge_project:
155
- rubygems_version: 1.3.5
167
+ rubygems_version: 1.3.6
156
168
  signing_key:
157
169
  specification_version: 3
158
- summary: Ruby wrapper for the Topsy otterapi
170
+ summary: Ruby wrapper for the Topsy API
159
171
  test_files:
160
172
  - test/helper.rb
161
173
  - test/test_topsy.rb
data/.gitignore DELETED
@@ -1,27 +0,0 @@
1
- ## Aptana
2
- .project
3
- .loadpath
4
-
5
- ## MAC OS
6
- .DS_Store
7
-
8
- ## TEXTMATE
9
- *.tmproj
10
- tmtags
11
-
12
- ## EMACS
13
- *~
14
- \#*
15
- .\#*
16
-
17
- ## VIM
18
- *.swp
19
-
20
- ## PROJECT::GENERAL
21
- coverage
22
- rdoc
23
- pkg
24
-
25
- ## PROJECT::SPECIFIC
26
- doc
27
- .yardoc
data/LICENSE DELETED
@@ -1,20 +0,0 @@
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.
@@ -1,102 +0,0 @@
1
- # Topsy
2
-
3
- Simple Ruby wrapper for the [Topsy.com](http://topsy.com) Otter API. Topsy is a search engine powered by tweets.
4
-
5
- ## Installation
6
-
7
- Topsy is hosted on Gemcutter, so:
8
-
9
- gem install gemcutter # if necessary
10
- gem tumble # if necessary
11
- sudo gem install topsy
12
-
13
- ## Usage
14
- >> Topsy.rate_limit
15
- => <#Topsy::RateLimitInfo limit=10000 remaining=10000 reset=1262804400>
16
-
17
- >> Topsy.author_info('http://twitter.com/barackobama')
18
- => <#Topsy::Author description="44th President of the United States" influence_level=10 name="Barack Obama" nick="barackobama" topsy_author_url="http://topsy.com/twitter/barackobama" type="twitter" url="http://twitter.com/barackobama">
19
-
20
- >> Topsy.author_search('programming')
21
- => <#Topsy::Page list=[<#Topsy::Author descript ... ] page=1 perpage=15 topsy_trackback_url=nil total=97229 window=nil>
22
-
23
- >> Topsy.author_search('programming', :perpage => 2, :page => 1)
24
- => <#Topsy::Page list=[<#Topsy::Author description="Most ... ] page=1 perpage=2 topsy_trackback_url=nil total=100685 window=nil>
25
-
26
- >> Topsy.link_posts('http://twitter.com/barackobama', :perpage => 2, :page => 2)
27
- => <#Topsy::Page list=[<#Topsy::Linkpost content="An important reminder ... ] page=2 perpage=2 topsy_trackback_url=nil total=402 window=nil>
28
-
29
- >> Topsy.link_posts('http://twitter.com/barackobama')
30
- => <#Topsy::Page list=[<#Topsy::Linkpost content="An important reminder about health reform on the @Whit... ] page=1 perpage=10 topsy_trackback_url=nil total=402 window=nil>
31
-
32
- >> Topsy.link_post_count('http://twitter.com/barackobama')
33
- => <#Topsy::LinkpostCount all=402 contains=0>
34
-
35
- >> Topsy.url_info('http://etagwerker.com')
36
- => <#Topsy::UrlInfo description="" description_attribution="" oneforty="just finished installing wordpress in a linux .." url="http://etagwerker.com/">
37
-
38
- >> Topsy.stats('http://www.google.com')
39
- => <#Topsy::Stats all=29869 contains=0 influential=2023 topsy_trackback_url="http://topsy.com/tb/www.google.com/">
40
-
41
- >> Topsy.search('rock')
42
- => <#Topsy::Page list=[<#Topsy::LinkSearchResult content="Why 30 Rock is a Rip-Off of The Muppet Show - http://is.gd/15KJZ" .. ] page=1 perpage=10 topsy_trackback_url=nil total=714429 window="a">
43
-
44
- >> Topsy.search('rock', :perpage => 2, :page => 3)
45
- => <#Topsy::Page list=[<#Topsy::LinkSearchResult content="Just released! Beatles Rock Band opening cinematic. Amaz ..." ] page=3 perpage=2 topsy_trackback_url=nil total=714429 window="a">
46
-
47
- >> Topsy.search('rock', :perpage => 2, :page => 3, :window => 'd')
48
- => <#Topsy::Page list=[<#Topsy::LinkSearchResult content="Be a Google Wave Rock Star http://ff.im/-dPdGL" highlight="Be a .. "] page=3 perpage=2 topsy_trackback_url=nil total=6064 window="d">
49
-
50
- >> Topsy.search_count('rock')
51
- => <#Topsy::SearchCounts a=5191790 d=7601 h=206 m=216179 w=45462>
52
-
53
- >> Topsy.profile_search('Hacker+Rubyist')
54
- => <#Topsy::Page list=[<#Topsy::Author description="Hacker; Rubyist; Bit Poet" influence_level=4 name="Ben Bleythi ...">] page=1 perpage=10 topsy_trackback_url=nil total=5 window=nil>
55
-
56
- >> Topsy.profile_search('Hacker+Rubyist', :perpage => 1, :page => 2)
57
- => <#Topsy::Page list=[<#Topsy::Author description="Rubyist, hacker, gamer (video, board and role-playing)... ">] page=2 perpage=1 topsy_trackback_url=nil total=5 window=nil>
58
-
59
- >> Topsy.related('http://www.twitter.com')
60
- => <#Topsy::Page list=[<#Topsy::LinkSearchResult title="New Twitter Feature: Body Counts | Danger Room ... ">] page=1 perpage=10 topsy_trackback_url=nil total=4458 window=nil>
61
-
62
- >> Topsy.tags('http://twitter.com')
63
- => <#Topsy::Page list=[<#Topsy::Tag name="current" url="http://topsy.com/s?q=current">, <#Topsy::Tag name="twe ... ">] page=1 perpage=10 topsy_trackback_url=nil total=1885 window=nil>
64
-
65
- >> Topsy.trending
66
- => <#Topsy::Page list=[<#Topsy::Trend term="u s reopens embassy in yemen" url="http://topsy.com/s?q=u+s%20r ... ">] page=1 perpage=10 topsy_trackback_url=nil total=1434 window=nil>
67
-
68
- >> Topsy.trending(:page => 3, :perpage => 2)
69
- => <#Topsy::Page list=[<#Topsy::Trend term="droid vs iphone" url="http://topsy.com/s?q=droid+vs%20iphone" ... ">] page=3 perpage=2 topsy_trackback_url=nil total=1434 window=nil>
70
-
71
- >> Topsy.trackbacks('http://twitter.com', :perpage => 2, :page => 2)
72
- => <#Topsy::Page list=[<#Topsy::Tweet author=<#Topsy::Author influence_level=8 name="tama" photo_url="http://a3.twimg .. ">] page=2 perpage=2 topsy_trackback_url="http://topsy.com/tb/twitter.com/" total=39705 window=nil>
73
-
74
- >> Topsy.trackbacks('http://twitter.com', :perpage => 2, :page => 2, :contains => 'mashable')
75
- => <#Topsy::Page list=[<#Topsy::Tweet author=<#Topsy::Author name="Hannah Grosvenor" photo_url="http://a1.t. ... >] page=2 perpage=2 topsy_trackback_url="http://topsy.com/tb/twitter.com/" total=41 window=nil>
76
-
77
- # Fetch search results for the query "gemcutter"
78
- >> results = Topsy.search("gemcutter")
79
- => <#Topsy::Page list=[<#Topsy::LinkSearchResult content="New design ... ]>
80
-
81
- # Fetch search counts for the query "gemcutter"
82
- >> counts = Topsy.search_count("gemcutter")
83
- => <#Topsy::SearchCounts a=773 d=6 h=0 m=103 w=24>
84
- >> counts.this_week
85
- => 24
86
-
87
- 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.
88
-
89
- ## Note on Patches/Pull Requests
90
-
91
- * Fork the project.
92
- * Make your feature addition or bug fix.
93
- * Add tests for it. This is important so I don't break it in a
94
- future version unintentionally.
95
- * Commit, do not mess with rakefile, version, or history.
96
- (if you want to have your own version, that is fine but
97
- bump version in a commit by itself I can ignore when I pull)
98
- * Send me a pull request. Bonus points for topic branches.
99
-
100
- ## Copyright
101
-
102
- Copyright (c) 2010 [Wynn Netherland](http://wynnnetherland.com). See LICENSE for details.