sharing_counter 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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +32 -0
- data/lib/api/facebook.rb +19 -0
- data/lib/api/twitter.rb +15 -0
- data/lib/api/vk.rb +17 -0
- data/lib/api_provider.rb +47 -0
- data/lib/client.rb +47 -0
- data/lib/configuration.rb +67 -0
- data/lib/sharing_counter.rb +14 -0
- data/lib/sharing_counter/version.rb +3 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 490f868de7de6559097e6e5cf7f46ca892091b1b
|
4
|
+
data.tar.gz: d49280a56de6d3355174809f1e85cd4579ae013e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e27243f99fd0b48c0e9b5ce69ea40f79473c812ff0c049e86d01525b082e7a4eaaa9833e30ad538ac75dec2187aace33031654a0e7fb079969185d2324933d4b
|
7
|
+
data.tar.gz: 9f8e95dd65ab25f2aefefecf32d9c9122302fda7c5de03aa601614505409ef3d3e042a69f7a96d671f1eb429286ad1701738c880e3e1a6bff8e0984faf7dbd6c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'SharingCounter'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
data/lib/api/facebook.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module SharingCounter
|
2
|
+
module API
|
3
|
+
class Facebook < APIprovider
|
4
|
+
|
5
|
+
DEFAULT_MEASUREMENT = "total_count"
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def request_url
|
10
|
+
"http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls=#{ @sharing_url }&format=json"
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(page)
|
14
|
+
JSON.parse(page)[0][@measurement].to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/api/twitter.rb
ADDED
data/lib/api/vk.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module SharingCounter
|
2
|
+
module API
|
3
|
+
class Vk < APIprovider
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def request_url
|
8
|
+
"http://vk.com/widget_like.php?app=#{ @app_id }&page=0&url=#{ @sharing_url }&type=mini"
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(page)
|
12
|
+
page.force_encoding("ISO-8859-1").encode("utf-8", replace: nil).scan(/var counter = ([0-9]+);/)[0][0].to_i
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/api_provider.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module SharingCounter
|
4
|
+
module API
|
5
|
+
class APIprovider
|
6
|
+
|
7
|
+
ATTRS = [:sharing_url]
|
8
|
+
DEFAULT_MEASUREMENT = false
|
9
|
+
DEFAULT_APP_ID = false
|
10
|
+
|
11
|
+
attr_accessor *(ATTRS + ::SharingCounter::Configuration::SETTINGS_KEYS)
|
12
|
+
|
13
|
+
def initialize(sharing_url)
|
14
|
+
@sharing_url = sharing_url
|
15
|
+
options = SharingCounter.options[self.class.name.demodulize.downcase.to_sym]
|
16
|
+
options.each do |key,val|
|
17
|
+
send "#{key}=", val
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def count
|
22
|
+
response = request
|
23
|
+
parse response.body if response.body && response.status == 200
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def request
|
29
|
+
Faraday.get do |r|
|
30
|
+
r.url URI.escape(request_url)
|
31
|
+
r.options = {
|
32
|
+
timeout: @timeout,
|
33
|
+
open_timeout: @open_timeout
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def request_url
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse(page)
|
42
|
+
JSON.parse(page)[@measurement].to_i
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/client.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
|
3
|
+
module SharingCounter
|
4
|
+
|
5
|
+
class Client
|
6
|
+
Dir[File.expand_path('../api/*.rb', __FILE__)].each{|f| require f}
|
7
|
+
|
8
|
+
ATTRS = [:sharing_url] + Configuration::NETWORKS_KEYS
|
9
|
+
|
10
|
+
attr_accessor *ATTRS
|
11
|
+
|
12
|
+
def initialize(sharing_url, networks=[])
|
13
|
+
@sharing_url = sharing_url
|
14
|
+
threads = []
|
15
|
+
networks.each_with_index do |network, i|
|
16
|
+
threads << Thread.new(i) do |i|
|
17
|
+
network_api = "SharingCounter::API::#{network.to_s.capitalize }".constantize
|
18
|
+
send "#{network}=", network_api.new(sharing_url)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
threads.each(&:join)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_count
|
25
|
+
start = Time.now
|
26
|
+
request = {
|
27
|
+
url: @sharing_url,
|
28
|
+
data: start,
|
29
|
+
}.merge networks_requests
|
30
|
+
request[:delay] = Time.now - start
|
31
|
+
request
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def networks_requests
|
37
|
+
request = {}
|
38
|
+
Configuration::NETWORKS_KEYS.each do |key|
|
39
|
+
network = send key
|
40
|
+
request[key] = network.count if network
|
41
|
+
end
|
42
|
+
request
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
|
3
|
+
module SharingCounter
|
4
|
+
|
5
|
+
module Configuration
|
6
|
+
|
7
|
+
NETWORKS_KEYS = [
|
8
|
+
:facebook,
|
9
|
+
:twitter,
|
10
|
+
:vk
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
DEFAULT_SETTINGS_KEYS = [
|
14
|
+
:timeout,
|
15
|
+
:open_timeout
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
INDIVIDUAL_SETTINGS_KEYS = [
|
19
|
+
:measurement,
|
20
|
+
:app_id
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
SETTINGS_KEYS = DEFAULT_SETTINGS_KEYS + INDIVIDUAL_SETTINGS_KEYS
|
24
|
+
|
25
|
+
DEFAULT_TIMEOUT = 2
|
26
|
+
DEFAULT_OPEN_TIMEOUT = 2
|
27
|
+
|
28
|
+
attr_accessor *NETWORKS_KEYS
|
29
|
+
|
30
|
+
# When this module is extended, set all configuration options to their default values
|
31
|
+
def self.extended(base)
|
32
|
+
base.reset
|
33
|
+
end
|
34
|
+
|
35
|
+
# Convenience method to allow configuration options to be set in a block
|
36
|
+
def configure
|
37
|
+
yield self
|
38
|
+
end
|
39
|
+
|
40
|
+
# Create a hash of options and their values
|
41
|
+
def options
|
42
|
+
NETWORKS_KEYS.inject({}) do |option, key|
|
43
|
+
option.merge! key => send(key)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Reset all configuration options to defaults
|
48
|
+
def reset
|
49
|
+
NETWORKS_KEYS.each do |network_key|
|
50
|
+
network = {}
|
51
|
+
DEFAULT_SETTINGS_KEYS.each do |key|
|
52
|
+
network[key] = "SharingCounter::Configuration::#{default(key)}".constantize
|
53
|
+
end
|
54
|
+
INDIVIDUAL_SETTINGS_KEYS.each do |key|
|
55
|
+
network[key] = "SharingCounter::API::#{network_key.to_s.capitalize }::#{ default(key) }".constantize
|
56
|
+
end
|
57
|
+
send "#{network_key}=", network
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def default(key)
|
64
|
+
"DEFAULT_#{ key.to_s.upcase }"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "configuration"
|
3
|
+
require "api_provider"
|
4
|
+
require "client"
|
5
|
+
|
6
|
+
module SharingCounter
|
7
|
+
extend Configuration
|
8
|
+
|
9
|
+
def self.get_count(url, networks = Configuration::NETWORKS_KEYS)
|
10
|
+
client = Client.new(url, networks)
|
11
|
+
client.get_count
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sharing_counter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tolia Demidov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: webmock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This simple Ruby function allows the user to display the amount of times
|
84
|
+
that an URL have been shared on different social networks.
|
85
|
+
email:
|
86
|
+
- toliademidov@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- MIT-LICENSE
|
92
|
+
- README.rdoc
|
93
|
+
- Rakefile
|
94
|
+
- lib/api/facebook.rb
|
95
|
+
- lib/api/twitter.rb
|
96
|
+
- lib/api/vk.rb
|
97
|
+
- lib/api_provider.rb
|
98
|
+
- lib/client.rb
|
99
|
+
- lib/configuration.rb
|
100
|
+
- lib/sharing_counter.rb
|
101
|
+
- lib/sharing_counter/version.rb
|
102
|
+
homepage: http://github.com/Tolia/sharing_counter
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.2.2
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Social Counter.
|
125
|
+
test_files: []
|