scouter 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/scouter/base/connection.rb +1 -1
- data/lib/scouter/base/object.rb +9 -7
- data/lib/scouter/base/version.rb +1 -1
- data/lib/scouter/buffer.rb +7 -6
- data/lib/scouter/facebook.rb +6 -3
- data/lib/scouter/feedly.rb +5 -3
- data/lib/scouter/google_plus.rb +11 -10
- data/lib/scouter/hatena_bookmark.rb +6 -3
- data/lib/scouter/linkedin.rb +8 -6
- data/lib/scouter/pinterest.rb +7 -5
- data/lib/scouter/pocket.rb +9 -5
- data/lib/scouter/twitter.rb +6 -4
- data/lib/scouter.rb +8 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de25a57191d53f274b602f1302d711dfe1984384
|
4
|
+
data.tar.gz: 4d037129761a3de61a5d30b0550c04313a19e330
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebec5f6833621e940f618c1efee5a1e13a2c486bb040480e1b8829d7b8cc25db14e945d55731f14a3d29296cafbd3452fdfe04633ea2168b6d9f2be7ff1ee177
|
7
|
+
data.tar.gz: b12926883efbce420c0527462229555029360393d515a0fb29ad66b95a7e8d59b66e4f5f7c27e52da68519847208098b80cdde28cc13d9ffd34b068ae89d02d6
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
require 'scouter'
|
28
28
|
|
29
|
-
results, errors =
|
29
|
+
results, errors = Scouter.get_count('http://google.com')
|
30
30
|
results.each do |url, service|
|
31
31
|
puts url #=> http://google.com
|
32
32
|
puts service.buffer #=> 129
|
@@ -40,7 +40,7 @@ Or install it yourself as:
|
|
40
40
|
|
41
41
|
if you want to get social count in facebook & twitter
|
42
42
|
|
43
|
-
results, errors =
|
43
|
+
results, errors = Scouter.get_count('http://google.com', [Scouter::Facebook, Scouter::Twitter])
|
44
44
|
results.each do |url, service|
|
45
45
|
puts url #=> http://google.com
|
46
46
|
puts service.facebook #=> 166458
|
@@ -49,7 +49,7 @@ if you want to get social count in facebook & twitter
|
|
49
49
|
|
50
50
|
## Contributing
|
51
51
|
|
52
|
-
1. Fork it ( https://github.com/
|
52
|
+
1. Fork it ( https://github.com/morizyun/scouter/fork )
|
53
53
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
54
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
55
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/scouter/base/object.rb
CHANGED
@@ -5,8 +5,9 @@ module Scouter
|
|
5
5
|
class Object
|
6
6
|
extend Scouter::Base::Connection
|
7
7
|
|
8
|
-
#
|
8
|
+
# Get Count By URL
|
9
9
|
# @param [String or Array] urls
|
10
|
+
# @return [Hashie::Mash, Array] URL & count hash, Error
|
10
11
|
def self.get_count(urls)
|
11
12
|
urls = check_and_trans_url(urls)
|
12
13
|
results, errors = {}, []
|
@@ -21,9 +22,9 @@ module Scouter
|
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
# Get
|
25
|
-
# @
|
26
|
-
# @return [String]
|
25
|
+
# Get response and parse it By URL
|
26
|
+
# @param [String or Array] urls
|
27
|
+
# @return [Hash, String] URL & count hash, Error message
|
27
28
|
def self.get_and_parse_response(urls)
|
28
29
|
url_str = api_url(urls)
|
29
30
|
json = get_response(url_str)
|
@@ -41,7 +42,8 @@ module Scouter
|
|
41
42
|
end
|
42
43
|
|
43
44
|
# Check and transform urls to Array
|
44
|
-
# @
|
45
|
+
# @param [String or Array] urls
|
46
|
+
# @return [Array] url
|
45
47
|
def self.check_and_trans_url(url)
|
46
48
|
url = to_array(url)
|
47
49
|
raise ArgumentError, "#{url} is not String and Array" unless url.class == Array
|
@@ -63,14 +65,14 @@ module Scouter
|
|
63
65
|
end
|
64
66
|
|
65
67
|
# Parse response data for response (For Override)
|
66
|
-
# @param [
|
68
|
+
# @param [String] response
|
67
69
|
# @return [Hash] urls & count
|
68
70
|
def self.parse_response(response, url = nil)
|
69
71
|
end
|
70
72
|
|
71
73
|
# build API URL (For Override)
|
72
74
|
# @param [String] url
|
73
|
-
# @return [String] API
|
75
|
+
# @return [String] API url
|
74
76
|
def self.api_url(url)
|
75
77
|
end
|
76
78
|
end
|
data/lib/scouter/base/version.rb
CHANGED
data/lib/scouter/buffer.rb
CHANGED
@@ -2,8 +2,9 @@ module Scouter
|
|
2
2
|
class Buffer < Scouter::Base::Object
|
3
3
|
END_POINT = 'https://api.bufferapp.com/1'.freeze
|
4
4
|
|
5
|
-
#
|
5
|
+
# Get Buffer Share Count
|
6
6
|
# @param [String or Array] urls
|
7
|
+
# @return [Hashie::Mash, Array] URL & count hash, Error
|
7
8
|
def self.get_count(urls)
|
8
9
|
urls = check_and_trans_url(urls)
|
9
10
|
results, errors = {}, []
|
@@ -19,9 +20,9 @@ module Scouter
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
# Get and parse response data
|
23
|
-
# @
|
24
|
-
# @return [String]
|
23
|
+
# Get and parse response data & error message
|
24
|
+
# @param [String] urls URL list
|
25
|
+
# @return [Hash, String] URL & count hash, Error message
|
25
26
|
def self.get_and_parse_response(url)
|
26
27
|
html = get_response(api_url(url))
|
27
28
|
res = parse_response(html, url)
|
@@ -31,7 +32,7 @@ module Scouter
|
|
31
32
|
return [nil, message]
|
32
33
|
end
|
33
34
|
|
34
|
-
#
|
35
|
+
# Build Feedly API URL
|
35
36
|
# @param [String] url
|
36
37
|
# @return [String] API url
|
37
38
|
def self.api_url(url)
|
@@ -39,7 +40,7 @@ module Scouter
|
|
39
40
|
end
|
40
41
|
|
41
42
|
# Parse json data for response
|
42
|
-
# @param [
|
43
|
+
# @param [String] json
|
43
44
|
# @return [Hash] url & count
|
44
45
|
def self.parse_response(json, url)
|
45
46
|
res = JSON.parse(json)
|
data/lib/scouter/facebook.rb
CHANGED
@@ -4,7 +4,7 @@ module Scouter
|
|
4
4
|
|
5
5
|
private
|
6
6
|
|
7
|
-
#
|
7
|
+
# Build Facebook Graph API url
|
8
8
|
# @param [Array] url
|
9
9
|
# @return [String] API url
|
10
10
|
def self.api_url(url)
|
@@ -12,13 +12,16 @@ module Scouter
|
|
12
12
|
"#{END_POINT}/fql?q=SELECT%20url,%20total_count%20FROM%20link_stat%20WHERE%20url%20in%20(#{str})"
|
13
13
|
end
|
14
14
|
|
15
|
-
# Parse
|
16
|
-
# @param [
|
15
|
+
# Parse JSON data of response
|
16
|
+
# @param [String] json
|
17
17
|
# @return [Hash] url & count
|
18
18
|
def self.parse_response(json, urls = nil)
|
19
19
|
parse_response_item(JSON.parse(json)['data'])
|
20
20
|
end
|
21
21
|
|
22
|
+
# Parse JSON List data of response
|
23
|
+
# @param [Array] json_list
|
24
|
+
# @return [Hash] url & count
|
22
25
|
def self.parse_response_item(json_list)
|
23
26
|
results = {}
|
24
27
|
json_list.each do |json|
|
data/lib/scouter/feedly.rb
CHANGED
@@ -2,8 +2,9 @@ module Scouter
|
|
2
2
|
class Feedly < Scouter::Base::Object
|
3
3
|
END_POINT = 'http://cloud.feedly.com/v3'.freeze
|
4
4
|
|
5
|
-
#
|
5
|
+
# Get feedly Count
|
6
6
|
# @param [String or Array] urls
|
7
|
+
# @return [Hashie::Mash, Array] URL & count hash, Error
|
7
8
|
def self.get_count(urls)
|
8
9
|
urls = check_and_trans_url(urls)
|
9
10
|
results, errors = {}, []
|
@@ -19,7 +20,7 @@ module Scouter
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
#
|
23
|
+
# Build Feedly API URL
|
23
24
|
# @param [String] url
|
24
25
|
# @return [String] API url
|
25
26
|
def self.api_url(url)
|
@@ -28,7 +29,8 @@ module Scouter
|
|
28
29
|
end
|
29
30
|
|
30
31
|
# Parse json data for response
|
31
|
-
# @param [
|
32
|
+
# @param [String] json response by API
|
33
|
+
# @param [String] url url
|
32
34
|
# @return [Hash] url & count
|
33
35
|
def self.parse_response(json, url)
|
34
36
|
res = JSON.parse(json)
|
data/lib/scouter/google_plus.rb
CHANGED
@@ -2,8 +2,9 @@ module Scouter
|
|
2
2
|
class GooglePlus < Scouter::Base::Object
|
3
3
|
API_KEY = 'AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ'.freeze
|
4
4
|
|
5
|
-
#
|
5
|
+
# Get Google+ Count
|
6
6
|
# @param [String or Array] urls
|
7
|
+
# @return [Hashie::Mash, Array] URL & count hash, Error
|
7
8
|
def self.get_count(urls)
|
8
9
|
urls = check_and_trans_url(urls)
|
9
10
|
results, errors = {}, []
|
@@ -20,8 +21,8 @@ module Scouter
|
|
20
21
|
private
|
21
22
|
|
22
23
|
# Get and parse response
|
23
|
-
# @
|
24
|
-
# @return [String]
|
24
|
+
# @param [String] url
|
25
|
+
# @return [Hash, String] URL & count hash, Error message
|
25
26
|
def self.get_and_parse_response(url)
|
26
27
|
json = get_response(url)
|
27
28
|
res = parse_response(json, url)
|
@@ -31,9 +32,9 @@ module Scouter
|
|
31
32
|
return [nil, message]
|
32
33
|
end
|
33
34
|
|
34
|
-
#
|
35
|
+
# Get json data from API
|
35
36
|
# @param [String] url
|
36
|
-
# @return [
|
37
|
+
# @return [String] response from API
|
37
38
|
def self.get_response(url)
|
38
39
|
option = {'Content-Type' => 'application/json'}
|
39
40
|
request = Net::HTTP::Post.new(api_uri.request_uri, option)
|
@@ -57,15 +58,15 @@ module Scouter
|
|
57
58
|
}.body
|
58
59
|
end
|
59
60
|
|
60
|
-
# Build url for
|
61
|
-
# @
|
62
|
-
# @return [String] API url
|
61
|
+
# Build url for API
|
62
|
+
# @return [URI] URI object of API URL
|
63
63
|
def self.api_uri
|
64
64
|
URI.parse("https://clients6.google.com/rpc?key=#{API_KEY}")
|
65
65
|
end
|
66
66
|
|
67
|
-
# Parse
|
68
|
-
# @param [
|
67
|
+
# Parse Json data of response
|
68
|
+
# @param [Array] json_list
|
69
|
+
# @param [String] url
|
69
70
|
# @return [Hash] url & count
|
70
71
|
def self.parse_response(json_list, url)
|
71
72
|
results = {}
|
@@ -4,7 +4,7 @@ module Scouter
|
|
4
4
|
|
5
5
|
private
|
6
6
|
|
7
|
-
#
|
7
|
+
# Build Hatena Bookmark Count API URL
|
8
8
|
# @param [Array] url
|
9
9
|
# @return [String] API url
|
10
10
|
def self.api_url(url)
|
@@ -12,13 +12,16 @@ module Scouter
|
|
12
12
|
"#{END_POINT}/entry.counts?#{url_str}"
|
13
13
|
end
|
14
14
|
|
15
|
-
# Parse
|
16
|
-
# @param [
|
15
|
+
# Parse JSON data of response
|
16
|
+
# @param [String] response
|
17
17
|
# @return [Hash] url & count
|
18
18
|
def self.parse_response(response, urls = nil)
|
19
19
|
parse_response_item(JSON.parse(response))
|
20
20
|
end
|
21
21
|
|
22
|
+
# Parse JSON list data of response
|
23
|
+
# @param [Array] response
|
24
|
+
# @return [Hash] url & count
|
22
25
|
def self.parse_response_item(json_list)
|
23
26
|
results = {}
|
24
27
|
json_list.each do |json|
|
data/lib/scouter/linkedin.rb
CHANGED
@@ -2,8 +2,9 @@ module Scouter
|
|
2
2
|
class Linkedin < Scouter::Base::Object
|
3
3
|
END_POINT = 'https://www.linkedin.com/countserv'.freeze
|
4
4
|
|
5
|
-
#
|
5
|
+
# Get Linkedin Count
|
6
6
|
# @param [String or Array] urls
|
7
|
+
# @return [Hashie::Mash, Array] URL & count hash, Error
|
7
8
|
def self.get_count(urls)
|
8
9
|
urls = check_and_trans_url(urls)
|
9
10
|
results, errors = {}, []
|
@@ -19,19 +20,20 @@ module Scouter
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
# Build url for
|
23
|
-
# @param [
|
23
|
+
# Build url for API
|
24
|
+
# @param [String] url
|
24
25
|
# @return [String] API url
|
25
26
|
def self.api_url(url)
|
26
27
|
"#{END_POINT}/count/share?url=#{url}&format=json"
|
27
28
|
end
|
28
29
|
|
29
|
-
# Parse
|
30
|
-
# @param [
|
30
|
+
# Parse JSON data for response
|
31
|
+
# @param [String] json
|
32
|
+
# @param [String] url
|
31
33
|
# @return [Hash] url & count
|
32
34
|
def self.parse_response(json, url)
|
33
35
|
res = JSON.parse(json)
|
34
|
-
{
|
36
|
+
{ url => { self.service_name => res['count'] } }
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
data/lib/scouter/pinterest.rb
CHANGED
@@ -2,8 +2,9 @@ module Scouter
|
|
2
2
|
class Pinterest < Scouter::Base::Object
|
3
3
|
END_POINT = 'http://api.pinterest.com/v1'.freeze
|
4
4
|
|
5
|
-
#
|
5
|
+
# Get Pinterest Count
|
6
6
|
# @param [String or Array] urls
|
7
|
+
# @return [Hashie::Mash, Array] URL & count hash, Error
|
7
8
|
def self.get_count(urls)
|
8
9
|
urls = check_and_trans_url(urls)
|
9
10
|
results, errors = {}, []
|
@@ -19,15 +20,16 @@ module Scouter
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
# Build url for
|
23
|
-
# @param [
|
23
|
+
# Build url for API
|
24
|
+
# @param [String] url
|
24
25
|
# @return [String] API url
|
25
26
|
def self.api_url(url)
|
26
27
|
"#{END_POINT}/urls/count.json?url=#{url}"
|
27
28
|
end
|
28
29
|
|
29
|
-
# Parse
|
30
|
-
# @param [
|
30
|
+
# Parse JSON data for response
|
31
|
+
# @param [String] json
|
32
|
+
# @param [String] url
|
31
33
|
# @return [Hash] url & count
|
32
34
|
def self.parse_response(json, url)
|
33
35
|
res = JSON.parse(json.gsub(/(receiveCount\(|\))/, ''))
|
data/lib/scouter/pocket.rb
CHANGED
@@ -2,8 +2,9 @@ module Scouter
|
|
2
2
|
class Pocket < Scouter::Base::Object
|
3
3
|
END_POINT = 'https://widgets.getpocket.com'.freeze
|
4
4
|
|
5
|
-
#
|
5
|
+
# Get Pocket Count
|
6
6
|
# @param [String or Array] urls
|
7
|
+
# @return [Hashie::Mash, Array] URL & count hash, Error
|
7
8
|
def self.get_count(urls)
|
8
9
|
urls = check_and_trans_url(urls)
|
9
10
|
results, errors = {}, []
|
@@ -17,6 +18,8 @@ module Scouter
|
|
17
18
|
return [res_hash, errors]
|
18
19
|
end
|
19
20
|
|
21
|
+
# Set API parameter for test mock
|
22
|
+
# @param [String or Array] num
|
20
23
|
def self.set_api_random(num)
|
21
24
|
@@api_rand_num = num
|
22
25
|
end
|
@@ -24,8 +27,8 @@ module Scouter
|
|
24
27
|
private
|
25
28
|
|
26
29
|
# Get and parse response data
|
27
|
-
# @
|
28
|
-
# @return [String]
|
30
|
+
# @param [String] url URL
|
31
|
+
# @return [Hash, String] URL & count hash, Error message
|
29
32
|
def self.get_and_parse_response(url)
|
30
33
|
html = get_response(api_url(url))
|
31
34
|
res = parse_response(html, url)
|
@@ -35,7 +38,7 @@ module Scouter
|
|
35
38
|
return [nil, message]
|
36
39
|
end
|
37
40
|
|
38
|
-
#
|
41
|
+
# Build Pocket API URL
|
39
42
|
# @param [String] url
|
40
43
|
# @return [String] API url
|
41
44
|
def self.api_url(url)
|
@@ -45,7 +48,8 @@ module Scouter
|
|
45
48
|
end
|
46
49
|
|
47
50
|
# Parse html for response
|
48
|
-
# @param [
|
51
|
+
# @param [String] html
|
52
|
+
# @param [String] url
|
49
53
|
# @return [Hash] url & count
|
50
54
|
def self.parse_response(html, url)
|
51
55
|
count = (html.to_s =~ /id="cnt"[^0-9]+([0-9]+)/) ? $1.to_i : 0
|
data/lib/scouter/twitter.rb
CHANGED
@@ -2,8 +2,9 @@ module Scouter
|
|
2
2
|
class Twitter < Scouter::Base::Object
|
3
3
|
END_POINT = 'http://urls.api.twitter.com'.freeze
|
4
4
|
|
5
|
-
#
|
5
|
+
# Get Twitter Count
|
6
6
|
# @param [String or Array] urls
|
7
|
+
# @return [Hashie::Mash, Array] URL & count hash, Error
|
7
8
|
def self.get_count(urls)
|
8
9
|
urls = check_and_trans_url(urls)
|
9
10
|
results, errors = {}, []
|
@@ -19,7 +20,7 @@ module Scouter
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
#
|
23
|
+
# Build Twitter API URL
|
23
24
|
# @param [String] url
|
24
25
|
# @return [String] API url
|
25
26
|
def self.api_url(url)
|
@@ -27,8 +28,9 @@ module Scouter
|
|
27
28
|
"#{END_POINT}/1/urls/count.json?url=#{escaped_url}"
|
28
29
|
end
|
29
30
|
|
30
|
-
# Parse
|
31
|
-
# @param [
|
31
|
+
# Parse JSON data for response
|
32
|
+
# @param [String] json data
|
33
|
+
# @param [String] url
|
32
34
|
# @return [Hash] url & count
|
33
35
|
def self.parse_response(json, url)
|
34
36
|
res = JSON.parse(json)
|
data/lib/scouter.rb
CHANGED
@@ -33,10 +33,12 @@ module Scouter
|
|
33
33
|
Scouter::Pocket,
|
34
34
|
Scouter::Twitter ]
|
35
35
|
|
36
|
-
#
|
37
|
-
# @param [String or Array] urls
|
36
|
+
# Get Social Count By Buffer/Facebook/Feedly/GooglePlus/HatenaBookmark/Linkedin/Pinterest/Pocket/Twitter
|
37
|
+
# @param [String or Array] urls url list ot get count
|
38
|
+
# @param [Array or nil] service service list to get count
|
39
|
+
# @return [Hashie::Mash, Hashie::Mash] URL & count hash, Error
|
38
40
|
def self.get_count(urls, services = SERVICES)
|
39
|
-
results, errors = [],
|
41
|
+
results, errors = [], Hashie::Mash.new()
|
40
42
|
|
41
43
|
Parallel.each(services, in_threads: services.count) do |service|
|
42
44
|
result, error = service.get_count(urls)
|
@@ -50,6 +52,9 @@ module Scouter
|
|
50
52
|
|
51
53
|
private
|
52
54
|
|
55
|
+
# Merge result data of service to hash
|
56
|
+
# @param [Hashie::Mash] social count & url of some services
|
57
|
+
# @return [Hashie::Mash] URL & count hash, Error
|
53
58
|
def self.results_merged_hash(results)
|
54
59
|
results_hash = {}
|
55
60
|
results.each do |item|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scouter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- morizyun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|