thecount 0.1.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -2
- data/lib/thecount/countable/google.rb +18 -0
- data/spec/countable/google_spec.rb +20 -1
- data/spec/thecount_spec.rb +2 -2
- data/thecount.gemspec +2 -2
- metadata +3 -4
data/README.md
CHANGED
@@ -2,7 +2,7 @@ TheCount Gem
|
|
2
2
|
====================
|
3
3
|
Provides a simple interface for counting and reporting arbitrary things on the web
|
4
4
|
|
5
|
-

|
6
6
|
|
7
7
|
Installation
|
8
8
|
-------------------
|
@@ -13,7 +13,7 @@ Sample Usage
|
|
13
13
|
# Setup a counting request
|
14
14
|
data = TheCount::count do |config|
|
15
15
|
# What do we want to count
|
16
|
-
config[:strategies] = [ TheCount::Twitter, TheCount::Facebook, TheCount::LinkedIn ]
|
16
|
+
config[:strategies] = [ TheCount::Twitter, TheCount::Facebook, TheCount::LinkedIn, TheCount::Google::Plus ]
|
17
17
|
|
18
18
|
# Where do we want to count it
|
19
19
|
config[:args] = { :url => "http://techcrunch.com/2011/06/16/rebecca-black-friday-video-no-longer-available-on-youtube/" }
|
@@ -23,11 +23,13 @@ Sample Usage
|
|
23
23
|
p "#{data[TheCount::Twitter].service_name} -> #{data[TheCount::Twitter].value}"
|
24
24
|
p "#{data[TheCount::Facebook].service_name} -> #{data[TheCount::Facebook].value}"
|
25
25
|
p "#{data[TheCount::LinkedIn].service_name} -> #{data[TheCount::LinkedIn].value}"
|
26
|
+
p "#{data[TheCount::Google::Plus].service_name} -> #{data[TheCount::Google::Plus].value}"
|
26
27
|
|
27
28
|
# (at the time of this example)
|
28
29
|
# twitter -> 900
|
29
30
|
# facebook -> 3000
|
30
31
|
# linkedin -> 444
|
32
|
+
# google -> 3333
|
31
33
|
|
32
34
|
Supported Services
|
33
35
|
-------------------
|
@@ -23,5 +23,23 @@ module TheCount
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
class Plus < TheCount::Countable
|
27
|
+
def initialize
|
28
|
+
@service_name = "google"
|
29
|
+
@unit = "shares"
|
30
|
+
@value = 0
|
31
|
+
end
|
32
|
+
def count(data)
|
33
|
+
url = "https://plusone.google.com/u/0/_/+1/fastbutton?url="
|
34
|
+
url = "#{url}#{CGI::escape(data[:url])}"
|
35
|
+
begin
|
36
|
+
# like penut butter brittle
|
37
|
+
@value = open(url).string.split('window.__SSR = {')[1].split('};')[0].split("'c':")[1].split(",")[0].strip.to_i
|
38
|
+
rescue Exception => e
|
39
|
+
puts e
|
40
|
+
@value = 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
26
44
|
end
|
27
45
|
end
|
@@ -18,4 +18,23 @@ describe TheCount::Google::Buzz do
|
|
18
18
|
goog.value.should > 0
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe TheCount::Google::Plus do
|
24
|
+
describe "#initialize" do
|
25
|
+
it "should set the correct defaults" do
|
26
|
+
goog = TheCount::Google::Plus.new
|
27
|
+
|
28
|
+
goog.service_name.should eql "google"
|
29
|
+
goog.unit.should eql "shares"
|
30
|
+
goog.value.should be 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
describe "#count" do
|
34
|
+
it "should return a non 0 integer for the count" do
|
35
|
+
goog = TheCount::Google::Plus.new
|
36
|
+
goog.count({ :url => 'http://www.google.com/' })
|
37
|
+
goog.value.should > 0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/thecount_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require 'helper'
|
|
5
5
|
describe TheCount do
|
6
6
|
describe "#count" do
|
7
7
|
context "given a single strategy input" do
|
8
|
-
it "should return an
|
8
|
+
it "should return an hash with an key-value pair for the strategy type" do
|
9
9
|
counts = TheCount::count do |config|
|
10
10
|
config[:strategies] = TheCount::Twitter
|
11
11
|
config[:args] = { :url => 'http://google.com' }
|
@@ -15,7 +15,7 @@ describe TheCount do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
context "given multiple strategies as input" do
|
18
|
-
it "should return an
|
18
|
+
it "should return an hash with an key-value pair for the strategy type" do
|
19
19
|
counts = TheCount::count do |config|
|
20
20
|
config[:strategies] = [TheCount::Facebook, TheCount::Twitter]
|
21
21
|
config[:args] = { :url => 'http://google.com' }
|
data/thecount.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'thecount'
|
3
|
-
gem.version = '0.
|
4
|
-
gem.date = '2011-
|
3
|
+
gem.version = '0.2'
|
4
|
+
gem.date = '2011-10-16'
|
5
5
|
gem.summary = "A simple generic counting service"
|
6
6
|
gem.description = "Provides a simple interface for counting and reporting arbitrary things on the web"
|
7
7
|
gem.author = "Ian Chan"
|
metadata
CHANGED
@@ -4,9 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
|
9
|
-
version: 0.1.1
|
7
|
+
- 2
|
8
|
+
version: "0.2"
|
10
9
|
platform: ruby
|
11
10
|
authors:
|
12
11
|
- Ian Chan
|
@@ -14,7 +13,7 @@ autorequire:
|
|
14
13
|
bindir: bin
|
15
14
|
cert_chain: []
|
16
15
|
|
17
|
-
date: 2011-
|
16
|
+
date: 2011-10-16 00:00:00 -07:00
|
18
17
|
default_executable:
|
19
18
|
dependencies: []
|
20
19
|
|