virility 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 554a235ea250af95894241a6e9355737a26bee66
4
- data.tar.gz: c3a69e3f7d9b7e54ee8eac49e49eb1e488c29ab1
3
+ metadata.gz: 86bc24a712fad94c529ca1640b612f09d4545ab3
4
+ data.tar.gz: 37590a9fb4e07de2f51c60b41cabf1fd04f2fcf7
5
5
  SHA512:
6
- metadata.gz: cead613eadceaec0a0f9d2535e9ab44c585e96a17a6906b22c911b20625494db85a4b80b87e9515392eda63b39d04c801ad096fb816c675ee78fbbbdd8f29beb
7
- data.tar.gz: 07c0df627f75818bce04941e27fdb88d754a0b66c36e3dd917da84028d705650911ad4ff2d3df4b40e24c15e4b881712fad5dba375d28f58d743c6e303d6afc7
6
+ metadata.gz: a75fa6211d092f128bf8c5a18d58d8abf9958b913cdb345bc2ea18aa122aab731a9289836cc7ea5b1f4367e93f68c43588ee1cc67252053100e7792374b648b7
7
+ data.tar.gz: b2001fb8c82f13e8e70a9091e3435de30573cd3de0b520e8610c16b19d980c9fc4c2b82a0ad5c06e28d6f9a2be4637b4941855544be00e342bc6f10ac45a28e8
@@ -1 +1 @@
1
- ruby-2.2.4
1
+ ruby-2.3.1
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Jay Sanders
1
+ Copyright (c) 2016 Jay Sanders
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Virility
2
2
 
3
- Virility calls upon the API's of many popular social services such as Facebook, Twitter and Pinterest to collect the number of likes, tweets, pins etc. of a particular URL. Written with a modular construction, Virility makes it easy to drop new data collection strategies into the framework so that you can collect all of your statistics in one easy location.
3
+ Virility calls upon the API's of many popular social services such as Facebook, Reddit and Pinterest to collect the number of likes, tweets, pins etc. of a particular URL. Written with a modular construction, Virility makes it easy to drop new data collection strategies into the framework so that you can collect all of your statistics in one easy location.
4
4
 
5
5
  View a demo online: http://virility.herokuapp.com/
6
6
 
@@ -23,7 +23,7 @@ Or install it yourself as:
23
23
  If all you need is the raw shares numbers for a URL, Virility has some very simple methods you can use right out of the box:
24
24
 
25
25
  Virility.poll("http://rubygems.org") # => Returns a hash with the collected results from all of the social network strategies
26
- Virility.counts("http://rubygems.org") # => {:delicious=>0, :facebook=>72, :pinterest=>0, :plus_one=>138, :stumble_upon=>1488, :twitter=>2322}
26
+ Virility.counts("http://rubygems.org") # => {:delicious=>0, :facebook=>72, :pinterest=>0, :plus_one=>138, :stumble_upon=>1488, :reddit=>2322}
27
27
  Virility.total("http://rubygems.org") # => 4020
28
28
  Virility.url("http://rubygems.org") # => Returns a Virility::Excitation object that you can manipulate
29
29
 
@@ -33,16 +33,17 @@ The Virility::Excitation object does the heavy lifting of collecting the data fr
33
33
 
34
34
  virility = Virility::Excitation.new("http://rubygems.org")
35
35
  virility.poll # returns a hash with the collected output of all data sources
36
- virility.counts # returns a hash of just the virility counts => {:delicious=>943, :facebook=>72, :pinterest=>0, :plusone=>137, :stumbleupon=>1488, :twitter=>2319}
36
+ virility.counts # returns a hash of just the virility counts => {:facebook=>5116303, :linkedin => 17, :pinterest=>1, :plus_one=>8, reddit:35, :stumble_upon=>4731 }
37
37
  virility.total # returns the sum of all virility counts
38
38
 
39
39
  ## Individual Strategies
40
40
 
41
41
  Currently there is support for the following social resources:
42
42
  * Facebook
43
- * Twitter
43
+ * Linkedin
44
44
  * Pinterest
45
45
  * Google Plus One
46
+ * Reddit
46
47
  * Stumble Upon
47
48
 
48
49
  Each social resource is implemented as a Virility::Strategy and contains at least three methods: poll, results and count. __poll__ does the work of querying the API to get the data and returns the same hash as the results method, __results__ returns the hashed values that were provided by the social network and __count__ pulls out the individual number of shares for that social network.
@@ -53,19 +54,25 @@ There are several ways you can access the object for an individual strategy.
53
54
 
54
55
  The Virility object has a __factory__ method that will return the strategy object:
55
56
 
56
- tweets = Virility.factory(:twitter, "http://rubygems.org") # => returns a Virility::Twitter object with the rubygems url
57
+ tweets = Virility.factory(:reddit, "http://rubygems.org") # => returns a Virility::Reddit object with the rubygems url
57
58
 
58
- You can also instate the Virility::Twitter object directly:
59
+ You can also instate the Virility::Reddit object directly:
59
60
 
60
- tweets = Virility::Twitter.new("http://rubygems.org")
61
+ tweets = Virility::Reddit.new("http://rubygems.org")
62
+
63
+ #### Ignoring Strategies
64
+
65
+ Thanks to (Storyful)[https://github.com/storyful/virility], it is now possible to specify which strategies you want to use when initializing the Excitation object. Simply pass in an array of identifiers when creating the object and only those strategies will be implemented. The default is to use all available strategies.
66
+
67
+ Virility.poll("http://rubygems.org",[:facebook,:linkedin,:pinterest])
61
68
 
62
69
  #### Individual Usage Example
63
70
 
64
- Let's say you only need to get the number of tweets for a URL, you could use the Virility::Twitter class by itself:
71
+ Let's say you only need to get the number of tweets for a URL, you could use the Virility::Reddit class by itself:
65
72
 
66
- tweets = Virility::Twitter.new("http://rubygems.org")
67
- tweets.poll # returns a hash with the collected output from Twitter => {"url"=>"http://rubygems.org/", "count"=>2319}
68
- tweets.results # returns a hash with the collected output from Twitter => {"url"=>"http://rubygems.org/", "count"=>2319}
73
+ tweets = Virility::Reddit.new("http://rubygems.org")
74
+ tweets.poll # returns a hash with the collected output from Reddit => {"url"=>"http://rubygems.org/", "count"=>2319}
75
+ tweets.results # returns a hash with the collected output from Reddit => {"url"=>"http://rubygems.org/", "count"=>2319}
69
76
  tweets.count # returns the number of tweets for that URL => 2319
70
77
 
71
78
  ## Facebook Usage
@@ -82,16 +89,14 @@ The Facebook strategy leverages the FQL query against the link_stat table. Becau
82
89
  * commentsbox_count
83
90
  * total_count (used as the default count for all Facebook activity)
84
91
 
85
- ## Dynamic Finders
86
-
87
92
  #### Virility::Excitation
88
93
 
89
94
  If you have a Virility::Excitation object, there are dynamic finders that will return the individual Virility::Strategy object for a social network. Simply call the name of the strategy against the Virility::Excitation object and that strategy will be returned:
90
95
 
91
96
  virility = Virility::Excitation.new("http://rubygems.org")
92
97
  facebook = virility.facebook
93
- twitter = virility.twitter
94
- delicious = virility.delicious
98
+ linkedin = virility.linkedin
99
+ reddit = virility.reddit
95
100
  pinterest = virility.pinterest
96
101
  plus_one = virility.plus_one
97
102
  stumble_upon = virility.stumble_upon
@@ -127,12 +132,12 @@ Compare the total count results for http://ruby-lang.org/en. One has the trailin
127
132
  On this particular day, there was a 5,495 count difference between the two values. Inspecting the actual results shows you which of the social networks takes the varying forms of the urls into account:
128
133
 
129
134
  Virility::Excitation.new("http://www.ruby-lang.org/en").counts
130
- # => {:delicious=>37, :facebook=>3, :pinterest=>0, :plusone=>20, :stumbleupon=>246937, :twitter=>698}
135
+ # => {:delicious=>37, :facebook=>3, :pinterest=>0, :plusone=>20, :stumbleupon=>246937}
131
136
 
132
137
  Virility::Excitation.new("http://www.ruby-lang.org/en/").counts
133
- # => {:delicious=>4314, :facebook=>813, :pinterest=>22, :plusone=>406, :stumbleupon=>246937, :twitter=>698}
138
+ # => {:delicious=>4314, :facebook=>813, :pinterest=>22, :plusone=>406, :stumbleupon=>246937}
134
139
 
135
- Stumbleupon and Twitter are consistent while Facebook, Pinterest and Google Plus One return different results. Depending on your needs, you could craft an algorithm that takes all of this into account and attempts to deliver an accurate number by combining the data sets that are different and trusting the ones that are the same.
140
+ Stumbleupon is consistent while Facebook, Pinterest and Google Plus One return different results. Depending on your needs, you could craft an algorithm that takes all of this into account and attempts to deliver an accurate number by combining the data sets that are different and trusting the ones that are the same.
136
141
 
137
142
  Based on this logic, it is possible to consider that the true total share count is closer to _253,250_. Not only is this an opinionated number, it's accuracy is questionable based on assumptions, however if you are just trying to get a ballpark feeling of the virility of your content, this number should suffice.
138
143
 
@@ -146,5 +151,5 @@ Based on this logic, it is possible to consider that the true total share count
146
151
 
147
152
  ## Copyright
148
153
 
149
- Copyright (c) 2012 Jay Sanders. See LICENSE.txt for
154
+ Copyright (c) 2016 Jay Sanders. See LICENSE.txt for
150
155
  further details.
@@ -16,20 +16,20 @@ module Virility
16
16
  # Public API
17
17
  #
18
18
 
19
- def self.counts(url)
20
- Virility::Excitation.new(url).counts
19
+ def self.counts(url, strategies = [])
20
+ Virility::Excitation.new(url, strategies).counts
21
21
  end
22
22
 
23
- def self.total(url)
24
- Virility::Excitation.new(url).total
23
+ def self.total(url, strategies = [])
24
+ Virility::Excitation.new(url, strategies).total
25
25
  end
26
26
 
27
- def self.poll(url)
28
- Virility::Excitation.new(url).poll
27
+ def self.poll(url, strategies = [])
28
+ Virility::Excitation.new(url, strategies).poll
29
29
  end
30
30
 
31
- def self.url(url)
32
- virility = Virility::Excitation.new(url)
31
+ def self.url(url, strategies = [])
32
+ virility = Virility::Excitation.new(url, strategies)
33
33
  virility.poll
34
34
  virility
35
35
  end
@@ -1,19 +1,20 @@
1
1
  module Virility
2
2
  class Excitation
3
3
  include Virility::Supporter
4
-
4
+
5
5
  attr_accessor :url, :results, :strategies, :counts
6
6
 
7
7
  #
8
8
  # Initialization
9
9
  #
10
-
11
- def initialize url
10
+ def initialize(url, strategies = [])
12
11
  @url = url
13
12
  @strategies = {}
14
13
  @results = {}
15
14
  @counts = {}
15
+ @filter_strategies = strategies || []
16
16
  collect_strategies
17
+ filter_strategies
17
18
  end
18
19
 
19
20
  #
@@ -68,6 +69,11 @@ module Virility
68
69
  Dir["#{File.dirname(__FILE__)}/strategies/**/*.rb"].each { |klass| @strategies[get_class_string(klass).to_sym] = Virility.const_get(camelize(get_class_string(klass))).new(@url) }
69
70
  end
70
71
 
72
+ def filter_strategies
73
+ return if @filter_strategies.empty?
74
+ @strategies.select! { |k, _v| @filter_strategies.include?(k) }
75
+ end
76
+
71
77
  #
72
78
  # Reflection
73
79
  #
@@ -101,4 +107,4 @@ module Virility
101
107
  end
102
108
 
103
109
  end
104
- end
110
+ end
@@ -1,24 +1,23 @@
1
1
  module Virility
2
2
  class Facebook < Strategy
3
- BASE_URL = "https://api.facebook.com/method/fql.query?query=SELECT+share_count%2C+like_count%2C+comment_count%2C+total_count%2C+commentsbox_count%2C+click_count+FROM+link_stat+WHERE+url%3D"
4
-
3
+ BASE_URL = "https://api.facebook.com/method/links.getStats?urls="
5
4
  def census
6
- self.class.get("#{BASE_URL}%22#{@url}%22")
5
+ self.class.get("#{BASE_URL}#{@url}")
7
6
  end
8
-
7
+
9
8
  def outcome
10
- @response.parsed_response["fql_query_response"]["link_stat"]
9
+ @response.parsed_response["links_getStats_response"]["link_stat"]
11
10
  end
12
11
 
13
12
  def count
14
13
  results["total_count"] || 0
15
14
  end
16
-
15
+
17
16
  private
18
-
17
+
19
18
  def valid_response_test
20
- @response.respond_to?(:parsed_response) and @response.parsed_response.is_a?(Hash) and !@response.parsed_response["fql_query_response"].nil? and !@response.parsed_response["fql_query_response"]["link_stat"].nil?
19
+ @response.respond_to?(:parsed_response) and @response.parsed_response.is_a?(Hash) and !@response.parsed_response["links_getStats_response"].nil? and !@response.parsed_response["links_getStats_response"]["link_stat"].nil?
21
20
  end
22
21
 
23
22
  end
24
- end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Virility
2
+ class Linkedin < Strategy
3
+
4
+ parser(
5
+ Proc.new do |body, format|
6
+ MultiJson.decode(body.scan(/(\{.+\})/).flatten.first)
7
+ end
8
+ )
9
+
10
+ def census
11
+ self.class.get("http://www.linkedin.com/countserv/count/share?url=#{@original_url}&format=json")
12
+ end
13
+
14
+ def count
15
+ results[:count] || 0
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Virility
2
+ class Reddit < Strategy
3
+ def outcome
4
+ score = @response.parsed_response['data']['children'].map { |c| c['data']['score']}.reduce(:+) || 0
5
+ { 'score' => score }
6
+ end
7
+
8
+ def census
9
+ self.class.get("http://www.reddit.com/api/info.json?&url=#{@url}")
10
+ end
11
+
12
+ def count
13
+ results['score'] || 0
14
+ end
15
+
16
+ private
17
+
18
+ def valid_response_test
19
+ @response.respond_to?(:parsed_response) && @response.parsed_response.is_a?(Hash) && !@response.parsed_response['data'].nil? && !@response.parsed_response['data']['children'].map { |c| c['data']['score']}.nil?
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Virility
2
- VERSION = "0.2.0"
3
- end
2
+ VERSION = "0.3.0"
3
+ end
@@ -11,7 +11,7 @@ describe "Excitation" do
11
11
 
12
12
  context "initialization" do
13
13
  it "should raise an error if a URL is not set" do
14
- expect{Virility::Excitation.new}.to raise_error(ArgumentError, "wrong number of arguments (0 for 1)")
14
+ expect{Virility::Excitation.new}.to raise_error(ArgumentError, "wrong number of arguments (given 0, expected 1..2)")
15
15
  end
16
16
  end
17
17
 
@@ -111,4 +111,4 @@ describe "Excitation" do
111
111
  end
112
112
  end
113
113
  end
114
- end
114
+ end
@@ -21,12 +21,13 @@ end
21
21
  module Virility
22
22
  TESTING_STRATEGIES = {
23
23
  :facebook => Virility::Facebook,
24
- :twitter => Virility::Twitter,
25
24
  :pinterest => Virility::Pinterest,
26
25
  :plus_one => Virility::PlusOne,
27
- :stumble_upon => Virility::StumbleUpon
26
+ :stumble_upon => Virility::StumbleUpon,
27
+ :linkedin => Virility::Linkedin,
28
+ :reddit => Virility::Reddit
28
29
  }
29
- FAKE_TESTING_STRATEGIES = [:digg, :reddit, :linked_in, :instagram, :tumblr]
30
+ FAKE_TESTING_STRATEGIES = [:digg, :instagram, :tumblr]
30
31
 
31
32
  FB_RESULTS = {"like_count"=>"19", "click_count"=>"0", "share_count"=>"3", "comment_count"=>"0", "commentsbox_count"=>"0", "total_count"=>"22"}
32
33
  FAKE_FB_RESULTS = [:face_count, :pages, :friends]
@@ -44,4 +45,4 @@ RSpec.shared_examples "no context results" do
44
45
  it "should return 0 for count" do
45
46
  expect(@virility.count).to eq(0)
46
47
  end
47
- end
48
+ end
@@ -20,7 +20,7 @@ describe "Virility::Facebook" do
20
20
  describe "poll" do
21
21
  context "when there is not a valid result" do
22
22
  before(:each) do
23
- response = double("HTTParty::Response", :parsed_response => {"fql_query_response"=>{"list"=>"true"}})
23
+ response = double("HTTParty::Response", :parsed_response => {"links_getStats_response"=>{"list"=>"true"}})
24
24
  allow(Virility::Facebook).to receive(:get) { response }
25
25
  @virility = Virility::Facebook.new(@url)
26
26
  end
@@ -38,7 +38,7 @@ describe "Virility::Facebook" do
38
38
  it_should_behave_like "no facebook results"
39
39
  end
40
40
 
41
- context "when there is a result but no fql_query_response" do
41
+ context "when there is a result but no links_getStats_response" do
42
42
  before(:each) do
43
43
  response = double("HTTParty::Response", :parsed_response => {})
44
44
  allow(Virility::Facebook).to receive(:get) { response }
@@ -60,7 +60,7 @@ describe "Virility::Facebook" do
60
60
 
61
61
  context "when there is a valid result" do
62
62
  before(:each) do
63
- response = double("HTTParty::Response", :parsed_response => {"fql_query_response"=>{"list"=>"true", "link_stat"=>{"like_count"=>"977662", "click_count"=>"265614", "share_count"=>"3020040", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"}}})
63
+ response = double("HTTParty::Response", :parsed_response => {"links_getStats_response"=>{"list"=>"true", "link_stat"=>{"like_count"=>"977662", "click_count"=>"265614", "share_count"=>"3020040", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"}}})
64
64
  allow(Virility::Facebook).to receive(:get) { response }
65
65
  @virility = Virility::Facebook.new(@url)
66
66
  end
@@ -78,7 +78,7 @@ describe "Virility::Facebook" do
78
78
 
79
79
  context "when there is a valid result, but not all fields are present" do
80
80
  before(:each) do
81
- response = double("HTTParty::Response", :parsed_response => {"fql_query_response"=>{"list"=>"true", "link_stat"=>{"like_count"=>"977662", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"}}})
81
+ response = double("HTTParty::Response", :parsed_response => {"links_getStats_response"=>{"list"=>"true", "link_stat"=>{"like_count"=>"977662", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"}}})
82
82
  allow(Virility::Facebook).to receive(:get) { response }
83
83
  @virility = Virility::Facebook.new(@url)
84
84
  end
@@ -95,4 +95,4 @@ describe "Virility::Facebook" do
95
95
  end
96
96
  end
97
97
 
98
- end
98
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Virility::Twitter" do
3
+ describe "Virility::Linkedin" do
4
4
  before(:each) do
5
5
  @url = "http://creativeallies.com"
6
6
  end
@@ -9,8 +9,8 @@ describe "Virility::Twitter" do
9
9
  context "when there is not a valid result" do
10
10
  before(:each) do
11
11
  response = double("HTTParty::Response", :parsed_response => {"fake_return_value"=> "OICU812"})
12
- allow(Virility::Twitter).to receive(:get) { response }
13
- @virility = Virility::Twitter.new(@url)
12
+ allow(Virility::Linkedin).to receive(:get) { response }
13
+ @virility = Virility::Linkedin.new(@url)
14
14
  end
15
15
 
16
16
  it_should_behave_like "no context results"
@@ -19,8 +19,8 @@ describe "Virility::Twitter" do
19
19
  context "when there is no result" do
20
20
  before(:each) do
21
21
  response = double("HTTParty::Response")
22
- allow(Virility::Twitter).to receive(:get) { response }
23
- @virility = Virility::Twitter.new(@url)
22
+ allow(Virility::Linkedin).to receive(:get) { response }
23
+ @virility = Virility::Linkedin.new(@url)
24
24
  end
25
25
 
26
26
  it_should_behave_like "no context results"
@@ -29,8 +29,8 @@ describe "Virility::Twitter" do
29
29
  context "when there is a result but no specific hash value" do
30
30
  before(:each) do
31
31
  response = double("HTTParty::Response", :parsed_response => {})
32
- allow(Virility::Twitter).to receive(:get) { response }
33
- @virility = Virility::Twitter.new(@url)
32
+ allow(Virility::Linkedin).to receive(:get) { response }
33
+ @virility = Virility::Linkedin.new(@url)
34
34
  end
35
35
 
36
36
  it_should_behave_like "no context results"
@@ -39,8 +39,8 @@ describe "Virility::Twitter" do
39
39
  context "when there is a result but parsed_response is weird" do
40
40
  before(:each) do
41
41
  response = double("HTTParty::Response", :parsed_response => Object.new)
42
- allow(Virility::Twitter).to receive(:get) { response }
43
- @virility = Virility::Twitter.new(@url)
42
+ allow(Virility::Linkedin).to receive(:get) { response }
43
+ @virility = Virility::Linkedin.new(@url)
44
44
  end
45
45
 
46
46
  it_should_behave_like "no context results"
@@ -48,19 +48,18 @@ describe "Virility::Twitter" do
48
48
 
49
49
  context "when there is a valid result" do
50
50
  before(:each) do
51
- response = double("HTTParty::Response", :parsed_response => {"count"=>121, "url"=>"http://creativeallies.com/"})
52
- allow(Virility::Twitter).to receive(:get) { response }
53
- @virility = Virility::Twitter.new(@url)
51
+ response = double("HTTParty::Response", :parsed_response => { "count":17, "fCnt":"17", "fCntPlusOne":"18", "url":"http:\/\/creativeallies.com" })
52
+ allow(Virility::Linkedin).to receive(:get) { response }
53
+ @virility = Virility::Linkedin.new(@url)
54
54
  end
55
55
 
56
56
  it "should not raise an error" do
57
57
  expect{ @virility.poll }.not_to raise_error
58
58
  end
59
59
 
60
- it "should return 121 for the count" do
61
- expect(@virility.count).to eq(121)
60
+ it "should return 17 for the count" do
61
+ expect(@virility.count).to eq(17)
62
62
  end
63
63
  end
64
64
  end
65
-
66
65
  end
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Virility::Reddit" do
4
+ before(:each) do
5
+ @url = "http://creativeallies.com"
6
+ end
7
+
8
+ describe "poll" do
9
+ context "when there is not a valid result" do
10
+ before(:each) do
11
+ response = double("HTTParty::Response", :parsed_response => {"fake_return_value" => "OICU812"})
12
+ allow(Virility::Reddit).to receive(:get) { response }
13
+ @virility = Virility::Reddit.new(@url)
14
+ end
15
+ it_should_behave_like "no context results"
16
+ end
17
+
18
+ context "when there is no result" do
19
+ before(:each) do
20
+ response = double("HTTParty::Response")
21
+ allow(Virility::Reddit).to receive(:get) { response }
22
+ @virility = Virility::Reddit.new(@url)
23
+ end
24
+ it_should_behave_like "no context results"
25
+ end
26
+
27
+ context "when there is a result but no specific hash value" do
28
+ before(:each) do
29
+ response = double("HTTParty::Response", :parsed_response => {})
30
+ allow(Virility::Reddit).to receive(:get) { response }
31
+ @virility = Virility::Reddit.new(@url)
32
+ end
33
+ it_should_behave_like "no context results"
34
+ end
35
+
36
+ context "when there is a result but parsed_response is weird" do
37
+ before(:each) do
38
+ response = double("HTTParty::Response", :parsed_response => Object.new)
39
+ allow(Virility::Reddit).to receive(:get) { response }
40
+ @virility = Virility::Reddit.new(@url)
41
+ end
42
+
43
+ it_should_behave_like "no context results"
44
+ end
45
+
46
+ context "when there is a valid result" do
47
+ before(:each) do
48
+ response = double("HTTParty::Response", :parsed_response =>
49
+ { "kind" => "Listing",
50
+ "data" => {
51
+ "modhash" => "",
52
+ "children" =>
53
+ [{ "kind" => "t3", "data" => { "score" => 35 } }]
54
+ }
55
+ }
56
+ )
57
+ allow(Virility::Reddit).to receive(:get) { response }
58
+ @virility = Virility::Reddit.new(@url)
59
+ end
60
+
61
+ it "should not raise an error" do
62
+ expect{ @virility.poll }.not_to raise_error
63
+ end
64
+
65
+ it "should return 35 for the count" do
66
+ expect(@virility.count).to eq(35)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -11,7 +11,7 @@ describe "Strategy" do
11
11
 
12
12
  context "initialization" do
13
13
  it "should raise an error if a URL is not set" do
14
- expect{Virility::Strategy.new}.to raise_error(ArgumentError, "wrong number of arguments (0 for 1)")
14
+ expect{Virility::Strategy.new}.to raise_error(ArgumentError, "wrong number of arguments (given 0, expected 1)")
15
15
  end
16
16
 
17
17
  it "should set and encode the url" do
@@ -31,20 +31,20 @@ describe "Virility" do
31
31
  describe "Public API testing" do
32
32
  before(:each) do
33
33
  @url = "http://creativeallies.com"
34
- allow(Virility::Facebook).to receive(:get) { double("HTTParty::Response", :parsed_response => {"fql_query_response"=>{"list"=>"true", "link_stat"=>{"like_count"=>"977662", "click_count"=>"265614", "share_count"=>"3020040", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"}}}) }
34
+ allow(Virility::Facebook).to receive(:get) { double("HTTParty::Response", :parsed_response => {"links_getStats_response"=>{"list"=>"true", "link_stat"=>{"like_count"=>"977662", "click_count"=>"265614", "share_count"=>"3020040", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"}}}) }
35
35
  allow(Virility::Pinterest).to receive(:get) { double("HTTParty::Response", :parsed_response => {"count"=>1, "url"=>"http://creativeallies.com"}) }
36
36
  allow(Virility::PlusOne).to receive(:get) { double("HTTParty::Response", :parsed_response => {"shares"=>"8"}) }
37
37
  allow(Virility::StumbleUpon).to receive(:get) { double("HTTParty::Response", :parsed_response => {"url"=>"http://creativeallies.com/", "in_index"=>true, "publicid"=>"2UhTwK", "views"=>4731, "title"=>"Creative Allies | Create Art For Rockstars | Upload For A Chance To Win", "thumbnail"=>"http://cdn.stumble-upon.com/mthumb/388/49348388.jpg", "thumbnail_b"=>"http://cdn.stumble-upon.com/images/nobthumb.png", "submit_link"=>"http://www.stumbleupon.com/submit/?url=http://creativeallies.com/", "badge_link"=>"http://www.stumbleupon.com/badge/?url=http://creativeallies.com/", "info_link"=>"http://www.stumbleupon.com/url/creativeallies.com/"}) }
38
- allow(Virility::Twitter).to receive(:get) { double("HTTParty::Response", :parsed_response => {"count"=>121, "url"=>"http://creativeallies.com/"}) }
39
38
  allow(Virility::Linkedin).to receive(:get) { double("HTTParty::Response", :parsed_response => { "count":17, "fCnt":"17", "fCntPlusOne":"18", "url":"http:\/\/creativeallies.com" }) }
39
+ allow(Virility::Reddit).to receive(:get) { double("HTTParty::Response", :parsed_response => { "data" => { "children" => [{ "data" => { "domain" => "apple.com", "banned_by" => nil, "media_embed" => {}, "num_reports" => nil, "score" => 1}}, { "data" => { "domain" => "apple.com", "banned_by" => nil, "media_embed" => {}, "num_reports" => nil, "score" => 34 }}]}})}
40
40
  end
41
41
 
42
42
  it "Virility.counts should return a hash of counts" do
43
- expect(Virility.counts(@url)).to eq({:facebook=>5116303, :linkedin => 17, :pinterest=>1, :plus_one=>8, :stumble_upon=>4731, :twitter=>121})
43
+ expect(Virility.counts(@url)).to eq({:facebook=>5116303, :linkedin => 17, :pinterest=>1, :plus_one=>8, reddit:35, :stumble_upon=>4731 })
44
44
  end
45
45
 
46
46
  it "Virility.total should return the total count" do
47
- expect(Virility.total(@url)).to eq(5121181)
47
+ expect(Virility.total(@url)).to eq(5121095)
48
48
  end
49
49
 
50
50
  it "Virility.poll should return all of the hashed responses" do
@@ -54,7 +54,16 @@ describe "Virility" do
54
54
  :pinterest=>{"count"=>1, "url"=>"http://creativeallies.com"},
55
55
  :plus_one=>{"shares"=>"8"},
56
56
  :stumble_upon=>{"url"=>"http://creativeallies.com/", "in_index"=>true, "publicid"=>"2UhTwK", "views"=>4731, "title"=>"Creative Allies | Create Art For Rockstars | Upload For A Chance To Win", "thumbnail"=>"http://cdn.stumble-upon.com/mthumb/388/49348388.jpg", "thumbnail_b"=>"http://cdn.stumble-upon.com/images/nobthumb.png", "submit_link"=>"http://www.stumbleupon.com/submit/?url=http://creativeallies.com/", "badge_link"=>"http://www.stumbleupon.com/badge/?url=http://creativeallies.com/", "info_link"=>"http://www.stumbleupon.com/url/creativeallies.com/"},
57
- :twitter=>{"count"=>121, "url"=>"http://creativeallies.com/"}
57
+ :reddit=>{"score"=>35 }
58
+ })
59
+ end
60
+ it "Virility.poll should return all of the hashed responses with filtered strategies only" do
61
+ expect(Virility.poll(@url,[:facebook,:linkedin,:pinterest,:plus_one,:stumble_upon])).to eq({
62
+ :facebook=>{"like_count"=>"977662", "click_count"=>"265614", "share_count"=>"3020040", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"},
63
+ :linkedin=>{ "count":17, "fCnt":"17", "fCntPlusOne":"18", "url":"http:\/\/creativeallies.com" },
64
+ :pinterest=>{"count"=>1, "url"=>"http://creativeallies.com"},
65
+ :plus_one=>{"shares"=>"8"},
66
+ :stumble_upon=>{"url"=>"http://creativeallies.com/", "in_index"=>true, "publicid"=>"2UhTwK", "views"=>4731, "title"=>"Creative Allies | Create Art For Rockstars | Upload For A Chance To Win", "thumbnail"=>"http://cdn.stumble-upon.com/mthumb/388/49348388.jpg", "thumbnail_b"=>"http://cdn.stumble-upon.com/images/nobthumb.png", "submit_link"=>"http://www.stumbleupon.com/submit/?url=http://creativeallies.com/", "badge_link"=>"http://www.stumbleupon.com/badge/?url=http://creativeallies.com/", "info_link"=>"http://www.stumbleupon.com/url/creativeallies.com/"}
58
67
  })
59
68
  end
60
69
 
@@ -75,7 +84,7 @@ describe "Virility" do
75
84
  it "should return 0 for all strategy counts" do
76
85
  @virility = Virility.url("http://this.is.a.crap.url")
77
86
  expect(@virility.total).to eq(0)
78
- expect(@virility.counts).to eq({:facebook=>0, :linkedin=>0, :pinterest=>0, :plus_one=>0, :stumble_upon=>0, :twitter=>0})
87
+ expect(@virility.counts).to eq({:facebook=>0, :linkedin=>0, :pinterest=>0, :plus_one=>0, :reddit=>0, :stumble_upon=>0 })
79
88
  end
80
89
  end
81
90
  end
@@ -10,8 +10,9 @@ Gem::Specification.new do |gem|
10
10
  gem.authors = ["Jay Sanders"]
11
11
  gem.email = ["jay@allieslabs.com"]
12
12
  gem.description = "Virility leverages the API's of many popular social services to collect data about the virility of a particular URL."
13
- gem.summary = "Virility calls upon the API's of many popular social services such as Facebook, Twitter and Pinterest to collect the number of likes, tweets and pins of a particular URL. Written with a modular construction, Virility makes it easy to drop new data collection strategies into the framework so that you can collect all of your statistics in one easy location."
13
+ gem.summary = "Virility calls upon the API's of many popular social services such as Facebook, Reddit and Pinterest to collect the number of likes, tweets and pins of a particular URL. Written with a modular construction, Virility makes it easy to drop new data collection strategies into the framework so that you can collect all of your statistics in one easy location."
14
14
  gem.homepage = "http://github.com/mindtonic/virility"
15
+ gem.licenses = ['MIT', 'Beerware']
15
16
  # Files
16
17
  gem.files = `git ls-files`.split($/)
17
18
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Sanders
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -86,25 +86,29 @@ files:
86
86
  - lib/virility/exceptions.rb
87
87
  - lib/virility/excitation.rb
88
88
  - lib/virility/strategies/facebook.rb
89
+ - lib/virility/strategies/linkedin.rb
89
90
  - lib/virility/strategies/pinterest.rb
90
91
  - lib/virility/strategies/plus_one.rb
92
+ - lib/virility/strategies/reddit.rb
91
93
  - lib/virility/strategies/stumble_upon.rb
92
- - lib/virility/strategies/twitter.rb
93
94
  - lib/virility/strategy.rb
94
95
  - lib/virility/supporter.rb
95
96
  - lib/virility/version.rb
96
97
  - spec/excitation_spec.rb
97
98
  - spec/spec_helper.rb
98
99
  - spec/strategies/facebook_spec.rb
100
+ - spec/strategies/linkedin_spec.rb
99
101
  - spec/strategies/pinterest_spec.rb
100
102
  - spec/strategies/plus_one_spec.rb
103
+ - spec/strategies/reddit_spec.rb
101
104
  - spec/strategies/stumble_upon_spec.rb
102
- - spec/strategies/twitter_spec.rb
103
105
  - spec/strategy_spec.rb
104
106
  - spec/virility_spec.rb
105
107
  - virility.gemspec
106
108
  homepage: http://github.com/mindtonic/virility
107
- licenses: []
109
+ licenses:
110
+ - MIT
111
+ - Beerware
108
112
  metadata: {}
109
113
  post_install_message:
110
114
  rdoc_options: []
@@ -122,11 +126,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
126
  version: '0'
123
127
  requirements: []
124
128
  rubyforge_project:
125
- rubygems_version: 2.4.8
129
+ rubygems_version: 2.5.1
126
130
  signing_key:
127
131
  specification_version: 4
128
132
  summary: Virility calls upon the API's of many popular social services such as Facebook,
129
- Twitter and Pinterest to collect the number of likes, tweets and pins of a particular
133
+ Reddit and Pinterest to collect the number of likes, tweets and pins of a particular
130
134
  URL. Written with a modular construction, Virility makes it easy to drop new data
131
135
  collection strategies into the framework so that you can collect all of your statistics
132
136
  in one easy location.
@@ -134,9 +138,10 @@ test_files:
134
138
  - spec/excitation_spec.rb
135
139
  - spec/spec_helper.rb
136
140
  - spec/strategies/facebook_spec.rb
141
+ - spec/strategies/linkedin_spec.rb
137
142
  - spec/strategies/pinterest_spec.rb
138
143
  - spec/strategies/plus_one_spec.rb
144
+ - spec/strategies/reddit_spec.rb
139
145
  - spec/strategies/stumble_upon_spec.rb
140
- - spec/strategies/twitter_spec.rb
141
146
  - spec/strategy_spec.rb
142
147
  - spec/virility_spec.rb
@@ -1,13 +0,0 @@
1
- module Virility
2
- class Twitter < Strategy
3
-
4
- def census
5
- self.class.get("http://urls.api.twitter.com/1/urls/count.json?url=#{@url}")
6
- end
7
-
8
- def count
9
- results["count"] || 0
10
- end
11
-
12
- end
13
- end