social_shares 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -6
- data/lib/social_shares.rb +34 -3
- data/lib/social_shares/base.rb +7 -0
- data/lib/social_shares/facebook.rb +1 -1
- data/lib/social_shares/google.rb +2 -2
- data/lib/social_shares/linkedin.rb +14 -0
- data/lib/social_shares/mail_ru.rb +1 -1
- data/lib/social_shares/odnoklassniki.rb +1 -1
- data/lib/social_shares/pinterest.rb +14 -0
- data/lib/social_shares/reddit.rb +15 -0
- data/lib/social_shares/stumbleupon.rb +14 -0
- data/lib/social_shares/twitter.rb +1 -1
- data/lib/social_shares/version.rb +1 -1
- data/lib/social_shares/vkontakte.rb +1 -1
- data/social_shares.gemspec +1 -1
- metadata +32 -17
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -6,30 +6,44 @@ Supported networks:
|
|
6
6
|
* [facebook](http://www.facebook.com/)
|
7
7
|
* [google plus](https://plus.google.com)
|
8
8
|
* [twitter](https://twitter.com/)
|
9
|
+
* [reddit](http://www.reddit.com/)
|
10
|
+
* [linkedin](https://www.linkedin.com/)
|
11
|
+
* [pinterest](http://www.pinterest.com/)
|
12
|
+
* [stumbleupon](http://www.stumbleupon.com/)
|
9
13
|
* [vkontakte](http://vkontakte.ru/)
|
10
14
|
* [mail.ru](http://mail.ru/)
|
11
15
|
* [odnoklassniki](http://www.odnoklassniki.ru/)
|
12
16
|
|
13
17
|
Usage
|
14
18
|
-----
|
15
|
-
Currently all methods can raise exception when there is any error with network access.
|
16
19
|
```ruby
|
17
20
|
:000 > require 'social_shares'
|
18
21
|
=> true
|
19
22
|
:000 > SocialShares.supported_networks
|
20
|
-
=> [:vkontakte, :facebook, :google, :twitter, :mail_ru, :odnoklassniki]
|
23
|
+
=> [:vkontakte, :facebook, :google, :twitter, :mail_ru, :odnoklassniki, :reddit, :linkedin, :pinterest, :stumbleupon]
|
21
24
|
:000 > url = 'http://www.apple.com/'
|
22
|
-
=> "
|
25
|
+
=> "http://www.apple.com/"
|
23
26
|
:000 > SocialShares.facebook url
|
24
27
|
=> 394927
|
25
28
|
:000 > SocialShares.google url
|
26
29
|
=> 28289
|
27
30
|
:000 > SocialShares.twitter url
|
28
31
|
=> 1164675
|
32
|
+
# in case of exception it will return nil value
|
33
|
+
:000 > SocialShares.twitter url
|
34
|
+
=> nil
|
35
|
+
# but this method will raise it
|
36
|
+
:000 > SocialShares.twitter! url
|
37
|
+
=> RestClient::RequestTimeout: Request Timeout
|
29
38
|
:000 > SocialShares.all url
|
30
|
-
=> {:vkontakte=>
|
31
|
-
|
32
|
-
|
39
|
+
=> {:vkontakte=>44, :facebook=>399027, :google=>28346, :twitter=>1836, :mail_ru=>37, :odnoklassniki=>1, :reddit=>2361, :linkedin=>nil, :pinterest=>21011, :stumbleupon=>43035}
|
40
|
+
# same for #all! method, it will not handle exceptions
|
41
|
+
:000 > SocialShares.all! url
|
42
|
+
=> RestClient::RequestTimeout: Request Timeout
|
43
|
+
:000 > SocialShares.selected url, %w(facebook google linkedin)
|
44
|
+
=> {:facebook=>394927, :google=>28289, :linkedin=>nil}
|
45
|
+
:000 > SocialShares.selected! url, %w(facebook google linkedin)
|
46
|
+
=> RestClient::RequestTimeout: Request Timeout
|
33
47
|
# Total sum of sharings in selected networks
|
34
48
|
:000 > SocialShares.total url, %w(facebook google)
|
35
49
|
=> 423216
|
data/lib/social_shares.rb
CHANGED
@@ -8,10 +8,25 @@ require 'social_shares/twitter'
|
|
8
8
|
require 'social_shares/vkontakte'
|
9
9
|
require 'social_shares/mail_ru'
|
10
10
|
require 'social_shares/odnoklassniki'
|
11
|
+
require 'social_shares/reddit'
|
12
|
+
require 'social_shares/linkedin'
|
13
|
+
require 'social_shares/pinterest'
|
14
|
+
require 'social_shares/stumbleupon'
|
11
15
|
|
12
16
|
module SocialShares
|
13
17
|
class << self
|
14
|
-
SUPPORTED_NETWORKS = [
|
18
|
+
SUPPORTED_NETWORKS = [
|
19
|
+
:vkontakte,
|
20
|
+
:facebook,
|
21
|
+
:google,
|
22
|
+
:twitter,
|
23
|
+
:mail_ru,
|
24
|
+
:odnoklassniki,
|
25
|
+
:reddit,
|
26
|
+
:linkedin,
|
27
|
+
:pinterest,
|
28
|
+
:stumbleupon
|
29
|
+
]
|
15
30
|
|
16
31
|
def supported_networks
|
17
32
|
SUPPORTED_NETWORKS
|
@@ -22,6 +37,11 @@ module SocialShares
|
|
22
37
|
class_name = network_name.to_s.split('_').map(&:capitalize).join
|
23
38
|
SocialShares.const_get(class_name).new(url).shares
|
24
39
|
end
|
40
|
+
|
41
|
+
define_method("#{network_name}!") do |url|
|
42
|
+
class_name = network_name.to_s.split('_').map(&:capitalize).join
|
43
|
+
SocialShares.const_get(class_name).new(url).shares!
|
44
|
+
end
|
25
45
|
end
|
26
46
|
|
27
47
|
def selected(url, selected_networks)
|
@@ -31,16 +51,27 @@ module SocialShares
|
|
31
51
|
end
|
32
52
|
end
|
33
53
|
|
54
|
+
def selected!(url, selected_networks)
|
55
|
+
filtered_networks(selected_networks).inject({}) do |result, network_name|
|
56
|
+
result[network_name] = self.send("#{network_name}!", url)
|
57
|
+
result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
34
61
|
def all(url)
|
35
62
|
selected(url, SUPPORTED_NETWORKS)
|
36
63
|
end
|
37
64
|
|
65
|
+
def all!(url)
|
66
|
+
selected!(url, SUPPORTED_NETWORKS)
|
67
|
+
end
|
68
|
+
|
38
69
|
def total(url, selected_networks = SUPPORTED_NETWORKS)
|
39
|
-
selected(url, selected_networks).values.reduce(:+)
|
70
|
+
selected!(url, selected_networks).values.reduce(:+)
|
40
71
|
end
|
41
72
|
|
42
73
|
def has_any?(url, selected_networks = SUPPORTED_NETWORKS)
|
43
|
-
!filtered_networks(selected_networks).find{|n| self.send(n, url) > 0}.nil?
|
74
|
+
!filtered_networks(selected_networks).find{|n| self.send("#{n}!", url) > 0}.nil?
|
44
75
|
end
|
45
76
|
|
46
77
|
private
|
data/lib/social_shares/base.rb
CHANGED
data/lib/social_shares/google.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module SocialShares
|
2
2
|
class Google < Base
|
3
|
-
def shares
|
4
|
-
response = RestClient.post(url,
|
3
|
+
def shares!
|
4
|
+
response = RestClient.post(url, JSON.dump(params), content_type: :json, accept: :json)
|
5
5
|
JSON.parse(response)[0]["result"]["metadata"]["globalCounts"]["count"].to_i
|
6
6
|
end
|
7
7
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SocialShares
|
2
|
+
class Linkedin < Base
|
3
|
+
def shares!
|
4
|
+
response = RestClient.get(url)
|
5
|
+
JSON.parse(response)['count']
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def url
|
11
|
+
"http://www.linkedin.com/countserv/count/share?format=json&url=#{checked_url}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SocialShares
|
2
|
+
class Pinterest < Base
|
3
|
+
def shares!
|
4
|
+
response = RestClient.get(url)
|
5
|
+
/count":(\d+)/.match(response)[-1].to_i
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def url
|
11
|
+
"http://api.pinterest.com/v1/urls/count.json?url=#{checked_url}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SocialShares
|
2
|
+
class Reddit < Base
|
3
|
+
def shares!
|
4
|
+
response = RestClient.get(url)
|
5
|
+
children_data = JSON.parse(response)['data']['children']
|
6
|
+
children_data.map{|c| c['data']['score']}.reduce(:+) || 0
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def url
|
12
|
+
"http://www.reddit.com/api/info.json?url=#{checked_url}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SocialShares
|
2
|
+
class Stumbleupon < Base
|
3
|
+
def shares!
|
4
|
+
response = RestClient.get(url)
|
5
|
+
JSON.parse(response)['result']['views'] || 0
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def url
|
11
|
+
"http://www.stumbleupon.com/services/1.01/badge.getinfo?url=#{checked_url}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/social_shares.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Timur Kozmenko']
|
10
10
|
spec.email = ['timraell@gmail.com']
|
11
11
|
spec.summary = %q{Check how many times url was shared in social networks.}
|
12
|
-
spec.description = %q{Check how many times url was shared in social networks.}
|
12
|
+
spec.description = %q{Check how many times url was shared in social networks, e.g. share counts.}
|
13
13
|
spec.homepage = 'https://github.com/Timrael/social_shares'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
metadata
CHANGED
@@ -1,79 +1,88 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_shares
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Timur Kozmenko
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rest-client
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: json
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- -
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '0'
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- -
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: bundler
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '1.6'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '1.6'
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: rake
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
|
-
- -
|
67
|
+
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
61
69
|
version: '0'
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
|
-
- -
|
75
|
+
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '0'
|
69
|
-
description: Check how many times url was shared in social networks.
|
78
|
+
description: Check how many times url was shared in social networks, e.g. share counts.
|
70
79
|
email:
|
71
80
|
- timraell@gmail.com
|
72
81
|
executables: []
|
73
82
|
extensions: []
|
74
83
|
extra_rdoc_files: []
|
75
84
|
files:
|
76
|
-
-
|
85
|
+
- .gitignore
|
77
86
|
- Gemfile
|
78
87
|
- LICENSE.txt
|
79
88
|
- README.md
|
@@ -82,8 +91,12 @@ files:
|
|
82
91
|
- lib/social_shares/base.rb
|
83
92
|
- lib/social_shares/facebook.rb
|
84
93
|
- lib/social_shares/google.rb
|
94
|
+
- lib/social_shares/linkedin.rb
|
85
95
|
- lib/social_shares/mail_ru.rb
|
86
96
|
- lib/social_shares/odnoklassniki.rb
|
97
|
+
- lib/social_shares/pinterest.rb
|
98
|
+
- lib/social_shares/reddit.rb
|
99
|
+
- lib/social_shares/stumbleupon.rb
|
87
100
|
- lib/social_shares/twitter.rb
|
88
101
|
- lib/social_shares/version.rb
|
89
102
|
- lib/social_shares/vkontakte.rb
|
@@ -91,25 +104,27 @@ files:
|
|
91
104
|
homepage: https://github.com/Timrael/social_shares
|
92
105
|
licenses:
|
93
106
|
- MIT
|
94
|
-
metadata: {}
|
95
107
|
post_install_message:
|
96
108
|
rdoc_options: []
|
97
109
|
require_paths:
|
98
110
|
- lib
|
99
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
100
113
|
requirements:
|
101
|
-
- -
|
114
|
+
- - ! '>='
|
102
115
|
- !ruby/object:Gem::Version
|
103
116
|
version: '0'
|
104
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
105
119
|
requirements:
|
106
|
-
- -
|
120
|
+
- - ! '>='
|
107
121
|
- !ruby/object:Gem::Version
|
108
122
|
version: '0'
|
109
123
|
requirements: []
|
110
124
|
rubyforge_project:
|
111
|
-
rubygems_version:
|
125
|
+
rubygems_version: 1.8.25
|
112
126
|
signing_key:
|
113
|
-
specification_version:
|
127
|
+
specification_version: 3
|
114
128
|
summary: Check how many times url was shared in social networks.
|
115
129
|
test_files: []
|
130
|
+
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 27877d5ac4dc67febe1d05033a50c25649cc5232
|
4
|
-
data.tar.gz: b0365e412ee96188a36c57135a19d62bb6dd99a2
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 52c3e2cc8cbfe5fb9350a6abdb51cee0cc43e4a65d1bb12b02b8560cf5c4fae64fffa1d242fa1a3728829bbbdd3bfe0f748787b40911cac6d5daaad6bf47f8d5
|
7
|
-
data.tar.gz: d8a61a63e2a4cb5aa1192c0d77ca2905c6c99e720361ba428da411c216f272d3720e4751deb1a490669e2ccf79ee64ed03ec5a86f20b7c8e7f3644873fce7129
|