share_counter 0.1.0

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: e46fa1e2031e0a21b485923ed3fda5fda19bd8aa
4
+ data.tar.gz: a86d96640cffe7dd39e12deeecdd95e24782328c
5
+ SHA512:
6
+ metadata.gz: 4d29de7717153c21ed6794ac7a84737551971ec685671260efe567a2888d90ece22cf086fc53e5efa027eb5fbe9e2c9b6721411fd7e5a1fc0f8209de4880470f
7
+ data.tar.gz: 19c290aacd7e335db56b0680c3b933c44f8e8d0cad78b243e3fcd392f287cd275ec1895d459909d3dca3d97acd1388574a8516f7d17da6e2ae1b7df59ceed314
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in share_counter.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chorally LTD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # ShareCounter
2
+
3
+ This gem makes it super easy to check how many times a page/URL has been shared on social networks and aggregators.
4
+
5
+ Services currently supported:
6
+
7
+ Facebook
8
+
9
+ Twitter
10
+
11
+ Linkedin
12
+
13
+ Reddit
14
+
15
+ Stumbleupon
16
+
17
+ Pinterest
18
+
19
+ SeoMoz (individually)
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'share_counter'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install share_counter
36
+
37
+ ## Usage
38
+
39
+ Take all share count info from each service.
40
+
41
+ ```ruby
42
+ share_counter = ShareCounter.all 'www.chorally.com'
43
+
44
+ {:reddit=>0, :twitter=>47, :facebook=>{:commentsbox_count=>0, :click_count=>0, :total_count=>44, :comment_count=>12, :like_count=>19, :share_count=>13}, :linkedin=>58, :stumbleupon=>nil, :pinterest=>0}
45
+ ```
46
+ MozRank and PageAuthority
47
+
48
+ ```ruby
49
+ share_counter = ShareCounter.seomoz url, 'mozscape-7628090b62', '28bb5c0625d4f2b634a3d64e99e6fe3e'
50
+
51
+ {:mozrank=>5.797102554162212, :page_authority=>31.615971930077954}
52
+ ```
53
+
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/share_counter.
64
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "share_counter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,90 @@
1
+ require "share_counter/version"
2
+ require "rest-client"
3
+ require "json"
4
+ require "linkscape"
5
+
6
+ module ShareCounter
7
+ def self.twitter url
8
+ html = make_request "http://urls.api.twitter.com/1/urls/count.json", url: url
9
+ return JSON.parse(html)['count']
10
+ end
11
+
12
+ def self.facebook url
13
+ html = make_request "https://api.facebook.com/method/fql.query", format: "json", query: "select commentsbox_count, click_count, total_count, comment_count, like_count, share_count from link_stat where url=\"#{url}\""
14
+ return JSON.parse(html, symbolize_names: true)[0]
15
+ end
16
+
17
+ def self.reddit url
18
+ html = make_request "http://www.reddit.com/api/info.json", url: url
19
+ j = JSON.parse(html)
20
+
21
+ unless j['data']['children'].empty?
22
+ return j['data']['children'][0]['data']['score']
23
+ else
24
+ return 0
25
+ end
26
+ end
27
+
28
+ def self.linkedin url
29
+ html = make_request "https://www.linkedin.com/countserv/count/share", url: url, callback: "IN.Tags.Share.handleCount"
30
+ return JSON.parse(html)['count']
31
+ end
32
+
33
+ def self.stumbleupon url
34
+ html = make_request "http://www.stumbleupon.com/services/1.01/badge.getinfo", url: url
35
+ return JSON.parse(html)['result']['views']
36
+ end
37
+
38
+ def self.pinterest url
39
+ html = make_request "http://widgets.pinterest.com/v1/urls/count.json", url: url, source: 6
40
+ html.gsub! 'receiveCount(', ''
41
+ html.gsub! ')', ''
42
+ return JSON.parse(html)['count']
43
+ end
44
+
45
+ def self.seomoz url, access_id, secret
46
+ client = Linkscape::Client.new(accessID: access_id, secret: secret)
47
+ response = client.urlMetrics(url, cols: :all)
48
+ { mozrank: response.data['source'][:mozrank], page_authority: response.data['source'][:page_authority] }
49
+ end
50
+
51
+ def self.supported_networks
52
+ %w(reddit twitter facebook linkedin stumbleupon pinterest)
53
+ end
54
+
55
+ def self.all url
56
+ supported_networks.inject({}) { |r, c| r[c.to_sym] = ShareCounter.send(c, url); r }
57
+ end
58
+
59
+ def self.selected url, selections
60
+ selections.map{|name| name.downcase}.select{|name| supported_networks.include? name.to_s}.inject({}) {
61
+ |r, c| r[c.to_sym] = ShareCounter.send(c, url); r }
62
+ end
63
+
64
+ private
65
+
66
+ def self.make_request *args
67
+ result = nil
68
+ attempts = 1
69
+ url = args.shift
70
+ params = args.inject({}) { |r, c| r.merge! c }
71
+
72
+ begin
73
+ response = RestClient.get url, { params: params, timeout: 5 , ssl: { verify_ssl: false } }
74
+ result = params.keys.include?(:callback) \
75
+ ? response.gsub(/\A\/\*\*\/\s+/, "").gsub(/^(.*);+\n*$/, "\\1").gsub(/^#{params[:callback]}\((.*)\)$/, "\\1") \
76
+ : response
77
+ rescue => e
78
+ puts "Failed #{attempts} attempt(s) - #{e}"
79
+ attempts += 1
80
+ if attempts <= 3
81
+ sleep 2
82
+ retry
83
+ else
84
+ raise e
85
+ end
86
+ end
87
+
88
+ result
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ module ShareCounter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'share_counter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "share_counter"
8
+ spec.version = ShareCounter::VERSION
9
+ spec.authors = ["Davide Santangelo"]
10
+ spec.email = ["davide@chorally.com"]
11
+
12
+ spec.summary = %q{Check how many times a URL has been shared on social networks and aggregators}
13
+ spec.description = %q{This gem makes it super easy to check how many times a page/URL has been shared on social networks and aggregators.}
14
+ spec.homepage = "http://www.chorally.com"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec"
32
+
33
+ spec.add_dependency "rest-client"
34
+ spec.add_dependency "json"
35
+ spec.add_dependency "linkscape"
36
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: share_counter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Davide Santangelo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rest-client
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: json
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
+ - !ruby/object:Gem::Dependency
84
+ name: linkscape
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This gem makes it super easy to check how many times a page/URL has been
98
+ shared on social networks and aggregators.
99
+ email:
100
+ - davide@chorally.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/share_counter.rb
115
+ - lib/share_counter/version.rb
116
+ - share_counter.gemspec
117
+ homepage: http://www.chorally.com
118
+ licenses: []
119
+ metadata:
120
+ allowed_push_host: https://rubygems.org
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.8
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Check how many times a URL has been shared on social networks and aggregators
141
+ test_files: []