social_shares 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20fef347f60300838fdd4ea86f4e7aec7f175401
4
- data.tar.gz: 32a0e9a527986f1e11e3f54d8b73320498b72816
3
+ metadata.gz: 869ebf69f22900f1ae4fbfe5b71a19324aeacc83
4
+ data.tar.gz: c98ab7ec245dfbdb58d870d909f401f0f5225412
5
5
  SHA512:
6
- metadata.gz: a30527f4e51876f8e4aa9f12044b8f690ccbcce18c58b1968093614dce649e8596ca93d1679deb3278db484e662a05bf05a0ea54c58eda99cbb3cd7715a26f6c
7
- data.tar.gz: f224160cf61957771da91192a160cb04a52305460552531ae442556851ac8146017e894079265911f75884d9dfe8ae97e94166f7b2fc2d55faf243f65fb19d18
6
+ metadata.gz: bf6bce07abbcb34cc58243064370d346280c409b5143f5fcd76fe358aba2b481322ad385e6234069ac170e0fdc50ecf6fe7e7afa3ce12580acb8a1fe09da541b
7
+ data.tar.gz: e736be1d7b9fd30602466822deef747580da3c8e629d4a25689f213fa3a4185e1536901fe47613d772d9e6c7dbe5abba56f0494aed1cf49a991bb8f76c64fd65
data/README.md CHANGED
@@ -12,27 +12,37 @@ Usage
12
12
  -----
13
13
  Currently all methods can raise exception when there is any error with network access.
14
14
  ```ruby
15
- :001 > require 'social_shares'
15
+ :000 > require 'social_shares'
16
16
  => true
17
- :002 > url = 'https://www.ruby-toolbox.com/'
17
+ :000 > SocialShares.supported_networks
18
+ => [:vkontakte, :facebook, :google, :twitter]
19
+ :000 > url = 'https://www.ruby-toolbox.com/'
18
20
  => "https://www.ruby-toolbox.com/"
19
- :003 > SocialShares.facebook url
21
+ :000 > SocialShares.facebook url
22
+ => 209
23
+ :000 > SocialShares.facebook url
20
24
  => 209
21
- :004 > SocialShares.google url
25
+ :000 > SocialShares.google url
22
26
  => 227
23
- :005 > SocialShares.twitter url
27
+ :000 > SocialShares.twitter url
24
28
  => 784
25
- :006 > SocialShares.vkontakte url
29
+ :000 > SocialShares.vkontakte url
26
30
  => 5
27
- :007 > SocialShares.all url
31
+ :000 > SocialShares.all url
28
32
  => {:vkontakte=>5, :facebook=>209, :google=>227, :twitter=>784}
29
- :008 > SocialShares.selected url, %w(facebook google)
33
+ :000 > SocialShares.selected url, %w(facebook google)
30
34
  => {:facebook=>209, :google=>227}
31
- # Total sum of sharings in selected networks
32
- :009 > SocialShares.total url, %w(facebook google)
35
+ # Total sum of sharings in selected networks
36
+ :000 > SocialShares.total url, %w(facebook google)
33
37
  => 436
38
+ # Second arg is optional, by default it takes all networks
39
+ :000 > SocialShares.total url
40
+ => 1225
34
41
  # Note that #has_any? is faster than (#total > 0), coz it stops on first network that has at least 1 sharing
35
- :010 > SocialShares.has_any? url, %w(facebook google)
42
+ :000 > SocialShares.has_any? url, %w(facebook google)
43
+ => true
44
+ # Second arg is optional, by default it takes all networks
45
+ :000 > SocialShares.has_any? url
36
46
  => true
37
47
  ```
38
48
 
data/lib/social_shares.rb CHANGED
@@ -32,11 +32,11 @@ module SocialShares
32
32
  selected(url, SUPPORTED_NETWORKS)
33
33
  end
34
34
 
35
- def total(url, selected_networks)
35
+ def total(url, selected_networks = SUPPORTED_NETWORKS)
36
36
  selected(url, selected_networks).values.reduce(:+)
37
37
  end
38
38
 
39
- def has_any?(url, selected_networks)
39
+ def has_any?(url, selected_networks = SUPPORTED_NETWORKS)
40
40
  !filtered_networks(selected_networks).find{|n| self.send(n, url) > 0}.nil?
41
41
  end
42
42
 
@@ -2,7 +2,7 @@ module SocialShares
2
2
  class Facebook < Base
3
3
  def shares
4
4
  response = RestClient.get(url)
5
- Oj.load(response)["shares"] || 0
5
+ JSON.parse(response)["shares"] || 0
6
6
  end
7
7
 
8
8
  private
@@ -2,7 +2,7 @@ module SocialShares
2
2
  class Google < Base
3
3
  def shares
4
4
  response = RestClient.post(url, Oj.dump(params), content_type: :json, accept: :json)
5
- Oj.load(response)[0]["result"]["metadata"]["globalCounts"]["count"].to_i
5
+ JSON.parse(response)[0]["result"]["metadata"]["globalCounts"]["count"].to_i
6
6
  end
7
7
 
8
8
  private
@@ -2,7 +2,7 @@ module SocialShares
2
2
  class Twitter < Base
3
3
  def shares
4
4
  response = RestClient.get(url)
5
- Oj.load(response)["count"]
5
+ JSON.parse(response)["count"]
6
6
  end
7
7
 
8
8
  private
@@ -1,3 +1,3 @@
1
1
  module SocialShares
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'rest-client'
22
- spec.add_dependency 'oj'
22
+ spec.add_dependency 'json'
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.6'
25
25
  spec.add_development_dependency 'rake'
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.0.1
4
+ version: 0.0.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-10-05 00:00:00.000000000 Z
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: oj
28
+ name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="