social_shares 0.2.5 → 0.2.6

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: a746652fc7359c73e9f10aca8c6dd097ff7fc7a1
4
- data.tar.gz: 4b21b5c56dcf8f46eedc336d685092ce86847a59
3
+ metadata.gz: ac452383ad77f378be0ab45a1ead8cafe764f972
4
+ data.tar.gz: 388b9c0acf70dbff458e46e152bfb1d6ab704b10
5
5
  SHA512:
6
- metadata.gz: eb2d7b8e536dc714235a46ec871346279543fd33645144c7b4117237d8b0e5314f147c51209c1ed6c683ea0e59e4318304d91d8acba9aa052e816c9ff8b9519b
7
- data.tar.gz: be4340ccf79e4938f1855f237657d82417e5cfa2eb864c4e42871dea74bde955c50d3c2b413f78a40037c43a2906561b4772205cd94dd7346247e5904eb11e0c
6
+ metadata.gz: 2a384748962c9475047680cd905173e9e1878bb09d466097c2d53fcfe25b083a1cbe4c74eaff74f38bbfbacfe8baed57b878c8f2e2da127dcfd598035e3087a6
7
+ data.tar.gz: 68d85137a99cc78b5a3c1c85a6c00d20d4f70d16cd69a0e61a0987e63f722fa6068b3359df04307224c92ddf2577feae825f82fd69d6673f7c8e5dd7f7e85c03
@@ -1,5 +1,6 @@
1
1
  module SocialShares
2
2
  class Base
3
+ TIMEOUT = OPEN_TIMEOUT = 3
3
4
  attr_accessor :checked_url
4
5
 
5
6
  def initialize(checked_url)
@@ -14,6 +15,14 @@ module SocialShares
14
15
  nil
15
16
  end
16
17
 
18
+ def get(url, params)
19
+ RestClient::Resource.new(url, timeout: TIMEOUT, open_timeout: OPEN_TIMEOUT).get(params)
20
+ end
21
+
22
+ def post(url, params, headers = {})
23
+ RestClient::Resource.new(url, timeout: TIMEOUT, open_timeout: OPEN_TIMEOUT).post(params, headers)
24
+ end
25
+
17
26
  def shares!
18
27
  raise NotImplementedError
19
28
  end
@@ -3,7 +3,7 @@ module SocialShares
3
3
  URL = 'https://api.bufferapp.com/1/links/shares.json'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {:params => {:url => checked_url}})
6
+ response = get(URL, {:params => {:url => checked_url}})
7
7
  JSON.parse(response)['shares']
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module SocialShares
3
3
  URL = 'https://graph.facebook.com/fql'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {
6
+ response = get(URL, {
7
7
  :params => {
8
8
  :q => "SELECT share_count FROM link_stat WHERE url='#{checked_url}'"
9
9
  }
@@ -3,7 +3,7 @@ module SocialShares
3
3
  URL = 'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ'
4
4
 
5
5
  def shares!
6
- response = RestClient.post(URL, JSON.dump(params), content_type: :json, accept: :json)
6
+ response = post(URL, JSON.dump(params), {content_type: :json, accept: :json})
7
7
  JSON.parse(response)[0]['result']['metadata']['globalCounts']['count'].to_i
8
8
  end
9
9
 
@@ -3,12 +3,12 @@ module SocialShares
3
3
  URL = 'http://www.linkedin.com/countserv/count/share'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {
7
- :params => {
8
- :url => checked_url,
9
- :format => 'json'
10
- }
11
- })
6
+ response = get(URL, {
7
+ :params => {
8
+ :url => checked_url,
9
+ :format => 'json'
10
+ }
11
+ })
12
12
  JSON.parse(response)['count']
13
13
  end
14
14
  end
@@ -3,7 +3,7 @@ module SocialShares
3
3
  URL = 'https://connect.mail.ru/share_count'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {
6
+ response = get(URL, {
7
7
  params: {
8
8
  func: 'foo',
9
9
  callback: 1,
@@ -3,7 +3,7 @@ module SocialShares
3
3
  URL = 'http://api.pinterest.com/v1/urls/count.json'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {:params => {:url => checked_url}})
6
+ response = get(URL, {:params => {:url => checked_url}})
7
7
  /count":(\d+)/.match(response)[-1].to_i
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module SocialShares
3
3
  URL = 'http://www.reddit.com/api/info.json'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {:params => {:url => checked_url}})
6
+ response = get(URL, {:params => {:url => checked_url}})
7
7
  children_data = JSON.parse(response)['data']['children']
8
8
  children_data.map{|c| c['data']['score']}.reduce(:+) || 0
9
9
  end
@@ -3,7 +3,7 @@ module SocialShares
3
3
  URL = 'http://www.stumbleupon.com/services/1.01/badge.getinfo'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {:params => {:url => checked_url}})
6
+ response = get(URL, {:params => {:url => checked_url}})
7
7
  JSON.parse(response)['result']['views'] || 0
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module SocialShares
3
3
  URL = 'http://cdn.api.twitter.com/1/urls/count.json'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {:params => {:url => checked_url}})
6
+ response = get(URL, {:params => {:url => checked_url}})
7
7
  JSON.parse(response)['count']
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module SocialShares
2
- VERSION = '0.2.5'
2
+ VERSION = '0.2.6'
3
3
  end
@@ -3,13 +3,13 @@ module SocialShares
3
3
  URL = 'http://vk.com/share.php'
4
4
 
5
5
  def shares!
6
- response = RestClient.get(URL, {
7
- :params => {
8
- :act => 'count',
9
- :index => 1,
10
- :url => checked_url,
11
- }
12
- })
6
+ response = get(URL, {
7
+ :params => {
8
+ :act => 'count',
9
+ :index => 1,
10
+ :url => checked_url,
11
+ }
12
+ })
13
13
  /VK.Share.count\(1,\s(\d+)\)/.match(response)[1].to_i
14
14
  end
15
15
  end
@@ -4,26 +4,26 @@ module SocialShares
4
4
  URL_FOR_SHARE = 'https://api.weibo.com/2/short_url/share/counts.json'
5
5
 
6
6
  def shares!
7
- response = RestClient.get(URL_FOR_SHARE, {
8
- :params => {
9
- :_ => '1414437609900',
10
- :source => '8003029170',
11
- :url_short => short_url
12
- }
13
- })
7
+ response = get(URL_FOR_SHARE, {
8
+ :params => {
9
+ :_ => '1414437609900',
10
+ :source => '8003029170',
11
+ :url_short => short_url
12
+ }
13
+ })
14
14
  JSON.parse(response)['urls'].first['share_counts'].to_i
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def short_url
20
- response = RestClient.get(URL_FOR_SHORT, {
21
- :params => {
22
- :_ => '1414437609673',
23
- :source => '8003029170',
24
- :url_long => checked_url
25
- }
26
- })
20
+ response = get(URL_FOR_SHORT, {
21
+ :params => {
22
+ :_ => '1414437609673',
23
+ :source => '8003029170',
24
+ :url_long => checked_url
25
+ }
26
+ })
27
27
  JSON.parse(response)['urls'].first['url_short']
28
28
  end
29
29
  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.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timur Kozmenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.4.5
132
+ rubygems_version: 2.4.8
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Check how many times url was shared in social networks.