share-counter 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71205f4be75edf65365383aa2e57f340e14ac67d
4
- data.tar.gz: c72a6e11f8a22dffdbc7d78ea60ed1fbace6cf7f
3
+ metadata.gz: 28bd8134397ea367af88069e45b1b1b1ad9d54a7
4
+ data.tar.gz: b85350b9dc8689272f9b4bf798ba766eb91465b6
5
5
  SHA512:
6
- metadata.gz: 9f32634b33725d08d8715ef792ee9270afbf6bc128989db61f22b3195f9572387e5614cd191bc650f423e5f05c03fec083a210b1aca0faf9bcc4500528adc326
7
- data.tar.gz: edc9b636f900ba7cc7bcb6e86bb77c24a8d8c9de580802a751a777399774dcd4157cf87540af92fb05299d9c0b54106e486b86ab5bf668ea130994334a0d5f68
6
+ metadata.gz: dcc5841e2c3f56c367c20bc78946996de1b5d099392000e44d3e49662076dc85fa3aeb35648073936ca91765615ab6b78982b1ef6714a8513f9b786b6a0a96a6
7
+ data.tar.gz: 60605f80f2bb9a91ad08448ad15105c1b07924f8bd040c417702a7995b6b228d21de4e96476c6a058063461a4be0404ee9d3158ac0a44a694a926bb183ba3884
data/lib/share-counter.rb CHANGED
@@ -1,5 +1,51 @@
1
1
  class ShareCounter
2
- def self.hi
3
- puts "Hello world!"
2
+
3
+ # require 'share-counter/common'
4
+
5
+ # require 'json'
6
+ require 'rest-client'
7
+ require 'nokogiri'
8
+ require 'open-uri'
9
+
10
+ # def self.twitter url, raise_exceptions = false
11
+ # try("twitter", url, raise_exceptions) {
12
+ # extract_count from_json( "http://urls.api.twitter.com/1/urls/count.json", :url => url),
13
+ # :selector => "count"
14
+ # }
15
+ # end
16
+
17
+ # def self.facebook url, raise_exceptions = false
18
+ # try("facebook", url, raise_exceptions) {
19
+ # extract_count from_json("http://api.facebook.com/restserver.php", :v => "1.0", :method => "links.getStats",
20
+ # :urls => url, :callback => "fb_sharepro_render", :format => "json" ), :selector => "total_count"
21
+ # }
22
+ # end
23
+
24
+ # def self.linkedin url, raise_exceptions = false
25
+ # try("linkedin", url, raise_exceptions) {
26
+ # extract_count from_json("http://www.linkedin.com/cws/share-count",
27
+ # :url => url, :callback => "IN.Tags.Share.handleCount" ), :selector => "count"
28
+ # }
29
+ # end
30
+
31
+ def self.googleplus url
32
+ begin
33
+ url = "https://plusone.google.com/_/+1/fastbutton?url=" + URI::encode(url)
34
+ html = RestClient.get url
35
+ return Nokogiri::HTML.parse(html).xpath('//*[@id="aggregateCount"]').text.to_i
36
+ rescue Exception => e
37
+ puts e
38
+ end
39
+
4
40
  end
5
- end
41
+
42
+ # def self.all url
43
+ # supported_networks.inject({}) { |r, c| r[c.to_sym] = ShareCounts.send(c, url); r }
44
+ # end
45
+
46
+ # def self.selected url, selections
47
+ # selections.map{|name| name.downcase}.select{|name| supported_networks.include? name.to_s}.inject({}) {
48
+ # |r, c| r[c.to_sym] = ShareCounts.send(c, url); r }
49
+ # end
50
+
51
+ end
@@ -0,0 +1,40 @@
1
+ require 'rest-client'
2
+
3
+ #
4
+ #
5
+ # Performs an HTTP request to the given API URL with the specified params
6
+ # and within 2 seconds, and max 3 attempts
7
+ #
8
+ # If a :callback param is also specified, then it is assumed that the API
9
+ # returns a JSON text wrapped in a call to a method by that callback name,
10
+ # therefore in this case it manipulates the response to extract only
11
+ # the JSON data required.
12
+ #
13
+ def make_request *args
14
+ result = nil
15
+ attempts = 1
16
+ url = args.shift
17
+ params = args.inject({}) { |r, c| r.merge! c }
18
+
19
+ begin
20
+ response = RestClient.get url, { :params => params, :timeout => 5 }
21
+
22
+ # if a callback is specified, the expected response is in the format "callback_name(JSON data)";
23
+ # with the response ending with ";" and, in some cases, "\n"
24
+ #Strip off the preceeding /**/
25
+ result = params.keys.include?(:callback) \
26
+ ? response.gsub(/\A\/\*\*\/\s+/, "").gsub(/^(.*);+\n*$/, "\\1").gsub(/^#{params[:callback]}\((.*)\)$/, "\\1") \
27
+ : response
28
+
29
+ rescue Exception => e
30
+ puts "Failed #{attempts} attempt(s) - #{e}"
31
+ attempts += 1
32
+ if attempts <= 3
33
+ retry
34
+ else
35
+ raise Exception
36
+ end
37
+ end
38
+
39
+ result
40
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: share-counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ollie Glass
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-12-20 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0
13
27
  description: Check how many times a page/URL has been shared on social networks and
14
28
  aggregators
15
29
  email: ollieglaskovik@gmail.com
@@ -18,6 +32,7 @@ extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
20
34
  - lib/share-counter.rb
35
+ - lib/share-counter/common.rb
21
36
  homepage: http://rubygems.org/gems/share-counter
22
37
  licenses:
23
38
  - MIT
@@ -38,9 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
53
  version: '0'
39
54
  requirements: []
40
55
  rubyforge_project:
41
- rubygems_version: 2.1.5
56
+ rubygems_version: 2.1.11
42
57
  signing_key:
43
58
  specification_version: 4
44
59
  summary: Share
45
60
  test_files: []
46
- has_rdoc: