liker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +21 -0
- data/Rakefile +1 -0
- data/lib/liker.rb +46 -0
- data/lib/liker/version.rb +3 -0
- data/liker.gemspec +24 -0
- metadata +85 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#Liker
|
2
|
+
|
3
|
+
Liker is wrapper to social networks API, which fetches the count of likes for specified URL. It supports Twitter, Facebook and VK. You are welcome to add support of some other resources.
|
4
|
+
|
5
|
+
##Examples
|
6
|
+
|
7
|
+
Liker.likes_count "http://evrone.ru/", :source => :facebook
|
8
|
+
=> 60
|
9
|
+
|
10
|
+
Liker.likes_count "http://evrone.ru/"
|
11
|
+
=> {:total=>105, :vk=>5, :twitter=>40, :facebook=>60}
|
12
|
+
|
13
|
+
##Installation
|
14
|
+
|
15
|
+
```gem install likes```
|
16
|
+
|
17
|
+
or add `gem "likes"` to the `Gemfile`
|
18
|
+
|
19
|
+
##Author
|
20
|
+
|
21
|
+
* [Kir Shatrov](https://github.com/kirs/), [Evrone.com](http://evrone.com)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/liker.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "liker/version"
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Liker
|
6
|
+
def self.likes_count(*options)
|
7
|
+
url = options[0]
|
8
|
+
raise ArgumentError, "Specify the url as the first argument" unless url
|
9
|
+
source = options[1][:source] rescue nil
|
10
|
+
if source
|
11
|
+
Liker.send("#{source}_likes_count", url)
|
12
|
+
else
|
13
|
+
result = {
|
14
|
+
:facebook => self.facebook_likes_count(url),
|
15
|
+
:vk => self.vk_likes_count(url),
|
16
|
+
:twitter => self.twitter_likes_count(url)
|
17
|
+
}
|
18
|
+
result[:total] = result.values.inject{|sum,value| sum + value}
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def self.facebook_likes_count(url)
|
26
|
+
resp = Net::HTTP.get_response("graph.facebook.com", "/#{url}")
|
27
|
+
json = JSON.parse(resp.body)
|
28
|
+
json ? json["shares"].to_i : 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.vk_likes_count(url)
|
32
|
+
base_url = "http://vkontakte.ru/share.php"
|
33
|
+
url = "#{base_url}?act=count&index=0&url=#{url}"
|
34
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
35
|
+
regexp = /[VK.Share.count(0, ]([\d]*)[);]/
|
36
|
+
count = regexp.match(resp.body)
|
37
|
+
count ? count[1].to_i : 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.twitter_likes_count(url)
|
41
|
+
resp = Net::HTTP.get_response("cdn.api.twitter.com", "/1/urls/count.json?url=#{url}&callback=")
|
42
|
+
json = JSON.parse(resp.body)
|
43
|
+
json ? json["count"].to_i : 0
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/liker.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "liker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "liker"
|
7
|
+
s.version = Liker::VERSION
|
8
|
+
s.authors = ["Kir Shatrov"]
|
9
|
+
s.email = ["shatrov@me.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Fetches the count of likes for specified URL in social networks}
|
12
|
+
s.description = %q{Fetches the count of likes for specified URL in social networks}
|
13
|
+
|
14
|
+
s.rubyforge_project = "liker"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "json"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: liker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kir Shatrov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-12-09 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Fetches the count of likes for specified URL in social networks
|
35
|
+
email:
|
36
|
+
- shatrov@me.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- lib/liker.rb
|
49
|
+
- lib/liker/version.rb
|
50
|
+
- liker.gemspec
|
51
|
+
homepage: ""
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project: liker
|
80
|
+
rubygems_version: 1.8.11
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Fetches the count of likes for specified URL in social networks
|
84
|
+
test_files: []
|
85
|
+
|