social_shares 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +74 -10
- data/lib/social_shares/buffer.rb +14 -0
- data/lib/social_shares/version.rb +1 -1
- data/lib/social_shares/weibo.rb +23 -0
- data/lib/social_shares.rb +5 -1
- metadata +18 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b30b6f300dea16a77d0c94336c2d6d702db679f
|
4
|
+
data.tar.gz: 6a66438d21a2ed96e9edb06c8b9993c6358407e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7382f31c5ecea6af8b42a229ab6eb7e94d637304737cc32b4c314f94dc1ecd1a2b487d7df14d3c68066671a90056497f094485643296123e33186c7cc1a418a
|
7
|
+
data.tar.gz: 0d2572ae7a55547f5958153765f7d49abe2d430a5c66b537b48eb498757e1f4d5696966ea2341edc1e858c684e4d21888068ceb062f7721289e671a2e7c96457
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@ Social Shares
|
|
2
2
|
=============
|
3
3
|
Social shares is intended to easily check social sharings of an url.
|
4
4
|
|
5
|
-
Supported networks
|
5
|
+
Supported networks
|
6
|
+
------
|
7
|
+
International:
|
6
8
|
* [facebook](http://www.facebook.com/)
|
7
9
|
* [google plus](https://plus.google.com)
|
8
10
|
* [twitter](https://twitter.com/)
|
@@ -10,53 +12,89 @@ Supported networks:
|
|
10
12
|
* [linkedin](https://www.linkedin.com/)
|
11
13
|
* [pinterest](http://www.pinterest.com/)
|
12
14
|
* [stumbleupon](http://www.stumbleupon.com/)
|
15
|
+
* [buffer](https://bufferapp.com/)
|
16
|
+
|
17
|
+
Russian:
|
13
18
|
* [vkontakte](http://vkontakte.ru/)
|
14
19
|
* [mail.ru](http://mail.ru/)
|
15
20
|
* [odnoklassniki](http://www.odnoklassniki.ru/)
|
16
21
|
|
17
|
-
|
22
|
+
Chinese:
|
23
|
+
* [weibo](http://www.weibo.com)
|
24
|
+
|
25
|
+
Basic usage
|
18
26
|
-----
|
19
27
|
```ruby
|
20
28
|
:000 > require 'social_shares'
|
21
29
|
=> true
|
22
|
-
|
23
|
-
=> [:vkontakte, :facebook, :google, :twitter, :mail_ru, :odnoklassniki, :reddit, :linkedin, :pinterest, :stumbleupon]
|
30
|
+
|
24
31
|
:000 > url = 'http://www.apple.com/'
|
25
32
|
=> "http://www.apple.com/"
|
33
|
+
|
26
34
|
:000 > SocialShares.facebook url
|
27
35
|
=> 394927
|
36
|
+
|
28
37
|
:000 > SocialShares.google url
|
29
38
|
=> 28289
|
39
|
+
|
30
40
|
:000 > SocialShares.twitter url
|
31
41
|
=> 1164675
|
32
|
-
|
42
|
+
```
|
43
|
+
In case of exception:
|
44
|
+
```ruby
|
33
45
|
:000 > SocialShares.twitter url
|
34
46
|
=> nil
|
35
|
-
|
47
|
+
|
36
48
|
:000 > SocialShares.twitter! url
|
37
49
|
=> RestClient::RequestTimeout: Request Timeout
|
50
|
+
```
|
51
|
+
|
52
|
+
Advanced usage
|
53
|
+
-----
|
54
|
+
List of all supported networks:
|
55
|
+
```ruby
|
56
|
+
:000 > SocialShares.supported_networks
|
57
|
+
=> [:vkontakte, :facebook, :google, :twitter, :mail_ru, :odnoklassniki, :reddit, :linkedin, :pinterest, :stumbleupon, :buffer]
|
58
|
+
```
|
59
|
+
|
60
|
+
Fetch all shares by one method (#all, #all!):
|
61
|
+
```ruby
|
62
|
+
# in case of exception it will return nil
|
38
63
|
:000 > SocialShares.all url
|
39
|
-
=> {:vkontakte=>
|
40
|
-
|
64
|
+
=> {:vkontakte=>nil, :facebook=>399027, :google=>28346, :twitter=>1836, :mail_ru=>37, :odnoklassniki=>1, :reddit=>2361, :linkedin=>33, :pinterest=>21011, :stumbleupon=>43035, :weibo=>12760, :buffer=>1662}
|
65
|
+
|
66
|
+
# and this will raise it
|
41
67
|
:000 > SocialShares.all! url
|
42
68
|
=> RestClient::RequestTimeout: Request Timeout
|
69
|
+
```
|
70
|
+
|
71
|
+
Fetch shares of selected networks(#selected, #selected!):
|
72
|
+
```ruby
|
43
73
|
:000 > SocialShares.selected url, %w(facebook google linkedin)
|
44
74
|
=> {:facebook=>394927, :google=>28289, :linkedin=>nil}
|
75
|
+
|
76
|
+
# same here
|
45
77
|
:000 > SocialShares.selected! url, %w(facebook google linkedin)
|
46
78
|
=> RestClient::RequestTimeout: Request Timeout
|
47
|
-
|
79
|
+
```
|
80
|
+
Total sum of sharings in selected networks:
|
81
|
+
```ruby
|
48
82
|
:000 > SocialShares.total url, %w(facebook google)
|
49
83
|
=> 423216
|
84
|
+
|
50
85
|
# Second arg is optional, by default it takes all networks
|
51
86
|
:000 > SocialShares.total url
|
52
87
|
=> 1631102
|
53
|
-
|
88
|
+
```
|
89
|
+
Does any network have at least one link?
|
90
|
+
```ruby
|
54
91
|
:000 > SocialShares.has_any? url, %w(facebook google)
|
55
92
|
=> true
|
56
93
|
# Second arg is optional, by default it takes all networks
|
57
94
|
:000 > SocialShares.has_any? url
|
58
95
|
=> true
|
59
96
|
```
|
97
|
+
Note that #has_any? is faster than (#total > 0), because it stops on first network that has at least 1 sharing
|
60
98
|
|
61
99
|
Instalation
|
62
100
|
-----
|
@@ -65,6 +103,32 @@ Include the gem in your Gemfile:
|
|
65
103
|
gem 'social_shares'
|
66
104
|
```
|
67
105
|
|
106
|
+
Contributing
|
107
|
+
-----
|
108
|
+
* Create provider class in lib/social_shares/foo.rb with method #shares!, that return Integer value. #checked_url is accessed attribute.
|
109
|
+
```ruby
|
110
|
+
module SocialShares
|
111
|
+
class Foo < Base
|
112
|
+
def shares!
|
113
|
+
response = RestClient.get(url)
|
114
|
+
JSON.parse(response)["shares"] || 0
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def url
|
120
|
+
"http://foo.com/?url=#{checked_url}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
```
|
125
|
+
* Add it to lib/social_shares.rb
|
126
|
+
```
|
127
|
+
require 'social_shares/foo'
|
128
|
+
SUPPORTED_NETWORKS = [:foo, :vkontakte, :facebook]
|
129
|
+
```
|
130
|
+
* Update README: add link to list, possible answer in #all method, etc.
|
131
|
+
|
68
132
|
Authors
|
69
133
|
----
|
70
134
|
* [Timur Kozmenko](https://twitter.com/Timrael)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SocialShares
|
2
|
+
class Weibo < Base
|
3
|
+
def shares!
|
4
|
+
response = RestClient.get(url_for_share)
|
5
|
+
JSON.parse(response)['urls'].first['share_counts'].to_i
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def url_for_short
|
11
|
+
"https://api.weibo.com/2/short_url/shorten.json?_=1414437609673&source=8003029170&url_long=#{checked_url}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def short_url
|
15
|
+
response = RestClient.get(url_for_short)
|
16
|
+
JSON.parse(response)['urls'].first['url_short']
|
17
|
+
end
|
18
|
+
|
19
|
+
def url_for_share
|
20
|
+
"https://api.weibo.com/2/short_url/share/counts.json?_=1414437609900&source=8003029170&url_short=#{short_url}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/social_shares.rb
CHANGED
@@ -12,6 +12,8 @@ require 'social_shares/reddit'
|
|
12
12
|
require 'social_shares/linkedin'
|
13
13
|
require 'social_shares/pinterest'
|
14
14
|
require 'social_shares/stumbleupon'
|
15
|
+
require 'social_shares/weibo'
|
16
|
+
require 'social_shares/buffer'
|
15
17
|
|
16
18
|
module SocialShares
|
17
19
|
class << self
|
@@ -25,7 +27,9 @@ module SocialShares
|
|
25
27
|
:reddit,
|
26
28
|
:linkedin,
|
27
29
|
:pinterest,
|
28
|
-
:stumbleupon
|
30
|
+
:stumbleupon,
|
31
|
+
:weibo,
|
32
|
+
:buffer,
|
29
33
|
]
|
30
34
|
|
31
35
|
def supported_networks
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_shares
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Timur Kozmenko
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rest-client
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: json
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: bundler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '1.6'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '1.6'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Check how many times url was shared in social networks, e.g. share counts.
|
@@ -82,13 +73,14 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
86
77
|
- Gemfile
|
87
78
|
- LICENSE.txt
|
88
79
|
- README.md
|
89
80
|
- Rakefile
|
90
81
|
- lib/social_shares.rb
|
91
82
|
- lib/social_shares/base.rb
|
83
|
+
- lib/social_shares/buffer.rb
|
92
84
|
- lib/social_shares/facebook.rb
|
93
85
|
- lib/social_shares/google.rb
|
94
86
|
- lib/social_shares/linkedin.rb
|
@@ -100,31 +92,30 @@ files:
|
|
100
92
|
- lib/social_shares/twitter.rb
|
101
93
|
- lib/social_shares/version.rb
|
102
94
|
- lib/social_shares/vkontakte.rb
|
95
|
+
- lib/social_shares/weibo.rb
|
103
96
|
- social_shares.gemspec
|
104
97
|
homepage: https://github.com/Timrael/social_shares
|
105
98
|
licenses:
|
106
99
|
- MIT
|
100
|
+
metadata: {}
|
107
101
|
post_install_message:
|
108
102
|
rdoc_options: []
|
109
103
|
require_paths:
|
110
104
|
- lib
|
111
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
-
none: false
|
113
106
|
requirements:
|
114
|
-
- -
|
107
|
+
- - ">="
|
115
108
|
- !ruby/object:Gem::Version
|
116
109
|
version: '0'
|
117
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
111
|
requirements:
|
120
|
-
- -
|
112
|
+
- - ">="
|
121
113
|
- !ruby/object:Gem::Version
|
122
114
|
version: '0'
|
123
115
|
requirements: []
|
124
116
|
rubyforge_project:
|
125
|
-
rubygems_version:
|
117
|
+
rubygems_version: 2.4.2
|
126
118
|
signing_key:
|
127
|
-
specification_version:
|
119
|
+
specification_version: 4
|
128
120
|
summary: Check how many times url was shared in social networks.
|
129
121
|
test_files: []
|
130
|
-
has_rdoc:
|