totalshares 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/example.rb +2 -2
- data/lib/totalshares.rb +9 -9
- data/lib/webpage.rb +82 -82
- data/lib/website.rb +70 -70
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 920c671498f685d00753f08d6391b6ee55ba7581
|
4
|
+
data.tar.gz: 4f1530352149e20c61dcf218c3fc2b7733fb38cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75e62b5d2819b55e47aaa66a17dd42cf23488d76a1a25eb57689a252a9ead15eae6f9f27bc7373dd84ed0bd221bcf31b744c49267787dd71bfb482af0530ed43
|
7
|
+
data.tar.gz: c9ee2e2472828a4baf34d4aa0255d4191f053b92f025e0d29a557cd78e0ebd32534b2e4f93f89644d47cb8bbd7ff2e4156d074019cecefd04efbe55cda6e3e83
|
data/examples/example.rb
CHANGED
@@ -4,7 +4,7 @@ require 'totalshares'
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
webpage = Webpage.new "http://www.thegeekstuff.com/2014/10/linux-kvm-create-guest-vm/"
|
7
|
+
webpage = Totalshares::Webpage.new "http://www.thegeekstuff.com/2014/10/linux-kvm-create-guest-vm/"
|
8
8
|
|
9
9
|
webpage.gplus :v => true
|
10
10
|
webpage.twitter :v => true
|
@@ -29,7 +29,7 @@ puts webpage.all
|
|
29
29
|
|
30
30
|
|
31
31
|
|
32
|
-
website = Website.new("www.thegeekstuff.com")
|
32
|
+
website = Totalshares::Website.new("www.thegeekstuff.com")
|
33
33
|
|
34
34
|
puts website.facebook :depth_limit => 1, :v => true
|
35
35
|
puts website.twitter :depth_limit => 1
|
data/lib/totalshares.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Totalshares
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
SOCIAL_URLS = {
|
3
|
+
"twitter" => "http://cdn.api.twitter.com/1/urls/count.json?url=",
|
4
|
+
"facebook" => "http://graph.facebook.com/?id=",
|
5
|
+
"linkedin" => "http://www.linkedin.com/countserv/count/share?format=json&url=",
|
6
|
+
"reddit" => "http://www.reddit.com/api/info.json?url=",
|
7
|
+
"stumbledupon" => "http://www.stumbleupon.com/services/1.01/badge.getinfo?url=",
|
8
|
+
"pinterest" => "http://api.pinterest.com/v1/urls/count.json?url=",
|
9
|
+
"gplus" => "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ"
|
10
|
+
}
|
11
11
|
end
|
12
12
|
|
13
13
|
require 'website'
|
data/lib/webpage.rb
CHANGED
@@ -1,100 +1,100 @@
|
|
1
1
|
require 'typhoeus'
|
2
2
|
require 'json'
|
3
3
|
require 'yaml'
|
4
|
-
|
5
|
-
class Webpage
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def twitter(opts = {})
|
13
|
-
output = Typhoeus.get(SOCIAL_URLS["twitter"] + @url)
|
14
|
-
count = JSON.parse(output.response_body)["count"].to_i || 0
|
15
|
-
puts "#{@url}\n#{count}" if opts[:v]
|
16
|
-
count
|
17
|
-
end
|
4
|
+
module Totalshares
|
5
|
+
class Webpage
|
6
|
+
def initialize(url)
|
7
|
+
@url = url
|
8
|
+
@url ="http://#{url}" unless url.start_with? "https://" or url.start_with? "http://"
|
9
|
+
end
|
18
10
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
11
|
+
def twitter(opts = {})
|
12
|
+
output = Typhoeus.get(SOCIAL_URLS["twitter"] + @url)
|
13
|
+
count = JSON.parse(output.response_body)["count"].to_i || 0
|
14
|
+
puts "#{@url}\n#{count}" if opts[:v]
|
15
|
+
count
|
16
|
+
end
|
25
17
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
18
|
+
def facebook(opts = {})
|
19
|
+
output = Typhoeus.get(SOCIAL_URLS["facebook"] + @url)
|
20
|
+
count = JSON.parse(output.response_body)["shares"].to_i || 0
|
21
|
+
puts "#{@url}\n#{count}" if opts[:v]
|
22
|
+
count
|
23
|
+
end
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
25
|
+
def linkedin(opts = {})
|
26
|
+
output = Typhoeus.get(SOCIAL_URLS["linkedin"] + @url)
|
27
|
+
count = JSON.parse(output.response_body)["count"].to_i || 0
|
28
|
+
puts "#{@url}\n#{count}" if opts[:v]
|
29
|
+
count
|
30
|
+
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
32
|
+
def reddit(opts = {})
|
33
|
+
output = Typhoeus.get(SOCIAL_URLS["reddit"] + @url)
|
34
|
+
count = JSON.parse(output.response_body)["data"]["children"].size.to_i || 0
|
35
|
+
puts "#{@url}\n#{count}" if opts[:v]
|
36
|
+
count
|
37
|
+
end
|
46
38
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
output = output.response_body
|
51
|
-
json_output = output[output.index("{"), output.rindex("}")- (output.index("{")-1)]
|
52
|
-
count = JSON.parse(json_output)["count"].to_i || 0
|
39
|
+
def stumbledupon(opts = {})
|
40
|
+
output = Typhoeus.get(SOCIAL_URLS["stumbledupon"] + @url)
|
41
|
+
count = JSON.parse(output.response_body)["result"]["views"].to_i || 0
|
53
42
|
puts "#{@url}\n#{count}" if opts[:v]
|
54
43
|
count
|
55
|
-
else
|
56
|
-
nil
|
57
44
|
end
|
58
|
-
end
|
59
45
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
jsonrpc: "2.0",
|
73
|
-
key: "p",
|
74
|
-
apiVersion: "v1"
|
75
|
-
}
|
76
|
-
]
|
77
|
-
output = Typhoeus.post(SOCIAL_URLS["gplus"], body: JSON.dump(body), headers: { "content-type" => "application/json", "accept" => "application/json"})
|
78
|
-
count = JSON.parse(output.response_body)[0]["result"]["metadata"]["globalCounts"]["count"].to_i || 0
|
79
|
-
puts "#{@url}\n#{count}" if opts[:v]
|
80
|
-
count
|
81
|
-
end
|
46
|
+
def pinterest(opts = {})
|
47
|
+
output = Typhoeus.get(SOCIAL_URLS["pinterest"] + @url)
|
48
|
+
if output.response_code.eql? 200
|
49
|
+
output = output.response_body
|
50
|
+
json_output = output[output.index("{"), output.rindex("}")- (output.index("{")-1)]
|
51
|
+
count = JSON.parse(json_output)["count"].to_i || 0
|
52
|
+
puts "#{@url}\n#{count}" if opts[:v]
|
53
|
+
count
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
82
58
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
59
|
+
def gplus(opts = {})
|
60
|
+
body = [
|
61
|
+
{
|
62
|
+
method: "pos.plusones.get",
|
63
|
+
id: "p",
|
64
|
+
params: {
|
65
|
+
nolog: true,
|
66
|
+
id: @url,
|
67
|
+
source: "widget",
|
68
|
+
userId: "@viewer",
|
69
|
+
groupId: "@self"
|
70
|
+
},
|
71
|
+
jsonrpc: "2.0",
|
72
|
+
key: "p",
|
73
|
+
apiVersion: "v1"
|
74
|
+
}
|
75
|
+
]
|
76
|
+
output = Typhoeus.post(SOCIAL_URLS["gplus"], body: JSON.dump(body), headers: { "content-type" => "application/json", "accept" => "application/json"})
|
77
|
+
count = JSON.parse(output.response_body)[0]["result"]["metadata"]["globalCounts"]["count"].to_i || 0
|
78
|
+
puts "#{@url}\n#{count}" if opts[:v]
|
79
|
+
count
|
80
|
+
end
|
81
|
+
|
82
|
+
def all(opts = {})
|
83
|
+
response = {}
|
84
|
+
SOCIAL_URLS.each do |key, value|
|
85
|
+
response[key] = self.send "#{key}"
|
86
|
+
end
|
87
|
+
puts "#{@url}\n#{response}" if opts[:v]
|
88
|
+
response
|
87
89
|
end
|
88
|
-
puts "#{@url}\n#{response}" if opts[:v]
|
89
|
-
response
|
90
|
-
end
|
91
90
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
def shares_selected(social_networks,opts = {})
|
92
|
+
response = {}
|
93
|
+
social_networks.each do |sn|
|
94
|
+
response[sn] = self.send "#{sn}" unless SOCIAL_URLS[sn].nil? or SOCIAL_URLS[sn] == ""
|
95
|
+
end
|
96
|
+
puts "#{@url}\n#{response}" if opts[:v]
|
97
|
+
response
|
96
98
|
end
|
97
|
-
puts "#{@url}\n#{response}" if opts[:v]
|
98
|
-
response
|
99
99
|
end
|
100
100
|
end
|
data/lib/website.rb
CHANGED
@@ -1,61 +1,27 @@
|
|
1
1
|
require 'webpage'
|
2
2
|
require 'anemone'
|
3
|
-
|
4
|
-
class Website
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
self.class.send(:define_method, "all") {|opts={}| self.shares("all", opts)}
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def shares_selected(social_networks, opts = {})
|
17
|
-
social_networks.each do |sn|
|
18
|
-
instance_variable_set("@#{sn}_count", 0)
|
19
|
-
end
|
20
|
-
output = {}
|
21
|
-
opts[:skip_query_strings] = true
|
22
|
-
Anemone.crawl(@url, opts) do | anemone |
|
23
|
-
anemone.on_every_page do |page|
|
24
|
-
webpage = Webpage.new(page.url.to_s)
|
25
|
-
count = webpage.send("shares_selected",social_networks)
|
26
|
-
print_flag=false
|
27
|
-
count.each do |key,value|
|
28
|
-
print_flag=true if value > 0
|
29
|
-
sum_of_count = instance_variable_get("@#{key}_count") + value
|
30
|
-
instance_variable_set("@#{key}_count", sum_of_count)
|
31
|
-
end
|
32
|
-
puts "#{page.url.to_s}\n#{count}" if print_flag and opts[:v]
|
33
|
-
output[page.url.to_s]=count if print_flag
|
3
|
+
module Totalshares
|
4
|
+
class Website
|
5
|
+
def initialize(url)
|
6
|
+
@url = url
|
7
|
+
@url ="http://#{url}" unless url.start_with? "https://" or url.start_with? "http://"
|
8
|
+
SOCIAL_URLS.each do |key, value|
|
9
|
+
instance_variable_set("@#{key}_count", 0)
|
10
|
+
self.class.send(:define_method, "#{key}") {|opts={}| self.shares(key, opts)}
|
11
|
+
self.class.send(:define_method, "all") {|opts={}| self.shares("all", opts)}
|
34
12
|
end
|
35
13
|
end
|
36
|
-
total=0
|
37
|
-
social_networks.each do |sn|
|
38
|
-
variable_name = "@#{sn}_count"
|
39
|
-
puts "#{sn}: #{instance_variable_get(variable_name)}"
|
40
|
-
total += instance_variable_get(variable_name)
|
41
|
-
end
|
42
|
-
puts "Total Shares: #{total}" if opts[:v]
|
43
|
-
return output, total
|
44
|
-
end
|
45
14
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
count = webpage.send("#{method_name}")
|
57
|
-
|
58
|
-
if method_name.eql?("all")
|
15
|
+
def shares_selected(social_networks, opts = {})
|
16
|
+
social_networks.each do |sn|
|
17
|
+
instance_variable_set("@#{sn}_count", 0)
|
18
|
+
end
|
19
|
+
output = {}
|
20
|
+
opts[:skip_query_strings] = true
|
21
|
+
Anemone.crawl(@url, opts) do | anemone |
|
22
|
+
anemone.on_every_page do |page|
|
23
|
+
webpage = Webpage.new(page.url.to_s)
|
24
|
+
count = webpage.send("shares_selected",social_networks)
|
59
25
|
print_flag=false
|
60
26
|
count.each do |key,value|
|
61
27
|
print_flag=true if value > 0
|
@@ -63,30 +29,64 @@ class Website
|
|
63
29
|
instance_variable_set("@#{key}_count", sum_of_count)
|
64
30
|
end
|
65
31
|
puts "#{page.url.to_s}\n#{count}" if print_flag and opts[:v]
|
66
|
-
output[page.url.to_s]
|
67
|
-
else
|
68
|
-
puts "#{page.url.to_s}\n#{count}" if !(count.eql? 0) and opts[:v]
|
69
|
-
output[page.url.to_s] = count if !(count.eql? 0)
|
70
|
-
|
71
|
-
sum_of_count = instance_variable_get("@#{method_name}_count") + count
|
72
|
-
instance_variable_set("@#{method_name}_count", sum_of_count)
|
32
|
+
output[page.url.to_s]=count if print_flag
|
73
33
|
end
|
74
|
-
|
75
34
|
end
|
76
|
-
end
|
77
|
-
|
78
|
-
if method_name.eql?("all")
|
79
35
|
total=0
|
80
|
-
|
81
|
-
variable_name = "@#{
|
82
|
-
puts "#{
|
36
|
+
social_networks.each do |sn|
|
37
|
+
variable_name = "@#{sn}_count"
|
38
|
+
puts "#{sn}: #{instance_variable_get(variable_name)}"
|
83
39
|
total += instance_variable_get(variable_name)
|
84
40
|
end
|
85
41
|
puts "Total Shares: #{total}" if opts[:v]
|
86
42
|
return output, total
|
87
|
-
|
88
|
-
|
89
|
-
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
def shares(method_name, opts = {})
|
47
|
+
SOCIAL_URLS.each do |key, value|
|
48
|
+
instance_variable_set("@#{key}_count", 0)
|
49
|
+
end
|
50
|
+
output = {}
|
51
|
+
opts[:skip_query_strings] = true
|
52
|
+
Anemone.crawl(@url, opts) do | anemone |
|
53
|
+
anemone.on_every_page do |page|
|
54
|
+
webpage = Webpage.new(page.url.to_s)
|
55
|
+
count = webpage.send("#{method_name}")
|
56
|
+
|
57
|
+
if method_name.eql?("all")
|
58
|
+
print_flag=false
|
59
|
+
count.each do |key,value|
|
60
|
+
print_flag=true if value > 0
|
61
|
+
sum_of_count = instance_variable_get("@#{key}_count") + value
|
62
|
+
instance_variable_set("@#{key}_count", sum_of_count)
|
63
|
+
end
|
64
|
+
puts "#{page.url.to_s}\n#{count}" if print_flag and opts[:v]
|
65
|
+
output[page.url.to_s] = count if print_flag
|
66
|
+
else
|
67
|
+
puts "#{page.url.to_s}\n#{count}" if !(count.eql? 0) and opts[:v]
|
68
|
+
output[page.url.to_s] = count if !(count.eql? 0)
|
69
|
+
|
70
|
+
sum_of_count = instance_variable_get("@#{method_name}_count") + count
|
71
|
+
instance_variable_set("@#{method_name}_count", sum_of_count)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if method_name.eql?("all")
|
78
|
+
total=0
|
79
|
+
SOCIAL_URLS.each do |key, value|
|
80
|
+
variable_name = "@#{key}_count"
|
81
|
+
puts "#{key}: #{instance_variable_get(variable_name)}" if opts[:v]
|
82
|
+
total += instance_variable_get(variable_name)
|
83
|
+
end
|
84
|
+
puts "Total Shares: #{total}" if opts[:v]
|
85
|
+
return output, total
|
86
|
+
else
|
87
|
+
puts "#{method_name}: #{instance_variable_get("@#{method_name}_count")}" if opts[:v]
|
88
|
+
return output, instance_variable_get("@#{method_name}_count")
|
89
|
+
end
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|