share_counts 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -5
- data/README.rdoc +7 -0
- data/lib/share_counts/common.rb +5 -3
- data/lib/share_counts/reddit.rb +15 -0
- data/share_counts.gemspec +1 -1
- metadata +5 -5
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -85,6 +85,13 @@ You can also specify which networks you want to query at once:
|
|
85
85
|
|
86
86
|
ruby-1.9.2-p0 :004 > ShareCounts.selected "http://vitobotta.com/awesomeprint-similar-production/", [:reddit, :twitter]
|
87
87
|
=> {:reddit=>5, :twitter=>2}
|
88
|
+
|
89
|
+
|
90
|
+
For Reddit, you can also get the share counts for all the known URLs from a given domain:
|
91
|
+
|
92
|
+
ruby-1.9.2-head :009 > ShareCounts::Reddit.by_domain "vitobotta.com"
|
93
|
+
Redis caching is disabled - Making request to reddit-domain...
|
94
|
+
|
88
95
|
|
89
96
|
Sometimes APIs may not be available or may be having issues (or there's some rate limit and you are making too many requests in a short time). When something goes wrong while querying a service, even for a max of 3 attempts, the share count for that service is left as set to nil. This way you can easily know whether a share count could be obtained or updated for a given URL, but simply checking if the share count is nil.
|
90
97
|
|
data/lib/share_counts/common.rb
CHANGED
@@ -98,9 +98,11 @@ module ShareCounts
|
|
98
98
|
#
|
99
99
|
#
|
100
100
|
def extract_info *args
|
101
|
-
json
|
102
|
-
|
103
|
-
|
101
|
+
json = args.shift
|
102
|
+
options = args.inject({}) {|r,c| r.merge(c)}
|
103
|
+
|
104
|
+
result = options[:selector].split("/").inject( json.is_a?(Array) ? json.first : json ) { |r, c|
|
105
|
+
(r[c].is_a?(Array) && !options[:preserve_arrays]) ? r[c].first : r[c]
|
104
106
|
}
|
105
107
|
end
|
106
108
|
|
data/lib/share_counts/reddit.rb
CHANGED
@@ -15,5 +15,20 @@ module ShareCounts
|
|
15
15
|
}
|
16
16
|
}
|
17
17
|
end
|
18
|
+
|
19
|
+
def self.by_domain domain
|
20
|
+
try("reddit-domain", domain) {
|
21
|
+
urls = extract_info from_json("http://www.reddit.com/domain/#{domain}.json"), :selector => "data/children", :preserve_arrays => true
|
22
|
+
urls.inject({}) do |result, url_all_info|
|
23
|
+
url_data = extract_info(url_all_info, :selector => "data").reject{ |key, value| !["permalink", "score", "url"].include? key }
|
24
|
+
url = url_data.delete "url"
|
25
|
+
p url
|
26
|
+
result[url] = url_data
|
27
|
+
|
28
|
+
result
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
18
33
|
end
|
19
34
|
end
|
data/share_counts.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: share_counts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vito Botta
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-24 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
requirements: []
|
155
155
|
|
156
156
|
rubyforge_project: share_counts
|
157
|
-
rubygems_version: 1.
|
157
|
+
rubygems_version: 1.5.2
|
158
158
|
signing_key:
|
159
159
|
specification_version: 3
|
160
160
|
summary: The easiest way to check how many times a URL has been shared on Reddit, Digg, Twitter, Facebook, LinkedIn, GoogleBuzz and StumbleUpon!
|