social_shares 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20fef347f60300838fdd4ea86f4e7aec7f175401
4
+ data.tar.gz: 32a0e9a527986f1e11e3f54d8b73320498b72816
5
+ SHA512:
6
+ metadata.gz: a30527f4e51876f8e4aa9f12044b8f690ccbcce18c58b1968093614dce649e8596ca93d1679deb3278db484e662a05bf05a0ea54c58eda99cbb3cd7715a26f6c
7
+ data.tar.gz: f224160cf61957771da91192a160cb04a52305460552531ae442556851ac8146017e894079265911f75884d9dfe8ae97e94166f7b2fc2d55faf243f65fb19d18
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in social_shares.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Timur Kozmenko
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ Social Shares
2
+ =============
3
+ Social shares is intended to easily check social sharings of an url.
4
+
5
+ Supported networks:
6
+ * facebook
7
+ * google plus
8
+ * twitter
9
+ * vkontakte
10
+
11
+ Usage
12
+ -----
13
+ Currently all methods can raise exception when there is any error with network access.
14
+ ```ruby
15
+ :001 > require 'social_shares'
16
+ => true
17
+ :002 > url = 'https://www.ruby-toolbox.com/'
18
+ => "https://www.ruby-toolbox.com/"
19
+ :003 > SocialShares.facebook url
20
+ => 209
21
+ :004 > SocialShares.google url
22
+ => 227
23
+ :005 > SocialShares.twitter url
24
+ => 784
25
+ :006 > SocialShares.vkontakte url
26
+ => 5
27
+ :007 > SocialShares.all url
28
+ => {:vkontakte=>5, :facebook=>209, :google=>227, :twitter=>784}
29
+ :008 > SocialShares.selected url, %w(facebook google)
30
+ => {:facebook=>209, :google=>227}
31
+ # Total sum of sharings in selected networks
32
+ :009 > SocialShares.total url, %w(facebook google)
33
+ => 436
34
+ # 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)
36
+ => true
37
+ ```
38
+
39
+ Instalation
40
+ -----
41
+ Include the gem in your Gemfile:
42
+ ```
43
+ gem 'social_shares'
44
+ ```
45
+
46
+ Authors
47
+ ----
48
+ * [Timur Kozmenko](https://twitter.com/Timrael)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,13 @@
1
+ module SocialShares
2
+ class Base
3
+ attr_accessor :checked_url
4
+
5
+ def initialize(checked_url)
6
+ @checked_url = checked_url
7
+ end
8
+
9
+ def shares
10
+ raise NotImplementedError
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module SocialShares
2
+ class Facebook < Base
3
+ def shares
4
+ response = RestClient.get(url)
5
+ Oj.load(response)["shares"] || 0
6
+ end
7
+
8
+ private
9
+
10
+ def url
11
+ "http://graph.facebook.com/?id=#{checked_url}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ module SocialShares
2
+ class Google < Base
3
+ def shares
4
+ response = RestClient.post(url, Oj.dump(params), content_type: :json, accept: :json)
5
+ Oj.load(response)[0]["result"]["metadata"]["globalCounts"]["count"].to_i
6
+ end
7
+
8
+ private
9
+
10
+ def url
11
+ "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ"
12
+ end
13
+
14
+ def params
15
+ [{
16
+ 'method' => 'pos.plusones.get',
17
+ 'id' => 'p',
18
+ 'jsonrpc' => '2.0',
19
+ 'key' => 'p',
20
+ 'apiVersion' => 'v1',
21
+ 'params' => {
22
+ 'nolog' => true,
23
+ 'id' => checked_url,
24
+ 'source' => 'widget',
25
+ 'userId' => '@viewer',
26
+ 'groupId' => '@self'
27
+ }
28
+ }]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ module SocialShares
2
+ class Twitter < Base
3
+ def shares
4
+ response = RestClient.get(url)
5
+ Oj.load(response)["count"]
6
+ end
7
+
8
+ private
9
+
10
+ def url
11
+ "http://cdn.api.twitter.com/1/urls/count.json?url=#{checked_url}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module SocialShares
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,14 @@
1
+ module SocialShares
2
+ class Vkontakte < Base
3
+ def shares
4
+ response = RestClient.get(url)
5
+ /VK.Share.count\(1,\s(\d+)\)/.match(response)[1].to_i
6
+ end
7
+
8
+ private
9
+
10
+ def url
11
+ "http://vk.com/share.php?act=count&index=1&url=#{checked_url}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ require 'rest-client'
2
+ require 'oj'
3
+ require 'social_shares/version'
4
+ require 'social_shares/base'
5
+ require 'social_shares/facebook'
6
+ require 'social_shares/google'
7
+ require 'social_shares/twitter'
8
+ require 'social_shares/vkontakte'
9
+
10
+ module SocialShares
11
+ class << self
12
+ SUPPORTED_NETWORKS = [:vkontakte, :facebook, :google, :twitter]
13
+
14
+ def supported_networks
15
+ SUPPORTED_NETWORKS
16
+ end
17
+
18
+ SUPPORTED_NETWORKS.each do |network_name|
19
+ define_method(network_name) do |url|
20
+ Object.const_get("#{self.name}::#{network_name.to_s.capitalize}").new(url).shares
21
+ end
22
+ end
23
+
24
+ def selected(url, selected_networks)
25
+ filtered_networks(selected_networks).inject({}) do |result, network_name|
26
+ result[network_name] = self.send(network_name, url)
27
+ result
28
+ end
29
+ end
30
+
31
+ def all(url)
32
+ selected(url, SUPPORTED_NETWORKS)
33
+ end
34
+
35
+ def total(url, selected_networks)
36
+ selected(url, selected_networks).values.reduce(:+)
37
+ end
38
+
39
+ def has_any?(url, selected_networks)
40
+ !filtered_networks(selected_networks).find{|n| self.send(n, url) > 0}.nil?
41
+ end
42
+
43
+ private
44
+
45
+ def filtered_networks(selected_networks)
46
+ selected_networks.map(&:to_sym) & SUPPORTED_NETWORKS
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'social_shares/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'social_shares'
8
+ spec.version = SocialShares::VERSION
9
+ spec.authors = ['Timur Kozmenko']
10
+ spec.email = ['timraell@gmail.com']
11
+ spec.summary = %q{Check how many times url was shared in social networks.}
12
+ spec.description = %q{Check how many times url was shared in social networks.}
13
+ spec.homepage = 'https://github.com/Timrael/social_shares'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rest-client'
22
+ spec.add_dependency 'oj'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: social_shares
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Timur Kozmenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Check how many times url was shared in social networks.
70
+ email:
71
+ - timraell@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/social_shares.rb
82
+ - lib/social_shares/base.rb
83
+ - lib/social_shares/facebook.rb
84
+ - lib/social_shares/google.rb
85
+ - lib/social_shares/twitter.rb
86
+ - lib/social_shares/version.rb
87
+ - lib/social_shares/vkontakte.rb
88
+ - social_shares.gemspec
89
+ homepage: https://github.com/Timrael/social_shares
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Check how many times url was shared in social networks.
113
+ test_files: []