popularity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +3 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +126 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +92 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/popularity.rb +92 -0
- data/lib/popularity/crawler.rb +76 -0
- data/lib/popularity/facebook.rb +26 -0
- data/lib/popularity/github.rb +28 -0
- data/lib/popularity/google_plus.rb +22 -0
- data/lib/popularity/medium.rb +33 -0
- data/lib/popularity/pinterest.rb +21 -0
- data/lib/popularity/reddit_comment.rb +32 -0
- data/lib/popularity/reddit_post.rb +47 -0
- data/lib/popularity/reddit_share.rb +72 -0
- data/lib/popularity/results_container.rb +70 -0
- data/lib/popularity/search.rb +79 -0
- data/lib/popularity/soundcloud.rb +44 -0
- data/lib/popularity/twitter.rb +21 -0
- data/popularity.gemspec +124 -0
- data/spec/cassettes/facebook.yml +50 -0
- data/spec/cassettes/github-valid.yml +105 -0
- data/spec/cassettes/google_plus.yml +89 -0
- data/spec/cassettes/medium-valid.yml +110 -0
- data/spec/cassettes/pinterest.yml +44 -0
- data/spec/cassettes/reddit-comment.yml +207 -0
- data/spec/cassettes/reddit-post.yml +174 -0
- data/spec/cassettes/reddit.yml +183 -0
- data/spec/cassettes/result-container-test.yml +97 -0
- data/spec/cassettes/search-multi.yml +1211 -0
- data/spec/cassettes/search.yml +598 -0
- data/spec/cassettes/soundcloud-valid.yml +682 -0
- data/spec/cassettes/twitter.yml +64 -0
- data/spec/cassettes/unknown-reddit-post.yml +68 -0
- data/spec/facebook_spec.rb +23 -0
- data/spec/github_spec.rb +39 -0
- data/spec/google_plus_spec.rb +27 -0
- data/spec/medium_spec.rb +47 -0
- data/spec/pinterest_spec.rb +27 -0
- data/spec/reddit_comment_spec.rb +60 -0
- data/spec/reddit_post_spec.rb +64 -0
- data/spec/reddit_spec.rb +89 -0
- data/spec/results_container_spec.rb +61 -0
- data/spec/search_spec.rb +79 -0
- data/spec/soundcloud_spec.rb +66 -0
- data/spec/spec_helper.rb +95 -0
- data/spec/twitter_spec.rb +19 -0
- data/test/facebook_test.rb +28 -0
- data/test/fixtures/vcr_cassettes/facebook.yml +50 -0
- data/test/fixtures/vcr_cassettes/google.yml +425 -0
- data/test/helper.rb +34 -0
- data/test/test_non_specific.rb +27 -0
- data/test/test_twitter.rb +28 -0
- metadata +242 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://cdn.api.twitter.com/1/urls/count.json?url=http://google.com
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip
|
14
|
+
User-Agent:
|
15
|
+
- unirest-ruby/1.1
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Thu, 09 Apr 2015 17:30:25 GMT
|
23
|
+
Server:
|
24
|
+
- tsa_a
|
25
|
+
Cache-Control:
|
26
|
+
- must-revalidate, max-age=900
|
27
|
+
Content-Encoding:
|
28
|
+
- gzip
|
29
|
+
Content-Type:
|
30
|
+
- application/json;charset=utf-8
|
31
|
+
Expires:
|
32
|
+
- Thu, 09 Apr 2015 17:44:35 GMT
|
33
|
+
Last-Modified:
|
34
|
+
- Thu, 09 Apr 2015 17:29:35 GMT
|
35
|
+
Strict-Transport-Security:
|
36
|
+
- max-age=631138519
|
37
|
+
X-Connection-Hash:
|
38
|
+
- d92a3da2734891d68f5a79f0d1800a3b
|
39
|
+
X-Response-Time:
|
40
|
+
- '11'
|
41
|
+
Content-Length:
|
42
|
+
- '71'
|
43
|
+
Accept-Ranges:
|
44
|
+
- bytes
|
45
|
+
Via:
|
46
|
+
- 1.1 varnish
|
47
|
+
Age:
|
48
|
+
- '51'
|
49
|
+
X-Served-By:
|
50
|
+
- cache-tw-dfw1-cr1-3-TWDFW1
|
51
|
+
X-Cache:
|
52
|
+
- HIT
|
53
|
+
X-Cache-Hits:
|
54
|
+
- '1'
|
55
|
+
Vary:
|
56
|
+
- Accept-Encoding
|
57
|
+
body:
|
58
|
+
encoding: ASCII-8BIT
|
59
|
+
string: !binary |-
|
60
|
+
H4sIAAAAAAAAAKpWSs4vzStRsjI0NDU11FEqLcpRslLKKCkpsIrRj9FPz89P
|
61
|
+
z0nVS87PjdFXqgUAAAD//wMABIYJ+C0AAAA=
|
62
|
+
http_version:
|
63
|
+
recorded_at: Thu, 09 Apr 2015 17:30:25 GMT
|
64
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,68 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://www.reddit.com/r/search/search.json?q=url:http://jeffkeen.me/totallyunknown
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip
|
14
|
+
User-Agent:
|
15
|
+
- unirest-ruby/1.1
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Thu, 09 Apr 2015 21:56:46 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=UTF-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Set-Cookie:
|
30
|
+
- __cfduid=d50f20e6118c05422f5d59fe19256efb91428616606; expires=Fri, 08-Apr-16
|
31
|
+
21:56:46 GMT; path=/; domain=.reddit.com; HttpOnly
|
32
|
+
X-Ua-Compatible:
|
33
|
+
- IE=edge
|
34
|
+
X-Frame-Options:
|
35
|
+
- SAMEORIGIN
|
36
|
+
X-Content-Type-Options:
|
37
|
+
- nosniff
|
38
|
+
X-Xss-Protection:
|
39
|
+
- 1; mode=block
|
40
|
+
Access-Control-Allow-Origin:
|
41
|
+
- "*"
|
42
|
+
Access-Control-Expose-Headers:
|
43
|
+
- X-Reddit-Tracking, X-Moose
|
44
|
+
X-Reddit-Tracking:
|
45
|
+
- https://pixel.redditmedia.com/pixel/of_destiny.png?v=NPjKlQn6h%2F0gWlAsQzt7u95XdyAaw8SNbh8xp5HZg3KKYA9i7jpvVCL6GuG0jB8s%2F51Z0Ey4yao%3D
|
46
|
+
X-Moose:
|
47
|
+
- majestic
|
48
|
+
Cache-Control:
|
49
|
+
- no-cache
|
50
|
+
Cf-Cache-Status:
|
51
|
+
- MISS
|
52
|
+
Vary:
|
53
|
+
- Accept-Encoding
|
54
|
+
Server:
|
55
|
+
- cloudflare-nginx
|
56
|
+
Cf-Ray:
|
57
|
+
- 1d4976c03d7903ee-DFW
|
58
|
+
Content-Encoding:
|
59
|
+
- gzip
|
60
|
+
body:
|
61
|
+
encoding: ASCII-8BIT
|
62
|
+
string: !binary |-
|
63
|
+
H4sIAAAAAAAAAy3JwQ2AIAxG4VWa/8wEzOAGxgPaIo1YEsATYXdj4vF9b+BS
|
64
|
+
Y3jCoq2rnXAEDj3A08BdOIWWvv35kTRzFYOndXOEELtUeLInZ0fYJZYqf8/5
|
65
|
+
AmghW1ZbAAAA
|
66
|
+
http_version:
|
67
|
+
recorded_at: Thu, 09 Apr 2015 21:56:47 GMT
|
68
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Popularity::Facebook do
|
4
|
+
context "valid url" do
|
5
|
+
use_vcr_cassette "facebook"
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Popularity::Facebook.new('http://google.com')
|
9
|
+
}
|
10
|
+
|
11
|
+
it "should return correct comment count" do
|
12
|
+
expect(10121).to equal subject.comments
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return correct share count" do
|
16
|
+
expect(12085903).to equal subject.shares
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should calculate the correct total" do
|
20
|
+
expect(subject.total).to equal (subject.shares + subject.comments)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/github_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Popularity::Github do
|
4
|
+
context "non-github url" do
|
5
|
+
use_vcr_cassette "github-invalid"
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Popularity::Github.new('http://google.com')
|
9
|
+
}
|
10
|
+
|
11
|
+
it "should be invalid" do
|
12
|
+
expect(subject.valid?).to eq(false)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have no response" do
|
16
|
+
expect(subject.response).to eq(false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "github url" do
|
21
|
+
use_vcr_cassette "github-valid"
|
22
|
+
|
23
|
+
subject {
|
24
|
+
Popularity::Github.new('http://github.com/jkeen/tracking_number')
|
25
|
+
}
|
26
|
+
|
27
|
+
it "should be valid" do
|
28
|
+
expect(subject.valid?).to eq(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have response" do
|
32
|
+
expect(subject.response).to_not eq(false)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have correct number of stars" do
|
36
|
+
expect(18).to eq(subject.stars)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Popularity::GooglePlus do
|
4
|
+
context "valid url" do
|
5
|
+
use_vcr_cassette "google_plus"
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Popularity::GooglePlus.new('http://google.com')
|
9
|
+
}
|
10
|
+
|
11
|
+
it "should return correct plus-one count" do
|
12
|
+
expect(11180649).to eq subject.plus_ones
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should calculate the correct total" do
|
16
|
+
expect(subject.plus_ones).to equal subject.total
|
17
|
+
end
|
18
|
+
|
19
|
+
context "json" do
|
20
|
+
let(:json) { subject.to_json }
|
21
|
+
|
22
|
+
it "should have required attributes in json" do
|
23
|
+
expect(subject.plus_ones).to eq(json["plus_ones"])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/medium_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Popularity::Medium do
|
4
|
+
context "non-medium url" do
|
5
|
+
use_vcr_cassette "medium-invalid"
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Popularity::Medium.new('http://google.com')
|
9
|
+
}
|
10
|
+
|
11
|
+
it "should be invalid" do
|
12
|
+
expect(subject.valid?).to eq(false)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have no resposne" do
|
16
|
+
expect(subject.response).to eq(false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "medium url" do
|
21
|
+
use_vcr_cassette "medium-valid"
|
22
|
+
|
23
|
+
subject {
|
24
|
+
Popularity::Medium.new('https://medium.com/@jeffkeen/call-me-sometime-64ed463c02f0')
|
25
|
+
}
|
26
|
+
|
27
|
+
it "should be valid" do
|
28
|
+
expect(subject.valid?).to eq(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have response" do
|
32
|
+
expect(subject.response).to_not eq(false)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have correct number of recommends" do
|
36
|
+
expect(13).to eq(subject.recommends)
|
37
|
+
end
|
38
|
+
|
39
|
+
context "json" do
|
40
|
+
let(:json) { subject.to_json }
|
41
|
+
|
42
|
+
it "should have required attributes in json" do
|
43
|
+
expect(subject.recommends).to eq(json["recommends"])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Popularity::Pinterest do
|
4
|
+
context "valid url" do
|
5
|
+
use_vcr_cassette "pinterest"
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Popularity::Pinterest.new('http://google.com')
|
9
|
+
}
|
10
|
+
|
11
|
+
it "should return correct pin count" do
|
12
|
+
expect(11278).to eq subject.pins
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should calculate the correct total" do
|
16
|
+
expect(subject.total).to eq subject.pins
|
17
|
+
end
|
18
|
+
|
19
|
+
context "json" do
|
20
|
+
let(:json) { subject.to_json }
|
21
|
+
|
22
|
+
it "should have required attributes in json" do
|
23
|
+
expect(subject.pins).to eq(json["pins"])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Popularity::RedditComment do
|
5
|
+
context "non-reddit url" do
|
6
|
+
use_vcr_cassette "reddit-comment"
|
7
|
+
|
8
|
+
subject {
|
9
|
+
Popularity::RedditComment.new('http://google.com')
|
10
|
+
}
|
11
|
+
|
12
|
+
it "should be invalid" do
|
13
|
+
expect(subject.valid?).to eq(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have no resposne" do
|
17
|
+
expect(subject.response).to eq(false)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "non-comment url" do
|
22
|
+
use_vcr_cassette "reddit-comment"
|
23
|
+
|
24
|
+
subject {
|
25
|
+
Popularity::RedditComment.new('http://www.reddit.com/r/Fitness/comments/30wleu/me_and_my_wife_joined_the_gym_9_months_ago_we')
|
26
|
+
}
|
27
|
+
|
28
|
+
it "should be invalid" do
|
29
|
+
expect(subject.valid?).to eq(false)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have no resposne" do
|
33
|
+
expect(subject.response).to eq(false)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "reddit url" do
|
38
|
+
use_vcr_cassette "reddit-comment"
|
39
|
+
|
40
|
+
subject {
|
41
|
+
Popularity::RedditComment.new('http://www.reddit.com/r/Fitness/comments/30wleu/me_and_my_wife_joined_the_gym_9_months_ago_we/cpwrwat')
|
42
|
+
}
|
43
|
+
|
44
|
+
it "should be valid" do
|
45
|
+
expect(subject.valid?).to eq(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have response" do
|
49
|
+
expect(subject.response).to_not eq(false)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have correct score" do
|
53
|
+
expect(500).to eq(subject.score)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have correct total" do
|
57
|
+
expect(subject.total).to eq(subject.score)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Popularity::RedditPost do
|
5
|
+
context "non-reddit url" do
|
6
|
+
use_vcr_cassette "reddit-post"
|
7
|
+
|
8
|
+
subject {
|
9
|
+
Popularity::RedditPost.new('http://google.com')
|
10
|
+
}
|
11
|
+
|
12
|
+
it "should be invalid" do
|
13
|
+
expect(subject.valid?).to eq(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have no resposne" do
|
17
|
+
expect(subject.response).to eq(false)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "non-post url" do
|
22
|
+
use_vcr_cassette "reddit-post"
|
23
|
+
|
24
|
+
subject {
|
25
|
+
Popularity::RedditPost.new('http://www.reddit.com/r/Fitness/comments/30wleu/me_and_my_wife_joined_the_gym_9_months_ago_we/cpwrwat')
|
26
|
+
}
|
27
|
+
|
28
|
+
it "should be invalid" do
|
29
|
+
expect(subject.valid?).to eq(false)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have no resposne" do
|
33
|
+
expect(subject.response).to eq(false)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "reddit url" do
|
38
|
+
use_vcr_cassette "reddit-post"
|
39
|
+
|
40
|
+
subject {
|
41
|
+
Popularity::RedditPost.new('http://www.reddit.com/r/funny/comments/2naq2t/every_time_my_brother_leaves_me_a_voicemail_he/')
|
42
|
+
}
|
43
|
+
|
44
|
+
it "should be valid" do
|
45
|
+
expect(subject.valid?).to eq(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have response" do
|
49
|
+
expect(subject.response).to_not eq(false)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have correct number of comments" do
|
53
|
+
expect(36).to eq(subject.comments)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have correct score" do
|
57
|
+
expect(629).to eq(subject.score)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have correct total" do
|
61
|
+
expect(subject.total).to eq(subject.score + subject.comments)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/reddit_spec.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Popularity::RedditShare do
|
4
|
+
context "valid url" do
|
5
|
+
use_vcr_cassette "reddit"
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Popularity::RedditShare.new('http://google.com')
|
9
|
+
}
|
10
|
+
|
11
|
+
it "should have multiple results" do
|
12
|
+
expect(25).to eq(subject.results.size)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should roll up score counts" do
|
16
|
+
totals = subject.results.collect { |r| r.score }
|
17
|
+
expect(totals.reduce(:+)).to eq subject.score
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should roll up comment counts" do
|
21
|
+
totals = subject.results.collect { |r| r.comments }
|
22
|
+
expect(totals.reduce(:+)).to eq subject.comments
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should allow access to underlying results" do
|
26
|
+
expect(4687).to eq(subject.results.first.score)
|
27
|
+
end
|
28
|
+
|
29
|
+
context "json" do
|
30
|
+
let(:json) { subject.to_json }
|
31
|
+
|
32
|
+
it "should include post count in json" do
|
33
|
+
expect(25).to eq(json["posts"])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should comments in json" do
|
37
|
+
expect(json["comments"]).to_not be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should score in json" do
|
41
|
+
expect(json["score"]).to_not be_nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "unknown url" do
|
46
|
+
use_vcr_cassette "unknown-reddit-post"
|
47
|
+
subject {
|
48
|
+
Popularity::RedditShare.new('http://jeffkeen.me/totallyunknown')
|
49
|
+
}
|
50
|
+
|
51
|
+
it "should be valid" do
|
52
|
+
expect(subject.valid?).to eq(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have response" do
|
56
|
+
expect(subject.response).to_not eq(false)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have correct number of comments" do
|
60
|
+
expect(0).to eq(subject.comments)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should have correct score" do
|
64
|
+
expect(0).to eq(subject.score)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have correct total" do
|
68
|
+
expect(subject.total).to eq(subject.score + subject.comments)
|
69
|
+
end
|
70
|
+
|
71
|
+
context "json" do
|
72
|
+
let(:json) { subject.to_json }
|
73
|
+
|
74
|
+
it "should include post count in json" do
|
75
|
+
expect(0).to eq(json["posts"])
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should comments in json" do
|
79
|
+
expect(0).to eq(json["comments"])
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should score in json" do
|
83
|
+
expect(0).to eq(json["score"])
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|