social_shares 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3dc59d3b27ca52593a5640de7644553809b04c28
4
- data.tar.gz: 0dce44440e73dbf90c362d5e99fc4c4e143199d7
3
+ metadata.gz: 6259f93a09c15854ac52f03b32136de946a88c03
4
+ data.tar.gz: 07a079f3f62a5018a2a2adca0f46436b7bb45263
5
5
  SHA512:
6
- metadata.gz: 20a1613a06450ef62ad2b504f0fd84653c97d769fb12663a70a399e517f3c35b6882e8daac00a5e880c1809197511975e64e7c96f0d933939f51d1aa28b03bc2
7
- data.tar.gz: 0708c973883b1f4aa6249333b3a8f52922d548ebc2a1e1aebf4473d4b52636ccb2b772d4818a2e802f9397c3eb11a85bf28c424e60218b994530e3e90add619b
6
+ metadata.gz: 75406f65e084f2857ae45bc3729787dcdf7747a3678792268769217a94d0034ce7d58816d13965a2ac6224faea4afa477f35858b9c0def0f4ce3f1c44248d874
7
+ data.tar.gz: 846320f4af49eeda570a735e21db14a8b323b8f7da7ed2e633b40354c3275bd7dddcfeba8733934b3fe9620fb6d8c7ccd131d84f40ad8524b7d728a0bf5dcf3e
data/.gitignore CHANGED
@@ -27,7 +27,7 @@ build/
27
27
  # for a library or gem, you might want to ignore these files since the code is
28
28
  # intended to run in multiple environments; otherwise, check them in:
29
29
  Gemfile.lock
30
- # .ruby-version
30
+ .ruby-version
31
31
  # .ruby-gemset
32
32
 
33
33
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  Social Shares
2
2
  =============
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/social_shares.svg)](http://badge.fury.io/rb/social_shares)
5
+
3
6
  Social shares is intended to easily check social sharings of an url.
4
7
 
5
8
  Supported networks
@@ -1,14 +1,10 @@
1
1
  module SocialShares
2
2
  class Buffer < Base
3
+ URL = 'https://api.bufferapp.com/1/links/shares.json'
4
+
3
5
  def shares!
4
- response = RestClient.get(url)
6
+ response = RestClient.get(URL, {:params => {:url => checked_url}})
5
7
  JSON.parse(response)['shares']
6
8
  end
7
-
8
- private
9
-
10
- def url
11
- "https://api.bufferapp.com/1/links/shares.json?url=#{checked_url}"
12
- end
13
9
  end
14
10
  end
@@ -1,14 +1,17 @@
1
1
  module SocialShares
2
2
  class Facebook < Base
3
- def shares!
4
- response = RestClient.get(url)
5
- JSON.parse(response)["shares"] || 0
6
- end
3
+ URL = 'http://api.ak.facebook.com/restserver.php'
7
4
 
8
- private
9
-
10
- def url
11
- "http://graph.facebook.com/?id=#{checked_url}"
5
+ def shares!
6
+ response = RestClient.get(URL, {
7
+ :params => {
8
+ :urls => checked_url,
9
+ :v => '1.0',
10
+ :method => 'links.getStats',
11
+ :format => 'json'
12
+ }
13
+ })
14
+ JSON.parse(response)[0]['share_count'] || 0
12
15
  end
13
16
  end
14
17
  end
@@ -1,16 +1,14 @@
1
1
  module SocialShares
2
2
  class Google < Base
3
+ URL = 'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ'
4
+
3
5
  def shares!
4
- response = RestClient.post(url, JSON.dump(params), content_type: :json, accept: :json)
5
- JSON.parse(response)[0]["result"]["metadata"]["globalCounts"]["count"].to_i
6
+ response = RestClient.post(URL, JSON.dump(params), content_type: :json, accept: :json)
7
+ JSON.parse(response)[0]['result']['metadata']['globalCounts']['count'].to_i
6
8
  end
7
9
 
8
10
  private
9
11
 
10
- def url
11
- "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ"
12
- end
13
-
14
12
  def params
15
13
  [{
16
14
  'method' => 'pos.plusones.get',
@@ -1,14 +1,15 @@
1
1
  module SocialShares
2
2
  class Linkedin < Base
3
+ URL = 'http://www.linkedin.com/countserv/count/share'
4
+
3
5
  def shares!
4
- response = RestClient.get(url)
6
+ response = RestClient.get(URL, {
7
+ :params => {
8
+ :url => checked_url,
9
+ :format => 'json'
10
+ }
11
+ })
5
12
  JSON.parse(response)['count']
6
13
  end
7
-
8
- private
9
-
10
- def url
11
- "http://www.linkedin.com/countserv/count/share?format=json&url=#{checked_url}"
12
- end
13
14
  end
14
15
  end
@@ -1,7 +1,7 @@
1
1
  module SocialShares
2
2
  class MailRu < Base
3
3
  def shares!
4
- response["share_mm"].to_i
4
+ response['share_mm'].to_i
5
5
  end
6
6
 
7
7
  protected
@@ -1,7 +1,7 @@
1
1
  module SocialShares
2
2
  class Odnoklassniki < MailRu
3
3
  def shares!
4
- response["share_ok"].to_i
4
+ response['share_ok'].to_i
5
5
  end
6
6
  end
7
7
  end
@@ -1,14 +1,10 @@
1
1
  module SocialShares
2
2
  class Pinterest < Base
3
+ URL = 'http://api.pinterest.com/v1/urls/count.json'
4
+
3
5
  def shares!
4
- response = RestClient.get(url)
6
+ response = RestClient.get(URL, {:params => {:url => checked_url}})
5
7
  /count":(\d+)/.match(response)[-1].to_i
6
8
  end
7
-
8
- private
9
-
10
- def url
11
- "http://api.pinterest.com/v1/urls/count.json?url=#{checked_url}"
12
- end
13
9
  end
14
10
  end
@@ -1,15 +1,11 @@
1
1
  module SocialShares
2
2
  class Reddit < Base
3
+ URL = 'http://www.reddit.com/api/info.json'
4
+
3
5
  def shares!
4
- response = RestClient.get(url)
6
+ response = RestClient.get(URL, {:params => {:url => checked_url}})
5
7
  children_data = JSON.parse(response)['data']['children']
6
8
  children_data.map{|c| c['data']['score']}.reduce(:+) || 0
7
9
  end
8
-
9
- private
10
-
11
- def url
12
- "http://www.reddit.com/api/info.json?url=#{checked_url}"
13
- end
14
10
  end
15
11
  end
@@ -1,14 +1,10 @@
1
1
  module SocialShares
2
2
  class Stumbleupon < Base
3
+ URL = 'http://www.stumbleupon.com/services/1.01/badge.getinfo'
4
+
3
5
  def shares!
4
- response = RestClient.get(url)
6
+ response = RestClient.get(URL, {:params => {:url => checked_url}})
5
7
  JSON.parse(response)['result']['views'] || 0
6
8
  end
7
-
8
- private
9
-
10
- def url
11
- "http://www.stumbleupon.com/services/1.01/badge.getinfo?url=#{checked_url}"
12
- end
13
9
  end
14
10
  end
@@ -1,14 +1,10 @@
1
1
  module SocialShares
2
2
  class Twitter < Base
3
- def shares!
4
- response = RestClient.get(url)
5
- JSON.parse(response)["count"]
6
- end
3
+ URL = 'http://cdn.api.twitter.com/1/urls/count.json'
7
4
 
8
- private
9
-
10
- def url
11
- "http://cdn.api.twitter.com/1/urls/count.json?url=#{checked_url}"
5
+ def shares!
6
+ response = RestClient.get(URL, {:params => {:url => checked_url}})
7
+ JSON.parse(response)['count']
12
8
  end
13
9
  end
14
10
  end
@@ -1,3 +1,3 @@
1
1
  module SocialShares
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -1,14 +1,16 @@
1
1
  module SocialShares
2
2
  class Vkontakte < Base
3
+ URL = 'http://vk.com/share.php'
4
+
3
5
  def shares!
4
- response = RestClient.get(url)
6
+ response = RestClient.get(URL, {
7
+ :params => {
8
+ :act => 'count',
9
+ :index => 1,
10
+ :url => checked_url,
11
+ }
12
+ })
5
13
  /VK.Share.count\(1,\s(\d+)\)/.match(response)[1].to_i
6
14
  end
7
-
8
- private
9
-
10
- def url
11
- "http://vk.com/share.php?act=count&index=1&url=#{checked_url}"
12
- end
13
15
  end
14
16
  end
@@ -1,23 +1,30 @@
1
1
  module SocialShares
2
2
  class Weibo < Base
3
+ URL_FOR_SHORT = 'https://api.weibo.com/2/short_url/shorten.json'
4
+ URL_FOR_SHARE = 'https://api.weibo.com/2/short_url/share/counts.json'
5
+
3
6
  def shares!
4
- response = RestClient.get(url_for_share)
7
+ response = RestClient.get(URL_FOR_SHARE, {
8
+ :params => {
9
+ :_ => '1414437609900',
10
+ :source => '8003029170',
11
+ :url_short => short_url
12
+ }
13
+ })
5
14
  JSON.parse(response)['urls'].first['share_counts'].to_i
6
15
  end
7
16
 
8
17
  private
9
18
 
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
19
  def short_url
15
- response = RestClient.get(url_for_short)
20
+ response = RestClient.get(URL_FOR_SHORT, {
21
+ :params => {
22
+ :_ => '1414437609673',
23
+ :source => '8003029170',
24
+ :url_long => checked_url
25
+ }
26
+ })
16
27
  JSON.parse(response)['urls'].first['url_short']
17
28
  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
29
  end
23
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_shares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timur Kozmenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client