popularity 0.0.1 → 0.1.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: 626966520a15ec4f37c183a2a380b5010f105f85
4
- data.tar.gz: 00cf045aff8dcdfd8883ff3384ecb7bb253979ed
3
+ metadata.gz: 0048626f9fa80640a2fa1fe48db95e65435fd88c
4
+ data.tar.gz: 06cb57772c17993c8cbfefff1ed8a8494e07ca2b
5
5
  SHA512:
6
- metadata.gz: 437afdbe8bd81499712c32c1df0015a5adea309b8d0f548e8d830505942f855b11dd0ce8208caf0f0acb6066f12f27f8ad849e3a0b40925c7af6dc22c57fe4f1
7
- data.tar.gz: 302858361aebd23d0565a593ddf94a9b9fa9e5d260b03f4dd1bbd605e2525af5dc439261ff86f2d49076fa7b8d0216a60c4914e100e34c125b19fbf93076fe28
6
+ metadata.gz: 7f74093f5e0170d6ca1a7b35deac27dd4e74a9a2ed3cddd7b84f168078342114e560a72fa7e10de5ec4c7f41c93761705aacaa2a8e88a459d469f8b49ba4fb56
7
+ data.tar.gz: 2da61d6f6a64cfdb6d0e5d84d713b06cc5ec609e0883f2cc3e71daa6d0e498f6cbd88369888355d769c517deffe8badfda6bab95adc6574f19afecebd8973a69
@@ -15,6 +15,7 @@ Reddit Comments | `score` | only for reddit comment ur
15
15
  Github | `stars` | only for github repo urls
16
16
  Medium | `recommends` | only for medium posts
17
17
  Soundcloud | `plays`, `likes`, `comments`, `downloads` | only for soundcloud urls
18
+ Rubygems | `downloads` | only for rubygems
18
19
 
19
20
  ```ruby
20
21
 
@@ -23,10 +24,10 @@ Soundcloud | `plays`, `likes`, `comments`, `downloads` | only for soundclo
23
24
  > search.facebook.comments #=> comment count
24
25
  > search.twitter.tweets #=> tweet count
25
26
  > search.pinterests.pins #=> pin count
26
- > search.reddit.posts #=> post count
27
+ > search.reddit.posts #=> post count
27
28
  > search.reddit.comments #=> comment count across all posts
28
29
  > search.reddit.score #=> reddit score total across all posts
29
- > search.total #=> All of the above numbers added up
30
+ > search.total #=> All of the above numbers added up
30
31
 
31
32
  ```
32
33
 
@@ -40,10 +41,10 @@ Sometimes multiple URLs refer to the same thing. Maybe your URLs changed, but yo
40
41
  > search.facebook.comments #=> comment count across all urls
41
42
  > search.twitter.tweets #=> tweet count across all urls
42
43
  > search.pinterests.pins #=> pin count across all urls
43
- > search.reddit.posts #=> post count across all urls
44
+ > search.reddit.posts #=> post count across all urls
44
45
  > search.reddit.comments #=> comment count across all posts and urls
45
46
  > search.reddit.score #=> reddit score total across all posts and urls
46
- > search.total #=> All of the above numbers added up
47
+ > search.total #=> All of the above numbers added up
47
48
  ```
48
49
 
49
50
  JSON:
@@ -64,17 +65,15 @@ search.sources #=> [:facebook, :reddit, :google_plus, :pinterest, :twitter, :med
64
65
  search.results #=> returns the individual network result classes, i.e. RedditPost, Medium, Soundcloud, Facebook
65
66
  ```
66
67
 
67
- All of the searches done through Popularity.search are done asynchronously, but you don't need to worry about any of that because the method still blocks, so you can use it just like any other syncrhonous method.
68
+ All of the searches done through Popularity.search are done asynchronously, but you don't need to worry about any of that because the method still blocks, so you can use it just like any other synchronous method.
68
69
 
69
70
  To just query one network, interact with the class directly.
70
71
 
71
72
  ```ruby
72
- p = Popularity::RedditComment.new("http://www.reddit.com/r/:subreddit/comments/:id/:name/:comment")
73
+ p = Popularity::RedditComment.new("http://www.reddit.com/r/path/to/reddit/comment")
73
74
  p.score #=> comment score
74
75
  ```
75
76
 
76
-
77
-
78
77
  ### Contributing to Popularity
79
78
 
80
79
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "popularity"
18
18
  gem.homepage = "http://github.com/jkeen/popularity"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{Popularity searches social networks for urls and returns the metrics.L}
21
- gem.description = %Q{}
20
+ gem.summary = %Q{Popularity searches social networks a url and returns the metrics.}
21
+ gem.description = %Q{Supports Facebook, Twitter, Pinterest, Reddit (Links, Posts, and Comments), Github, Soundcloud, Medium, and Rubygems}
22
22
  gem.email = "jeff@keen.me"
23
23
  gem.authors = ["Jeff Keen"]
24
24
  # dependencies defined in Gemfile
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
Binary file
@@ -2,20 +2,21 @@
2
2
  require 'popularity/crawler'
3
3
  require 'popularity/search'
4
4
  require 'popularity/results_container'
5
- require 'popularity/facebook'
6
- require 'popularity/twitter'
7
- require 'popularity/pinterest'
8
- require 'popularity/google_plus'
9
- require 'popularity/medium'
10
- require 'popularity/reddit_post'
11
- require 'popularity/reddit_comment'
12
- require 'popularity/reddit_share'
13
- require 'popularity/soundcloud'
14
- require 'popularity/github'
15
5
 
16
6
  module Popularity
17
- TYPES = [Facebook, Twitter, Pinterest, GooglePlus, RedditShare, RedditPost, RedditComment, Medium, Soundcloud, Github]
7
+ TYPES = []
8
+ end
18
9
 
10
+ Gem.find_files("popularity/networks/*.rb").each { |path|
11
+ require path
12
+ file_name = path.split('/').last.split('.').first
13
+ class_name = file_name.gsub(/_[a-z]|^[a-z]/, &:upcase).gsub('_', '')
14
+
15
+ # Auto register the types in /networks
16
+ Popularity::TYPES << Object.const_get("Popularity::#{class_name}")
17
+ }
18
+
19
+ module Popularity
19
20
  def self.search(*urls)
20
21
  response = {}
21
22
 
@@ -0,0 +1,29 @@
1
+ module Popularity
2
+ class Rubygems < Crawler
3
+ def downloads
4
+ response_json["downloads"]
5
+ end
6
+
7
+ def as_json(options = {})
8
+ {"downloads" => downloads}
9
+ end
10
+
11
+ def total
12
+ downloads
13
+ end
14
+
15
+ def valid?
16
+ host == 'rubygems.org' && @url =~ /\/gems\//
17
+ end
18
+
19
+ protected
20
+
21
+ def gem_name
22
+ @url.split("/").last
23
+ end
24
+
25
+ def request_url
26
+ "https://rubygems.org/api/v1/gems/#{gem_name}.json"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Popularity
2
+ class Rubygems < Crawler
3
+ def downloads
4
+ response_json["downloads"]
5
+ end
6
+
7
+ def as_json(options = {})
8
+ {"downloads" => downloads}
9
+ end
10
+
11
+ def total
12
+ downloads
13
+ end
14
+
15
+ def valid?
16
+ host == 'rubygems.org' && @url =~ /\/gems\//
17
+ end
18
+
19
+ protected
20
+
21
+ def gem_name
22
+ @url.split("/").last
23
+ end
24
+
25
+ def request_url
26
+ "https://rubygems.org/api/v1/gems/#{gem_name}.json"
27
+ end
28
+ end
29
+ end
@@ -2,21 +2,21 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: popularity 0.0.1 ruby lib
5
+ # stub: popularity 0.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "popularity"
9
- s.version = "0.0.1"
9
+ s.version = "0.1.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Jeff Keen"]
14
- s.date = "2015-04-09"
15
- s.description = ""
14
+ s.date = "2015-04-10"
15
+ s.description = "Supports Facebook, Twitter, Pinterest, Reddit (Links, Posts, and Comments), Github, Soundcloud, Medium, and Rubygems"
16
16
  s.email = "jeff@keen.me"
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
- "README.rdoc"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
@@ -24,24 +24,26 @@ Gem::Specification.new do |s|
24
24
  "Gemfile",
25
25
  "Gemfile.lock",
26
26
  "LICENSE.txt",
27
- "README.rdoc",
27
+ "README.md",
28
28
  "Rakefile",
29
29
  "VERSION",
30
30
  "lib/.DS_Store",
31
31
  "lib/popularity.rb",
32
32
  "lib/popularity/crawler.rb",
33
- "lib/popularity/facebook.rb",
34
- "lib/popularity/github.rb",
35
- "lib/popularity/google_plus.rb",
36
- "lib/popularity/medium.rb",
37
- "lib/popularity/pinterest.rb",
38
- "lib/popularity/reddit_comment.rb",
39
- "lib/popularity/reddit_post.rb",
40
- "lib/popularity/reddit_share.rb",
33
+ "lib/popularity/networks/facebook.rb",
34
+ "lib/popularity/networks/github.rb",
35
+ "lib/popularity/networks/google_plus.rb",
36
+ "lib/popularity/networks/medium.rb",
37
+ "lib/popularity/networks/pinterest.rb",
38
+ "lib/popularity/networks/reddit_comment.rb",
39
+ "lib/popularity/networks/reddit_post.rb",
40
+ "lib/popularity/networks/reddit_share.rb",
41
+ "lib/popularity/networks/rubygems.rb",
42
+ "lib/popularity/networks/soundcloud.rb",
43
+ "lib/popularity/networks/twitter.rb",
41
44
  "lib/popularity/results_container.rb",
45
+ "lib/popularity/rubygems.rb",
42
46
  "lib/popularity/search.rb",
43
- "lib/popularity/soundcloud.rb",
44
- "lib/popularity/twitter.rb",
45
47
  "popularity.gemspec",
46
48
  "spec/cassettes/facebook.yml",
47
49
  "spec/cassettes/github-valid.yml",
@@ -52,6 +54,7 @@ Gem::Specification.new do |s|
52
54
  "spec/cassettes/reddit-post.yml",
53
55
  "spec/cassettes/reddit.yml",
54
56
  "spec/cassettes/result-container-test.yml",
57
+ "spec/cassettes/rubygems-valid.yml",
55
58
  "spec/cassettes/search-multi.yml",
56
59
  "spec/cassettes/search.yml",
57
60
  "spec/cassettes/soundcloud-valid.yml",
@@ -66,6 +69,7 @@ Gem::Specification.new do |s|
66
69
  "spec/reddit_post_spec.rb",
67
70
  "spec/reddit_spec.rb",
68
71
  "spec/results_container_spec.rb",
72
+ "spec/rubygems_spec.rb",
69
73
  "spec/search_spec.rb",
70
74
  "spec/soundcloud_spec.rb",
71
75
  "spec/spec_helper.rb",
@@ -80,7 +84,7 @@ Gem::Specification.new do |s|
80
84
  s.homepage = "http://github.com/jkeen/popularity"
81
85
  s.licenses = ["MIT"]
82
86
  s.rubygems_version = "2.2.2"
83
- s.summary = "Popularity searches social networks for urls and returns the metrics.L"
87
+ s.summary = "Popularity searches social networks a url and returns the metrics."
84
88
 
85
89
  if s.respond_to? :specification_version then
86
90
  s.specification_version = 4
@@ -0,0 +1,66 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://rubygems.org/api/v1/gems/popularity.json
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
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Fri, 10 Apr 2015 17:38:06 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Status:
32
+ - 200 OK
33
+ X-Frame-Options:
34
+ - SAMEORIGIN
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ Cache-Control:
40
+ - max-age=0, private, must-revalidate
41
+ X-Request-Id:
42
+ - 4b4d07a2-2c47-4f68-8165-491312f1fcfd
43
+ X-Runtime:
44
+ - '0.022088'
45
+ X-Ua-Compatible:
46
+ - IE=Edge,chrome=1
47
+ Content-Encoding:
48
+ - gzip
49
+ body:
50
+ encoding: ASCII-8BIT
51
+ string: !binary |-
52
+ H4sIAAAAAAAAA42T247TMBCGX8XydUhzaLrZSjwAJ4kL7gBFjj1J3Dp2GNut
53
+ UFWenQndXRpWrbizZr45/TM+cStG4Fs+uSkagTr85AlX7miNE8rzbV0l/ADo
54
+ tbNEZWmW5gQ8WZp/wMmI0DkcicTYzplEDINDysPfQ9exDwCWrNp2jkyfX2oy
55
+ DwLlAJ55J7UwzEI4Otx7RulYROOZsIohhIjWszAAGyGglj79SPmMlmA9UJmv
56
+ /NO7L/x7wsktlAiCb0/nhPuBHjxX66Ir8gyKx/ZBqCyTWdm2XV5Um8e6bKEU
57
+ dVVVa9l28FCV2aao19DJtu5KUdQiK6nShG4HMjQRNSUcQpi2q9U8aw+jTx32
58
+ q/mxWqhJlv/n3/yROKUYqja4ESbRwzK812GIbSrduNrtSdBltaPe6wtvozHz
59
+ LmUcwQYRaIXXjlFoo23fGO2f5rkEeBdRQiOdeqp7MbexbwIKuQdcpIcJrAIr
60
+ 9Sz/iSs4gHHTXJG2cXo+L3EET8M0E2pyJBzhR9QIMzYfx69vMctKYHm64efk
61
+ JaqNVhnAe3x2ze/gCHf5Il3wE843eqMXWsMCRlLyNl2meXHdih9cNEq8DrhM
62
+ +pYtcns9TgakO7zmn6Uhns4aow16/rB/pd15+po3p8jT+rotR9ua19cgKNJf
63
+ zkfhb0cvmoyWIvy97VGL5/Nv4rHkSVMEAAA=
64
+ http_version:
65
+ recorded_at: Fri, 10 Apr 2015 17:38:06 GMT
66
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popularity::Rubygems do
4
+ context "non-rubygems url" do
5
+ use_vcr_cassette "rubygems-invalid"
6
+
7
+ subject {
8
+ Popularity::Rubygems.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 "rubygems url" do
21
+ use_vcr_cassette "rubygems-valid"
22
+
23
+ subject {
24
+ Popularity::Rubygems.new('https://rubygems.org/gems/popularity')
25
+ }
26
+
27
+ it "should be valid" do
28
+ expect(subject.valid?).to be_truthy
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 downloads" do
36
+ expect(85).to eq(subject.downloads)
37
+ end
38
+
39
+ context "json" do
40
+ let(:json) { subject.to_json }
41
+
42
+ it "should have required attributes in json" do
43
+ [:downloads].each do |att|
44
+ expect(subject.send(att)).to eq(json[att.to_s])
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popularity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Keen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-09 00:00:00.000000000 Z
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open_uri_redirections
@@ -150,37 +150,40 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '1.6'
153
- description: ''
153
+ description: Supports Facebook, Twitter, Pinterest, Reddit (Links, Posts, and Comments),
154
+ Github, Soundcloud, Medium, and Rubygems
154
155
  email: jeff@keen.me
155
156
  executables: []
156
157
  extensions: []
157
158
  extra_rdoc_files:
158
159
  - LICENSE.txt
159
- - README.rdoc
160
+ - README.md
160
161
  files:
161
162
  - ".document"
162
163
  - ".rspec"
163
164
  - Gemfile
164
165
  - Gemfile.lock
165
166
  - LICENSE.txt
166
- - README.rdoc
167
+ - README.md
167
168
  - Rakefile
168
169
  - VERSION
169
170
  - lib/.DS_Store
170
171
  - lib/popularity.rb
171
172
  - lib/popularity/crawler.rb
172
- - lib/popularity/facebook.rb
173
- - lib/popularity/github.rb
174
- - lib/popularity/google_plus.rb
175
- - lib/popularity/medium.rb
176
- - lib/popularity/pinterest.rb
177
- - lib/popularity/reddit_comment.rb
178
- - lib/popularity/reddit_post.rb
179
- - lib/popularity/reddit_share.rb
173
+ - lib/popularity/networks/facebook.rb
174
+ - lib/popularity/networks/github.rb
175
+ - lib/popularity/networks/google_plus.rb
176
+ - lib/popularity/networks/medium.rb
177
+ - lib/popularity/networks/pinterest.rb
178
+ - lib/popularity/networks/reddit_comment.rb
179
+ - lib/popularity/networks/reddit_post.rb
180
+ - lib/popularity/networks/reddit_share.rb
181
+ - lib/popularity/networks/rubygems.rb
182
+ - lib/popularity/networks/soundcloud.rb
183
+ - lib/popularity/networks/twitter.rb
180
184
  - lib/popularity/results_container.rb
185
+ - lib/popularity/rubygems.rb
181
186
  - lib/popularity/search.rb
182
- - lib/popularity/soundcloud.rb
183
- - lib/popularity/twitter.rb
184
187
  - popularity.gemspec
185
188
  - spec/cassettes/facebook.yml
186
189
  - spec/cassettes/github-valid.yml
@@ -191,6 +194,7 @@ files:
191
194
  - spec/cassettes/reddit-post.yml
192
195
  - spec/cassettes/reddit.yml
193
196
  - spec/cassettes/result-container-test.yml
197
+ - spec/cassettes/rubygems-valid.yml
194
198
  - spec/cassettes/search-multi.yml
195
199
  - spec/cassettes/search.yml
196
200
  - spec/cassettes/soundcloud-valid.yml
@@ -205,6 +209,7 @@ files:
205
209
  - spec/reddit_post_spec.rb
206
210
  - spec/reddit_spec.rb
207
211
  - spec/results_container_spec.rb
212
+ - spec/rubygems_spec.rb
208
213
  - spec/search_spec.rb
209
214
  - spec/soundcloud_spec.rb
210
215
  - spec/spec_helper.rb
@@ -238,5 +243,5 @@ rubyforge_project:
238
243
  rubygems_version: 2.2.2
239
244
  signing_key:
240
245
  specification_version: 4
241
- summary: Popularity searches social networks for urls and returns the metrics.L
246
+ summary: Popularity searches social networks a url and returns the metrics.
242
247
  test_files: []