sharer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +2 -1
- data/LICENCE +20 -0
- data/README.md +34 -0
- data/Rakefile +5 -0
- data/lib/sharer/version.rb +1 -1
- data/lib/sharer.rb +71 -1
- data/sharer.gemspec +3 -5
- data/spec/sharer_spec.rb +24 -0
- data/spec/spec_helper.rb +1 -0
- metadata +31 -5
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/LICENCE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Adam Martinik
|
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.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Sharer
|
2
|
+
|
3
|
+
If your application needs to count the number of shared, this gem can help you.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
Add to your Gemfile and run the `bundle` command to install it.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "sharer"
|
11
|
+
```
|
12
|
+
## Source
|
13
|
+
|
14
|
+
Sharer's Git repo is available on GitHub, which can be browsed at:
|
15
|
+
|
16
|
+
http://github.com/14113/Sharer
|
17
|
+
|
18
|
+
and cloned with:
|
19
|
+
|
20
|
+
git clone git://github.com/14113/sharer.git
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Call Sharer in an Model and pass the url of the website.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
result = Sharer.find("google.com")
|
29
|
+
```
|
30
|
+
|
31
|
+
This will find count of shareing in facebook, twitter abd linkedin.
|
32
|
+
|
33
|
+
|
34
|
+
This gem is created by Adam Martinik and is under the MIT License.
|
data/Rakefile
CHANGED
data/lib/sharer/version.rb
CHANGED
data/lib/sharer.rb
CHANGED
@@ -1,5 +1,75 @@
|
|
1
1
|
require "sharer/version"
|
2
2
|
|
3
|
+
require "net/https"
|
4
|
+
require 'xmlrpc/client'
|
5
|
+
require 'rexml/document'
|
6
|
+
|
3
7
|
module Sharer
|
4
|
-
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
# Find the number of likes by url
|
12
|
+
def facebook_likes url
|
13
|
+
return nil unless valid_url? url
|
14
|
+
|
15
|
+
path = "http://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22#{url}%22"
|
16
|
+
content = content(path)
|
17
|
+
root = REXML::Document.new(content)
|
18
|
+
root.elements[1].elements["link_stat/like_count"].text.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
# Find the number of tweeter buttons by url
|
22
|
+
def twitter_button url
|
23
|
+
return nil unless valid_url? url
|
24
|
+
path = "http://urls.api.twitter.com/1/urls/count.json?url=#{url}"
|
25
|
+
content(path).match(/\"count\":([0-9]*),/)[1].to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
# Find the number of linkedin shares by url
|
29
|
+
def linked_in_share url
|
30
|
+
return nil unless valid_url? url
|
31
|
+
path = "http://www.linkedin.com/countserv/count/share?url=#{url}&callback=myCallback&format=json"
|
32
|
+
content(path).match(/\"count\":([0-9]*),/)[1].to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
# Find shareing by url
|
36
|
+
def find url
|
37
|
+
return nil unless valid_url? url
|
38
|
+
|
39
|
+
data = {}
|
40
|
+
threads = []
|
41
|
+
|
42
|
+
threads << Thread.new do
|
43
|
+
data["facebook"] = facebook_likes url
|
44
|
+
end
|
45
|
+
|
46
|
+
threads << Thread.new do
|
47
|
+
data["google"] = self.twitter_button url
|
48
|
+
end
|
49
|
+
|
50
|
+
threads << Thread.new do
|
51
|
+
data["twitter"] = self.linked_in_share url
|
52
|
+
end
|
53
|
+
|
54
|
+
threads.each {|t| t.join }
|
55
|
+
data
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
private
|
60
|
+
# Valid url
|
61
|
+
def valid_url? url
|
62
|
+
(url =~ URI::regexp).nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
# Content by url
|
66
|
+
def content url
|
67
|
+
begin
|
68
|
+
Net::HTTP.get_response(URI.parse(url)).body
|
69
|
+
rescue => exception
|
70
|
+
print exception.backtrace.join("\n")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
5
75
|
end
|
data/sharer.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Adam Martinik"]
|
9
9
|
s.email = ["a.martinik@seznam.cz"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = %q{
|
12
|
-
s.description = %q{
|
11
|
+
s.summary = %q{}
|
12
|
+
s.description = %q{If your application needs to count the number of shared, this gem can help you.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "sharer"
|
15
15
|
|
@@ -18,7 +18,5 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
22
|
-
# s.add_development_dependency "rspec"
|
23
|
-
# s.add_runtime_dependency "rest-client"
|
21
|
+
s.add_development_dependency "rspec"
|
24
22
|
end
|
data/spec/sharer_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sharer do
|
4
|
+
it "find count of likes on facebook" do
|
5
|
+
Sharer.facebook_likes("google.com").should be_a(Integer)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "find count of likes on twitter" do
|
9
|
+
Sharer.twitter_button("google.com").should be_a(Integer)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "find count of likes on twitter" do
|
13
|
+
Sharer.linked_in_share("google.com").should be_a(Integer)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "find count of shareing in facebook,twitter and linkedin" do
|
17
|
+
Sharer.find("google.com").should be_a(Hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "find count of likes on facebook by invalid url" do
|
21
|
+
Sharer.facebook_likes("ada:example/com").should eq(nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sharer'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sharer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,8 +10,20 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-04-22 00:00:00.000000000Z
|
13
|
-
dependencies:
|
14
|
-
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70217497905120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70217497905120
|
25
|
+
description: If your application needs to count the number of shared, this gem can
|
26
|
+
help you.
|
15
27
|
email:
|
16
28
|
- a.martinik@seznam.cz
|
17
29
|
executables: []
|
@@ -19,11 +31,17 @@ extensions: []
|
|
19
31
|
extra_rdoc_files: []
|
20
32
|
files:
|
21
33
|
- .gitignore
|
34
|
+
- .rspec
|
35
|
+
- CHANGELOG.md
|
22
36
|
- Gemfile
|
37
|
+
- LICENCE
|
38
|
+
- README.md
|
23
39
|
- Rakefile
|
24
40
|
- lib/sharer.rb
|
25
41
|
- lib/sharer/version.rb
|
26
42
|
- sharer.gemspec
|
43
|
+
- spec/sharer_spec.rb
|
44
|
+
- spec/spec_helper.rb
|
27
45
|
homepage: ''
|
28
46
|
licenses: []
|
29
47
|
post_install_message:
|
@@ -36,16 +54,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
54
|
- - ! '>='
|
37
55
|
- !ruby/object:Gem::Version
|
38
56
|
version: '0'
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
hash: 4557104551091993199
|
39
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
61
|
none: false
|
41
62
|
requirements:
|
42
63
|
- - ! '>='
|
43
64
|
- !ruby/object:Gem::Version
|
44
65
|
version: '0'
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
hash: 4557104551091993199
|
45
69
|
requirements: []
|
46
70
|
rubyforge_project: sharer
|
47
71
|
rubygems_version: 1.8.10
|
48
72
|
signing_key:
|
49
73
|
specification_version: 3
|
50
|
-
summary:
|
51
|
-
test_files:
|
74
|
+
summary: ''
|
75
|
+
test_files:
|
76
|
+
- spec/sharer_spec.rb
|
77
|
+
- spec/spec_helper.rb
|