topsy 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,6 +110,17 @@ module Topsy
110
110
  def self.search_count(q)
111
111
  Topsy::Client.new.search_count(q)
112
112
  end
113
+
114
+ # Returns data on the volume of tweets
115
+ #
116
+ # @param [String] the query
117
+ # @params [String] what is being counted - "target" (default) - the number of unique links , or "citation" - cthe number of unique tweets about links
118
+ # @params [Integer] The number of seconds for each slice ( default: 86400 = 1 day )
119
+ # @params [Integer] The number of slices (default 30 = 1 month)
120
+ # @return [Topsy::SearchHistogram]
121
+ def self.search_histogram( query , count_method = "target" , slice = 86400 , period = 30 )
122
+ Topsy::Client.new.search_histogram( query , count_method , slice , period )
123
+ end
113
124
 
114
125
  # Returns counts of tweets for a URL
115
126
  #
@@ -191,6 +202,7 @@ require File.join(directory, 'topsy', 'link_search_result')
191
202
  require File.join(directory, 'topsy', 'linkpost_count')
192
203
  require File.join(directory, 'topsy', 'page')
193
204
  require File.join(directory, 'topsy', 'search_counts')
205
+ require File.join(directory, 'topsy', 'search_histogram')
194
206
  require File.join(directory, 'topsy', 'stats')
195
207
  require File.join(directory, 'topsy', 'target')
196
208
  require File.join(directory, 'topsy', 'tag')
@@ -99,6 +99,18 @@ module Topsy
99
99
  counts = handle_response(self.class.get("/searchcount.json", :query => {:q => q}))
100
100
  Topsy::SearchCounts.new(counts)
101
101
  end
102
+
103
+ # Returns mention count data for the given query
104
+ #
105
+ # @param [String] q - The query. Use site:domain.com to get domain counts and @username to get mention counts.
106
+ # @param [String] count_method - what is being counted - "target" (default) - the number of unique links , or "citation" - cthe number of unique tweets about links
107
+ # @param [Integer] slice -
108
+ # @param [Integer] period -
109
+ #
110
+ def search_histogram( q , count_method , slice , period )
111
+ response = handle_response(self.class.get("/searchhistogram.json" , :query => { :q => q , :slice => slice , :period => period , :count_method => count_method } ))
112
+ Topsy::SearchHistogram.new(response)
113
+ end
102
114
 
103
115
  # Returns counts of tweets for a URL
104
116
  #
@@ -0,0 +1,18 @@
1
+ # This is the search_histogram class for the topsy library.
2
+ # A SearchHistogram has the following attributes:
3
+ # "histogram":[21024,10386,7270,12722,15993,17522,10517,8899,10363,11491,11729,16262,12940,8800,7589,8275,8692,14924,25927,30728,24562,22369,19203,33483,15497,11527,11814,11893,13998,7268],
4
+ # "period":30,
5
+ # "count_method":"citation",
6
+ # "slice":86400
7
+ # According to the official Topsy doc: http://code.google.com/p/otterapi/wiki/Resources#/searchhistogram
8
+ #
9
+ module Topsy
10
+
11
+ class SearchHistogram < Hashie::Mash
12
+
13
+ def to_s
14
+ "Topsy SearchHistogram: #{histogram}, Period: #{period}, Count Method: #{count_method} , Slice: #{slice}"
15
+ end
16
+
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Topsy
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -215,6 +215,40 @@ class TestTopsy < Test::Unit::TestCase
215
215
  results.description.should == "Social networking"
216
216
  results.description_attribution.should == "From DMOZ"
217
217
  end
218
+
219
+ context "#searchhistogram" do
220
+ context "citations" do
221
+ context "for domain" do
222
+ stub_get("/searchhistogram.json?q=site%3Abuzzfeed.com&slice=86400&period=30&count_method=citation", "searchhistogram-citation.json")
223
+ results = Topsy.search_histogram( 'site:buzzfeed.com' , "citation" , 86400 , 30 )
224
+ results.class.should == Topsy::SearchHistogram
225
+ results.period.should == 30
226
+ results.slice.should == 86400
227
+ results.count_method.should == "citation"
228
+ results.histogram.should == [21024,10386,7270,12722,15993,17522,10517,8899,10363,11491,11729,16262,12940,8800,7589,8275,8692,14924,25927,30728,24562,22369,19203,33483,15497,11527,11814,11893,13998,7268]
229
+ end
230
+
231
+ context "for user account" do
232
+ stub_get("/searchhistogram.json?q=%40garyvee&slice=86400&period=30&count_method=citation", "searchhistogram-mention-citation.json")
233
+ results = Topsy.search_histogram( '@garyvee' , "citation" , 86400 , 30 )
234
+ results.class.should == Topsy::SearchHistogram
235
+ results.period.should == 30
236
+ results.slice.should == 86400
237
+ results.count_method.should == "citation"
238
+ results.histogram.should == [69,77,279,117,143,186,123,49,75,75,173,167,58,42,46,40,64,186,94,166,96,146,106,51,42,101,89,69,209,78]
239
+ end
240
+
241
+ context "for keyword" do
242
+ stub_get("/searchhistogram.json?q=apple&slice=86400&period=30&count_method=citation", "searchhistogram-keyword-citation.json")
243
+ results = Topsy.search_histogram( 'apple' , "citation" , 86400 , 30 )
244
+ results.class.should == Topsy::SearchHistogram
245
+ results.period.should == 30
246
+ results.slice.should == 86400
247
+ results.count_method.should == "citation"
248
+ results.histogram.should == [249615,206548,161825,199043,267041,356657,303621,175584,166839,167086,197773,281216,234291,194937,162997,177703,167064,250086,300637,318948,361341,382810,254625,169622,203973,418762,550058,347752,370830,315412]
249
+ end
250
+ end
251
+ end
218
252
  end
219
253
 
220
254
  end
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.5.1
4
+ version: 0.6.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: &70126709212440 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 1.2.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70126709212440
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.2.0
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: httparty
28
- requirement: &70126709211980 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: 0.8.1
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70126709211980
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.8.1
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: shoulda
39
- requirement: &70126709211440 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ~>
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: 2.11.3
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70126709211440
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 2.11.3
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: mocha
50
- requirement: &70126709210860 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ~>
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: 0.9.10
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70126709210860
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 0.9.10
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: fakeweb
61
- requirement: &70126709210340 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ~>
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: 1.3.0
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *70126709210340
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.0
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: jnunemaker-matchy
72
- requirement: &70126709209660 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ~>
@@ -77,7 +102,12 @@ dependencies:
77
102
  version: 0.4.0
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *70126709209660
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.4.0
81
111
  description: Wrapper for the Topsy API
82
112
  email: wynn.netherland@gmail.com
83
113
  executables: []
@@ -92,6 +122,7 @@ files:
92
122
  - lib/topsy/page.rb
93
123
  - lib/topsy/rate_limit_info.rb
94
124
  - lib/topsy/search_counts.rb
125
+ - lib/topsy/search_histogram.rb
95
126
  - lib/topsy/stats.rb
96
127
  - lib/topsy/tag.rb
97
128
  - lib/topsy/target.rb
@@ -122,10 +153,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
153
  version: 1.3.6
123
154
  requirements: []
124
155
  rubyforge_project:
125
- rubygems_version: 1.8.10
156
+ rubygems_version: 1.8.23
126
157
  signing_key:
127
158
  specification_version: 3
128
159
  summary: Ruby wrapper for the Topsy API
129
160
  test_files:
130
161
  - test/helper.rb
131
162
  - test/test_topsy.rb
163
+ has_rdoc: