topsy 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ module Topsy
3
3
  include HTTParty
4
4
  format :json
5
5
  base_uri "http://otter.topsy.com"
6
- @@windows = {:all => 'a', :auto => 'auto', :week => 'w', :day => 'd', :month => 'm', :hour => 'h', :realtime => 'realtime'}
6
+ @@windows = {:all => 'a', :week => 'w', :day => 'd', :month => 'm', :hour => 'h', :realtime => 'realtime'}
7
7
 
8
8
  # Returns info about API rate limiting
9
9
  #
@@ -25,12 +25,12 @@ module Topsy
25
25
  #
26
26
  # @param [String] q the search query string
27
27
  # @param [Hash] options method options
28
- # @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
28
+ # @option options [Symbol] :window Time window for results. (default: :all) Options: :dynamic most relevant, :hour last hour, :day last day, :week last week, :month last month, :all all time. You can also use the h6 (6 hours) d3 (3 days) syntax.
29
29
  # @option options [Integer] :page page number of the result set. (default: 1, max: 10)
30
30
  # @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
31
31
  # @return [Hashie::Mash]
32
32
  def experts(q, options={})
33
- options[:window] = @@windows[options[:window]] if options[:window]
33
+ options = set_window_or_default(options)
34
34
  handle_response(self.class.get("/experts.json", :query => {:q => q}.merge(options)))
35
35
  end
36
36
 
@@ -74,7 +74,7 @@ module Topsy
74
74
  #
75
75
  # @param [String] q the search query string
76
76
  # @param [Hash] options method options
77
- # @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
77
+ # @option options [Symbol] :window Time window for results. (default: :all) Options: :dynamic most relevant, :hour last hour, :day last day, :week last week, :month last month, :all all time. You can also use the h6 (6 hours) d3 (3 days) syntax.
78
78
  # @option options [Integer] :page page number of the result set. (default: 1, max: 10)
79
79
  # @option options [Integer] :perpage limit number of results per page. (default: 10, max: 50)
80
80
  # @option options [String] :site narrow results to a domain
@@ -86,7 +86,7 @@ module Topsy
86
86
  else
87
87
  q += " site:#{options.delete(:site)}" if options[:site]
88
88
  end
89
- options[:window] = @@windows[options[:window]] if options[:window]
89
+ options = set_window_or_default(options)
90
90
  results = handle_response(self.class.get("/search.json", :query => {:q => q}.merge(options)))
91
91
  Topsy::Page.new(results,Topsy::LinkSearchResult)
92
92
  end
@@ -163,6 +163,11 @@ module Topsy
163
163
  end
164
164
 
165
165
  private
166
+
167
+ def set_window_or_default(options)
168
+ options[:window] = @@windows[options[:window]] if options[:window] && @@windows[options[:window]]
169
+ options
170
+ end
166
171
 
167
172
  def handle_response(response)
168
173
  raise_errors(response)
@@ -1,3 +1,3 @@
1
1
  module Topsy
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -109,6 +109,16 @@ class TestTopsy < Test::Unit::TestCase
109
109
  results = Topsy.search(:site => 'thechangelog.com', :window => :hour)
110
110
  end
111
111
 
112
+ should "handle hash queries with explicit window" do
113
+ stub_get("/search.json?q=site%3Athechangelog.com&window=h3", "search.json")
114
+ results = Topsy.search(:site => 'thechangelog.com', :window => 'h3')
115
+ end
116
+
117
+ should "handle hash queries with explicit window with undefined terms" do
118
+ stub_get("/search.json?q=site%3Athechangelog.com&window=dynamic", "search.json")
119
+ results = Topsy.search(:site => 'thechangelog.com', :window => :dynamic)
120
+ end
121
+
112
122
  should "handle combined queries" do
113
123
  stub_get("/search.json?q=riak%20site%3Athechangelog.com&window=h", "search.json")
114
124
  results = Topsy.search('riak', :site => 'thechangelog.com', :window => :hour)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2011-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hashie
17
- requirement: &70155566700020 !ruby/object:Gem::Requirement
17
+ requirement: &70188716824680 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70155566700020
25
+ version_requirements: *70188716824680
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: httparty
28
- requirement: &70155566699020 !ruby/object:Gem::Requirement
28
+ requirement: &70188716824040 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.8.1
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70155566699020
36
+ version_requirements: *70188716824040
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: shoulda
39
- requirement: &70155566698240 !ruby/object:Gem::Requirement
39
+ requirement: &70188716823180 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.11.3
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70155566698240
47
+ version_requirements: *70188716823180
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: mocha
50
- requirement: &70155566697520 !ruby/object:Gem::Requirement
50
+ requirement: &70188716822580 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 0.9.10
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70155566697520
58
+ version_requirements: *70188716822580
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: fakeweb
61
- requirement: &70155566696540 !ruby/object:Gem::Requirement
61
+ requirement: &70188716821960 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.3.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70155566696540
69
+ version_requirements: *70188716821960
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: jnunemaker-matchy
72
- requirement: &70155566694860 !ruby/object:Gem::Requirement
72
+ requirement: &70188716821140 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: 0.4.0
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70155566694860
80
+ version_requirements: *70188716821140
81
81
  description: Wrapper for the Topsy API
82
82
  email: wynn.netherland@gmail.com
83
83
  executables: []