sharer 0.0.2 → 0.0.3

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.
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 1.9.2
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'rake'
4
-
5
3
  gemspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Sharer
1
+ # Sharer [![Build Status](https://secure.travis-ci.org/14113/sharer.png?branch=master)](http://travis-ci.org/14113/sharer)
2
2
 
3
3
  If your application needs to count the number of shared, this gem can help you.
4
4
 
@@ -13,19 +13,23 @@ gem "sharer"
13
13
 
14
14
  Sharer's Git repo is available on GitHub, which can be browsed at:
15
15
 
16
- http://github.com/14113/Sharer
16
+ ```ruby
17
+ http://github.com/14113/Sharer
18
+ ```
17
19
 
18
20
  and cloned with:
19
21
 
20
- git clone git://github.com/14113/sharer.git
21
-
22
+ ```ruby
23
+ git clone git://github.com/14113/sharer.git
24
+ ```
22
25
 
23
26
  ## Usage
24
27
 
25
28
  Call Sharer in an Model and pass the url of the website.
26
29
 
27
30
  ```ruby
28
- result = Sharer.find("google.com")
31
+ site = Sharer::Site.new("google.com")
32
+ number_of_likes = site.facebook_likes
29
33
  ```
30
34
 
31
35
  This will find count of shareing in facebook, twitter abd linkedin.
@@ -1,3 +1,3 @@
1
1
  module Sharer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/sharer.rb CHANGED
@@ -6,49 +6,52 @@ require 'rexml/document'
6
6
 
7
7
  module Sharer
8
8
 
9
- class << self
9
+ class Site
10
10
 
11
+ def initialize url
12
+ @url = url
13
+ end
14
+
11
15
  # 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
+ def facebook_likes
17
+ return nil unless valid_url?
18
+ path = "http://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22#{@url}%22"
16
19
  content = content(path)
17
20
  root = REXML::Document.new(content)
18
21
  root.elements[1].elements["link_stat/like_count"].text.to_i
19
22
  end
20
23
 
21
24
  # 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
+ def twitter_button
26
+ return nil unless valid_url?
27
+ path = "http://urls.api.twitter.com/1/urls/count.json?url=#{@url}"
25
28
  content(path).match(/\"count\":([0-9]*),/)[1].to_i
26
29
  end
27
30
 
28
31
  # 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
+ def linked_in_share
33
+ return nil unless valid_url?
34
+ path = "http://www.linkedin.com/countserv/count/share?url=#{@url}&callback=myCallback&format=json"
32
35
  content(path).match(/\"count\":([0-9]*),/)[1].to_i
33
36
  end
34
37
 
35
38
  # Find shareing by url
36
- def find url
37
- return nil unless valid_url? url
39
+ def find
40
+ return nil unless valid_url?
38
41
 
39
42
  data = {}
40
43
  threads = []
41
44
 
42
45
  threads << Thread.new do
43
- data["facebook"] = facebook_likes url
46
+ data["facebook"] = facebook_likes
44
47
  end
45
48
 
46
49
  threads << Thread.new do
47
- data["google"] = self.twitter_button url
50
+ data["google"] = self.twitter_button
48
51
  end
49
52
 
50
53
  threads << Thread.new do
51
- data["twitter"] = self.linked_in_share url
54
+ data["twitter"] = self.linked_in_share
52
55
  end
53
56
 
54
57
  threads.each {|t| t.join }
@@ -58,14 +61,14 @@ module Sharer
58
61
 
59
62
  private
60
63
  # Valid url
61
- def valid_url? url
62
- (url =~ URI::regexp).nil?
64
+ def valid_url?
65
+ (@url =~ URI::regexp).nil?
63
66
  end
64
67
 
65
68
  # Content by url
66
- def content url
69
+ def content path
67
70
  begin
68
- Net::HTTP.get_response(URI.parse(url)).body
71
+ Net::HTTP.get_response(URI.parse(path)).body
69
72
  rescue => exception
70
73
  print exception.backtrace.join("\n")
71
74
  end
data/sharer.gemspec CHANGED
@@ -18,5 +18,6 @@ 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
+ s.add_development_dependency "rake"
21
22
  s.add_development_dependency "rspec"
22
23
  end
data/spec/sharer_spec.rb CHANGED
@@ -1,24 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Sharer do
4
+
5
+ before(:all) do
6
+ @site = Sharer::Site.new("google.com")
7
+ end
8
+
4
9
  it "find count of likes on facebook" do
5
- Sharer.facebook_likes("google.com").should be_a(Integer)
10
+ @site.facebook_likes.should be_a(Integer)
11
+ @site.facebook_likes.should > 0
6
12
  end
7
13
 
8
14
  it "find count of likes on twitter" do
9
- Sharer.twitter_button("google.com").should be_a(Integer)
15
+ @site.twitter_button.should be_a(Integer)
16
+ @site.twitter_button.should > 0
10
17
  end
11
18
 
12
19
  it "find count of likes on twitter" do
13
- Sharer.linked_in_share("google.com").should be_a(Integer)
20
+ @site.linked_in_share.should be_a(Integer)
21
+ @site.linked_in_share.should > 0
14
22
  end
15
23
 
16
24
  it "find count of shareing in facebook,twitter and linkedin" do
17
- Sharer.find("google.com").should be_a(Hash)
25
+ @site.find.should be_a(Hash)
18
26
  end
19
27
 
20
28
  it "find count of likes on facebook by invalid url" do
21
- Sharer.facebook_likes("ada:example/com").should eq(nil)
29
+ @site = Sharer::Site.new("ada:example/com")
30
+ @site.facebook_likes.should eq(nil)
22
31
  end
23
32
 
24
33
  end
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,9 +11,20 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-04-22 00:00:00.000000000Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70116654114500 !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: *70116654114500
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rspec
16
- requirement: &70217497905120 !ruby/object:Gem::Requirement
27
+ requirement: &70116654114040 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,7 +32,7 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *70217497905120
35
+ version_requirements: *70116654114040
25
36
  description: If your application needs to count the number of shared, this gem can
26
37
  help you.
27
38
  email:
@@ -32,6 +43,7 @@ extra_rdoc_files: []
32
43
  files:
33
44
  - .gitignore
34
45
  - .rspec
46
+ - .travis.yml
35
47
  - CHANGELOG.md
36
48
  - Gemfile
37
49
  - LICENCE
@@ -56,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
68
  version: '0'
57
69
  segments:
58
70
  - 0
59
- hash: 4557104551091993199
71
+ hash: 4518542178563020029
60
72
  required_rubygems_version: !ruby/object:Gem::Requirement
61
73
  none: false
62
74
  requirements:
@@ -65,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
77
  version: '0'
66
78
  segments:
67
79
  - 0
68
- hash: 4557104551091993199
80
+ hash: 4518542178563020029
69
81
  requirements: []
70
82
  rubyforge_project: sharer
71
83
  rubygems_version: 1.8.10