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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- share_counts (0.0.3)
4
+ share_counts (0.0.6)
5
5
  json
6
6
  nokogiri
7
7
  redis
@@ -24,9 +24,5 @@ PLATFORMS
24
24
 
25
25
  DEPENDENCIES
26
26
  ansi
27
- json
28
27
  minitest
29
- nokogiri
30
- redis
31
- rest-client
32
28
  share_counts!
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
 
@@ -98,9 +98,11 @@ module ShareCounts
98
98
  #
99
99
  #
100
100
  def extract_info *args
101
- json = args.shift
102
- result = args.first.to_a.flatten.last.split("/").inject( json.is_a?(Array) ? json.first : json ) {
103
- |r, c| r[c].is_a?(Array) ? r[c].first : r[c]
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
 
@@ -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
@@ -4,7 +4,7 @@ $:.push File.expand_path("../lib/share_counts", __FILE__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "share_counts"
7
- s.version = "0.0.5"
7
+ s.version = "0.0.6"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Vito Botta"]
10
10
  s.email = ["vito@botta.name"]
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
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-02-06 00:00:00 +00:00
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.4.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!