social_shares 0.0.2 → 0.0.3

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: 869ebf69f22900f1ae4fbfe5b71a19324aeacc83
4
- data.tar.gz: c98ab7ec245dfbdb58d870d909f401f0f5225412
3
+ metadata.gz: 27877d5ac4dc67febe1d05033a50c25649cc5232
4
+ data.tar.gz: b0365e412ee96188a36c57135a19d62bb6dd99a2
5
5
  SHA512:
6
- metadata.gz: bf6bce07abbcb34cc58243064370d346280c409b5143f5fcd76fe358aba2b481322ad385e6234069ac170e0fdc50ecf6fe7e7afa3ce12580acb8a1fe09da541b
7
- data.tar.gz: e736be1d7b9fd30602466822deef747580da3c8e629d4a25689f213fa3a4185e1536901fe47613d772d9e6c7dbe5abba56f0494aed1cf49a991bb8f76c64fd65
6
+ metadata.gz: 52c3e2cc8cbfe5fb9350a6abdb51cee0cc43e4a65d1bb12b02b8560cf5c4fae64fffa1d242fa1a3728829bbbdd3bfe0f748787b40911cac6d5daaad6bf47f8d5
7
+ data.tar.gz: d8a61a63e2a4cb5aa1192c0d77ca2905c6c99e720361ba428da411c216f272d3720e4751deb1a490669e2ccf79ee64ed03ec5a86f20b7c8e7f3644873fce7129
data/README.md CHANGED
@@ -3,10 +3,12 @@ Social Shares
3
3
  Social shares is intended to easily check social sharings of an url.
4
4
 
5
5
  Supported networks:
6
- * facebook
7
- * google plus
8
- * twitter
9
- * vkontakte
6
+ * [facebook](http://www.facebook.com/)
7
+ * [google plus](https://plus.google.com)
8
+ * [twitter](https://twitter.com/)
9
+ * [vkontakte](http://vkontakte.ru/)
10
+ * [mail.ru](http://mail.ru/)
11
+ * [odnoklassniki](http://www.odnoklassniki.ru/)
10
12
 
11
13
  Usage
12
14
  -----
@@ -15,29 +17,25 @@ Currently all methods can raise exception when there is any error with network a
15
17
  :000 > require 'social_shares'
16
18
  => true
17
19
  :000 > SocialShares.supported_networks
18
- => [:vkontakte, :facebook, :google, :twitter]
19
- :000 > url = 'https://www.ruby-toolbox.com/'
20
+ => [:vkontakte, :facebook, :google, :twitter, :mail_ru, :odnoklassniki]
21
+ :000 > url = 'http://www.apple.com/'
20
22
  => "https://www.ruby-toolbox.com/"
21
23
  :000 > SocialShares.facebook url
22
- => 209
23
- :000 > SocialShares.facebook url
24
- => 209
24
+ => 394927
25
25
  :000 > SocialShares.google url
26
- => 227
26
+ => 28289
27
27
  :000 > SocialShares.twitter url
28
- => 784
29
- :000 > SocialShares.vkontakte url
30
- => 5
28
+ => 1164675
31
29
  :000 > SocialShares.all url
32
- => {:vkontakte=>5, :facebook=>209, :google=>227, :twitter=>784}
30
+ => {:vkontakte=>43044, :facebook=>394927, :google=>28289, :twitter=>1164675, :mail_ru=>105, :odnoklassniki=>62}
33
31
  :000 > SocialShares.selected url, %w(facebook google)
34
- => {:facebook=>209, :google=>227}
32
+ => {:facebook=>394927, :google=>28289}
35
33
  # Total sum of sharings in selected networks
36
34
  :000 > SocialShares.total url, %w(facebook google)
37
- => 436
35
+ => 423216
38
36
  # Second arg is optional, by default it takes all networks
39
37
  :000 > SocialShares.total url
40
- => 1225
38
+ => 1631102
41
39
  # Note that #has_any? is faster than (#total > 0), coz it stops on first network that has at least 1 sharing
42
40
  :000 > SocialShares.has_any? url, %w(facebook google)
43
41
  => true
data/lib/social_shares.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  require 'rest-client'
2
- require 'oj'
2
+ require 'json'
3
3
  require 'social_shares/version'
4
4
  require 'social_shares/base'
5
5
  require 'social_shares/facebook'
6
6
  require 'social_shares/google'
7
7
  require 'social_shares/twitter'
8
8
  require 'social_shares/vkontakte'
9
+ require 'social_shares/mail_ru'
10
+ require 'social_shares/odnoklassniki'
9
11
 
10
12
  module SocialShares
11
13
  class << self
12
- SUPPORTED_NETWORKS = [:vkontakte, :facebook, :google, :twitter]
14
+ SUPPORTED_NETWORKS = [:vkontakte, :facebook, :google, :twitter, :mail_ru, :odnoklassniki]
13
15
 
14
16
  def supported_networks
15
17
  SUPPORTED_NETWORKS
@@ -17,7 +19,8 @@ module SocialShares
17
19
 
18
20
  SUPPORTED_NETWORKS.each do |network_name|
19
21
  define_method(network_name) do |url|
20
- Object.const_get("#{self.name}::#{network_name.to_s.capitalize}").new(url).shares
22
+ class_name = network_name.to_s.split('_').map(&:capitalize).join
23
+ SocialShares.const_get(class_name).new(url).shares
21
24
  end
22
25
  end
23
26
 
@@ -0,0 +1,18 @@
1
+ module SocialShares
2
+ class MailRu < Base
3
+ def shares
4
+ response["share_mm"].to_i
5
+ end
6
+
7
+ protected
8
+
9
+ def response
10
+ response = RestClient.get(url)
11
+ JSON.parse(response)
12
+ end
13
+
14
+ def url
15
+ "http://appsmail.ru/share/count/#{checked_url}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module SocialShares
2
+ class Odnoklassniki < MailRu
3
+ def shares
4
+ response["share_ok"].to_i
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module SocialShares
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  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.0.2
4
+ version: 0.0.3
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-06 00:00:00.000000000 Z
11
+ date: 2014-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -82,6 +82,8 @@ files:
82
82
  - lib/social_shares/base.rb
83
83
  - lib/social_shares/facebook.rb
84
84
  - lib/social_shares/google.rb
85
+ - lib/social_shares/mail_ru.rb
86
+ - lib/social_shares/odnoklassniki.rb
85
87
  - lib/social_shares/twitter.rb
86
88
  - lib/social_shares/version.rb
87
89
  - lib/social_shares/vkontakte.rb