sharing_counter 0.0.1 → 0.0.5
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 +4 -4
- data/Rakefile +36 -21
- data/lib/sharing_counter.rb +2 -3
- metadata +6 -42
- data/README.rdoc +0 -3
- data/lib/api/facebook.rb +0 -19
- data/lib/api/twitter.rb +0 -15
- data/lib/api/vk.rb +0 -17
- data/lib/api_provider.rb +0 -47
- data/lib/client.rb +0 -47
- data/lib/configuration.rb +0 -67
- data/lib/sharing_counter/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e14949c461eb4ecec57a716867bc880df78e3aa9
|
4
|
+
data.tar.gz: 1c692a3ea292cc115fd3eafe9e740e74a133ff01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e26411d038d457f6be9ae277c110e127a224f910424803650b58739db02047d35da89af02deb837fb35c8e2586ddd5b952ad9c9bac603b7bbb42a81c3a81db9a
|
7
|
+
data.tar.gz: 344abc8504a4e9654d7c1815caf3c2f9113a8254a09c40394eb6287ecc6d7b8524b6c2cebb577776763ace43557a2502114c237e2acc5cf873f59af8a1ed1038
|
data/Rakefile
CHANGED
@@ -1,32 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'rdoc/task'
|
1
|
+
require 'bundler/setup'
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "./lib/sharing_counter/version"
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
rdoc.title = 'SharingCounter'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.rdoc')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
5
|
+
def name
|
6
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
15
7
|
end
|
16
8
|
|
9
|
+
def version
|
10
|
+
SharingCounter::VERSION
|
11
|
+
end
|
17
12
|
|
13
|
+
def gemspec_file
|
14
|
+
"#{name}.gemspec"
|
15
|
+
end
|
18
16
|
|
17
|
+
def gem_file
|
18
|
+
"#{name}-#{version}.gem"
|
19
|
+
end
|
19
20
|
|
20
|
-
Bundler
|
21
|
+
Bundler.require
|
21
22
|
|
22
|
-
|
23
|
+
desc 'Default: run spec tests.'
|
24
|
+
task :default => :spec
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
t.pattern = 'test/**/*_test.rb'
|
28
|
-
t.verbose = false
|
26
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
27
|
+
spec.pattern = Dir.glob(['spec/sharing_counter/*'])
|
28
|
+
spec.rspec_opts = ['--backtrace']
|
29
29
|
end
|
30
30
|
|
31
|
+
desc "Create tag v#{version}, build the gem and push to Git"
|
32
|
+
task :release => :build do
|
33
|
+
unless `git branch` =~ /^\* master$/
|
34
|
+
puts "You must be on the master branch to release!"
|
35
|
+
exit!
|
36
|
+
end
|
37
|
+
sh "git tag v#{version}"
|
38
|
+
sh "git push origin master --tags"
|
39
|
+
end
|
31
40
|
|
32
|
-
|
41
|
+
desc "Build #{gem_file} into the pkg/ directory"
|
42
|
+
task :build do
|
43
|
+
sh "mkdir -p pkg"
|
44
|
+
sh "gem build #{gemspec_file}"
|
45
|
+
sh "mv #{gem_file} pkg"
|
46
|
+
sh "bundle --local"
|
47
|
+
end
|
data/lib/sharing_counter.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
require "configuration"
|
1
|
+
require_relative "./sharing_counter/version.rb"
|
3
2
|
require "api_provider"
|
4
3
|
require "client"
|
4
|
+
require "configuration"
|
5
5
|
|
6
6
|
module SharingCounter
|
7
7
|
extend Configuration
|
@@ -10,5 +10,4 @@ module SharingCounter
|
|
10
10
|
client = Client.new(url, networks)
|
11
11
|
client.get_count
|
12
12
|
end
|
13
|
-
|
14
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sharing_counter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tolia Demidov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -39,41 +39,13 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
|
-
type: :
|
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
|
48
|
+
type: :development
|
77
49
|
prerelease: false
|
78
50
|
version_requirements: !ruby/object:Gem::Requirement
|
79
51
|
requirements:
|
@@ -89,16 +61,8 @@ extensions: []
|
|
89
61
|
extra_rdoc_files: []
|
90
62
|
files:
|
91
63
|
- MIT-LICENSE
|
92
|
-
- README.rdoc
|
93
64
|
- 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
65
|
- lib/sharing_counter.rb
|
101
|
-
- lib/sharing_counter/version.rb
|
102
66
|
homepage: http://github.com/Tolia/sharing_counter
|
103
67
|
licenses: []
|
104
68
|
metadata: {}
|
@@ -110,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
74
|
requirements:
|
111
75
|
- - ">="
|
112
76
|
- !ruby/object:Gem::Version
|
113
|
-
version: '0'
|
77
|
+
version: '2.0'
|
114
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
79
|
requirements:
|
116
80
|
- - ">="
|
@@ -118,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
82
|
version: '0'
|
119
83
|
requirements: []
|
120
84
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.4.5
|
122
86
|
signing_key:
|
123
87
|
specification_version: 4
|
124
88
|
summary: Social Counter.
|
data/README.rdoc
DELETED
data/lib/api/facebook.rb
DELETED
@@ -1,19 +0,0 @@
|
|
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
DELETED
data/lib/api/vk.rb
DELETED
@@ -1,17 +0,0 @@
|
|
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
DELETED
@@ -1,47 +0,0 @@
|
|
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
DELETED
@@ -1,47 +0,0 @@
|
|
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
|
data/lib/configuration.rb
DELETED
@@ -1,67 +0,0 @@
|
|
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
|