crown 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/crown.gemspec +6 -3
- data/lib/crown.rb +5 -1
- data/lib/crown/backtype.rb +64 -0
- data/lib/crown/buzzurl.rb +2 -1
- data/lib/crown/delicious.rb +2 -1
- data/lib/crown/facebook.rb +72 -0
- data/lib/crown/hatena/bookmark.rb +12 -16
- data/lib/crown/livedoor/clip.rb +3 -2
- data/lib/crown/topsy.rb +62 -0
- data/lib/crown/tweetmeme.rb +62 -0
- data/lib/crown/twitter.rb +10 -11
- data/lib/crown/yahoo/bookmark.rb +2 -1
- data/test/crown_test.rb +41 -0
- metadata +8 -5
- data/lib/crown.gemspec +0 -0
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/crown.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{crown}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["clown"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-19}
|
13
13
|
s.description = %q{crown is uncategorized ruby libraries, which is added according to author's mood :-D}
|
14
14
|
s.email = %q{tt.clown@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,15 +26,18 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"crown.gemspec",
|
29
|
-
"lib/crown.gemspec",
|
30
29
|
"lib/crown.rb",
|
30
|
+
"lib/crown/backtype.rb",
|
31
31
|
"lib/crown/buzzurl.rb",
|
32
32
|
"lib/crown/delicious.rb",
|
33
|
+
"lib/crown/facebook.rb",
|
33
34
|
"lib/crown/hatena.rb",
|
34
35
|
"lib/crown/hatena/bookmark.rb",
|
35
36
|
"lib/crown/http.rb",
|
36
37
|
"lib/crown/livedoor.rb",
|
37
38
|
"lib/crown/livedoor/clip.rb",
|
39
|
+
"lib/crown/topsy.rb",
|
40
|
+
"lib/crown/tweetmeme.rb",
|
38
41
|
"lib/crown/twitter.rb",
|
39
42
|
"lib/crown/yahoo.rb",
|
40
43
|
"lib/crown/yahoo/bookmark.rb",
|
data/lib/crown.rb
CHANGED
@@ -40,7 +40,11 @@ require 'crown/livedoor'
|
|
40
40
|
require 'crown/buzzurl'
|
41
41
|
require 'crown/yahoo'
|
42
42
|
require 'crown/twitter'
|
43
|
+
require 'crown/topsy'
|
44
|
+
require 'crown/tweetmeme'
|
45
|
+
require 'crown/backtype'
|
46
|
+
require 'crown/facebook'
|
43
47
|
|
44
48
|
module Crown
|
45
|
-
VERSION = '0.0.
|
49
|
+
VERSION = '0.0.2'
|
46
50
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# --------------------------------------------------------------------------- #
|
3
|
+
#
|
4
|
+
# backtype.rb
|
5
|
+
#
|
6
|
+
# Copyright (c) 2008 - 2011, clown.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions
|
10
|
+
# are met:
|
11
|
+
#
|
12
|
+
# - Redistributions of source code must retain the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer.
|
14
|
+
# - Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in the
|
16
|
+
# documentation and/or other materials provided with the distribution.
|
17
|
+
# - No names of its contributors may be used to endorse or promote
|
18
|
+
# products derived from this software without specific prior written
|
19
|
+
# permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
# --------------------------------------------------------------------------- #
|
34
|
+
module Crown
|
35
|
+
module BackType
|
36
|
+
require 'cgi'
|
37
|
+
require 'net/http'
|
38
|
+
require 'crown/http'
|
39
|
+
require 'rubygems'
|
40
|
+
require 'json'
|
41
|
+
Net::HTTP.version_1_2
|
42
|
+
|
43
|
+
# ------------------------------------------------------------------- #
|
44
|
+
# count
|
45
|
+
# ------------------------------------------------------------------- #
|
46
|
+
def count(uri, api_key, proxy_host = nil, proxy_port = nil)
|
47
|
+
return 0 if (api_key == nil)
|
48
|
+
|
49
|
+
begin
|
50
|
+
session = Net::HTTP.new("api.backtype.com", 80, proxy_host, proxy_port)
|
51
|
+
path = "/tweetcount.json?q=" + CGI.escape(uri) + "&key=" + api_key
|
52
|
+
response = Crown::HTTP.get(session, path)
|
53
|
+
return nil if (response == nil || response.code.to_i != 200)
|
54
|
+
|
55
|
+
json = JSON.parse(response.body)
|
56
|
+
return json["tweetcount"].to_i
|
57
|
+
rescue Exception
|
58
|
+
return 0
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
module_function :count
|
63
|
+
end # BackTweets
|
64
|
+
end # Crown
|
data/lib/crown/buzzurl.rb
CHANGED
@@ -49,7 +49,8 @@ module Crown
|
|
49
49
|
# を指定する.
|
50
50
|
#
|
51
51
|
# ------------------------------------------------------------------- #
|
52
|
-
def count(uri,
|
52
|
+
def count(uri, proxy_host = nil, proxy_port = nil)
|
53
|
+
session = Net::HTTP.new('api.buzzurl.jp', 80, proxy_host, proxy_port)
|
53
54
|
path = '/api/counter/v1/json?url=' + CGI.escape(uri)
|
54
55
|
|
55
56
|
begin
|
data/lib/crown/delicious.rb
CHANGED
@@ -49,7 +49,8 @@ module Crown
|
|
49
49
|
# を指定する.
|
50
50
|
#
|
51
51
|
# ------------------------------------------------------------------- #
|
52
|
-
def count(uri,
|
52
|
+
def count(uri, proxy_host = nil, proxy_port = nil)
|
53
|
+
session = Net::HTTP.new('feeds.delicious.com', 80, proxy_host, proxy_port)
|
53
54
|
path = '/v2/json/urlinfo/blogbadge?hash=' + Digest::MD5.hexdigest(uri)
|
54
55
|
|
55
56
|
begin
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# --------------------------------------------------------------------------- #
|
3
|
+
#
|
4
|
+
# facebook.rb
|
5
|
+
#
|
6
|
+
# Copyright (c) 2008 - 2011, clown.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions
|
10
|
+
# are met:
|
11
|
+
#
|
12
|
+
# - Redistributions of source code must retain the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer.
|
14
|
+
# - Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in the
|
16
|
+
# documentation and/or other materials provided with the distribution.
|
17
|
+
# - No names of its contributors may be used to endorse or promote
|
18
|
+
# products derived from this software without specific prior written
|
19
|
+
# permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
# --------------------------------------------------------------------------- #
|
34
|
+
module Crown
|
35
|
+
module Facebook
|
36
|
+
require 'cgi'
|
37
|
+
require 'net/http'
|
38
|
+
require 'crown/http'
|
39
|
+
require 'rexml/document'
|
40
|
+
Net::HTTP.version_1_2
|
41
|
+
|
42
|
+
# ------------------------------------------------------------------- #
|
43
|
+
# structures
|
44
|
+
# ------------------------------------------------------------------- #
|
45
|
+
Counter = Struct.new(:like, :total, :share, :click)
|
46
|
+
|
47
|
+
# ------------------------------------------------------------------- #
|
48
|
+
# count
|
49
|
+
# ------------------------------------------------------------------- #
|
50
|
+
def count(uri, proxy_host = nil, proxy_port = nil)
|
51
|
+
begin
|
52
|
+
session = Net::HTTP.new("api.facebook.com", 80, proxy_host, proxy_port)
|
53
|
+
query = "select like_count, total_count, share_count, click_count from link_stat where url=\"" + uri + '"'
|
54
|
+
path = "/method/fql.query?query=" + CGI.escape(query)
|
55
|
+
response = Crown::HTTP.get(session, path)
|
56
|
+
return nil if (response == nil || response.code.to_i != 200)
|
57
|
+
|
58
|
+
xml = REXML::Document.new(response.body)
|
59
|
+
result = Counter.new
|
60
|
+
result.like = xml.elements['/fql_query_response/link_stat/like_count'].text.to_i
|
61
|
+
result.total = xml.elements['/fql_query_response/link_stat/total_count'].text.to_i
|
62
|
+
result.share = xml.elements['/fql_query_response/link_stat/share_count'].text.to_i
|
63
|
+
result.click = xml.elements['/fql_query_response/link_stat/click_count'].text.to_i
|
64
|
+
return result
|
65
|
+
rescue Exception
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module_function :count
|
71
|
+
end # Facebook
|
72
|
+
end # Crown
|
@@ -57,13 +57,13 @@ module Crown
|
|
57
57
|
# ----------------------------------------------------------- #
|
58
58
|
# initialize
|
59
59
|
# ----------------------------------------------------------- #
|
60
|
-
def initialize(path,
|
60
|
+
def initialize(path, proxy_host = nil, proxy_port = nil)
|
61
|
+
@session = Net::HTTP.new("b.hatena.ne.jp", 80, proxy_host, proxy_port)
|
61
62
|
@basename = String.new
|
62
63
|
@basename.concat("/") if (path[0] != 47)
|
63
64
|
@basename.concat(path)
|
64
65
|
@basename.concat("/") if (@basename.match(/^\/[\w\-]+$/) != nil && !@@reserved.include?(@basename))
|
65
66
|
@path = String.new(@basename)
|
66
|
-
@session = session
|
67
67
|
end
|
68
68
|
|
69
69
|
# ----------------------------------------------------------- #
|
@@ -150,12 +150,11 @@ module Crown
|
|
150
150
|
#
|
151
151
|
# count
|
152
152
|
#
|
153
|
-
# uri に指定したページのブックマーク数を取得する.
|
154
|
-
# には Net::HTTP クラス,またはその派生クラスのインスタンス
|
155
|
-
# を指定する.
|
153
|
+
# uri に指定したページのブックマーク数を取得する.
|
156
154
|
#
|
157
155
|
# --------------------------------------------------------------- #
|
158
|
-
def count(uri,
|
156
|
+
def count(uri, proxy_host = nil, proxy_port = nil)
|
157
|
+
session = Net::HTTP.new('api.b.st-hatena.com', 80, proxy_host, proxy_port)
|
159
158
|
path = "/entry.count?url=" + CGI.escape(uri)
|
160
159
|
begin
|
161
160
|
result = Crown::HTTP.get(session, path)
|
@@ -170,12 +169,11 @@ module Crown
|
|
170
169
|
#
|
171
170
|
# get
|
172
171
|
#
|
173
|
-
# uri に指定したページのブックマーク情報を取得する.
|
174
|
-
# には Net::HTTP クラス,またはその派生クラスのインスタンス
|
175
|
-
# を指定する.
|
172
|
+
# uri に指定したページのブックマーク情報を取得する.
|
176
173
|
#
|
177
174
|
# --------------------------------------------------------------- #
|
178
|
-
def get(uri,
|
175
|
+
def get(uri, proxy_host = nil, proxy_port = nil)
|
176
|
+
session = Net::HTTP.new('b.hatena.ne.jp', 80, proxy_host, proxy_port)
|
179
177
|
path = '/entry/json/?url=' + CGI.escape(uri)
|
180
178
|
|
181
179
|
begin
|
@@ -211,17 +209,15 @@ module Crown
|
|
211
209
|
# each
|
212
210
|
#
|
213
211
|
# LinkTrace クラスを使用してブックマークされている記事の URL
|
214
|
-
# 一覧を取得し,それらのブックマーク情報を順に返す.
|
215
|
-
# には Net::HTTP クラス,またはその派生クラスのインスタンス
|
216
|
-
# を指定する.
|
212
|
+
# 一覧を取得し,それらのブックマーク情報を順に返す.
|
217
213
|
#
|
218
214
|
# --------------------------------------------------------------- #
|
219
|
-
def each(query,
|
220
|
-
tracer = LinkTrace.new(query,
|
215
|
+
def each(query, proxy_host = nil, proxy_port = nil)
|
216
|
+
tracer = LinkTrace.new(query, proxy_host, proxy_port)
|
221
217
|
while (tracer.more?)
|
222
218
|
uris = tracer.get
|
223
219
|
uris.each { |uri|
|
224
|
-
result = Bookmark.get(uri,
|
220
|
+
result = Bookmark.get(uri, proxy_host, proxy_port)
|
225
221
|
yield(result) if (result != nil)
|
226
222
|
}
|
227
223
|
end
|
data/lib/crown/livedoor/clip.rb
CHANGED
@@ -44,9 +44,10 @@ module Crown
|
|
44
44
|
# uri に指定したページのクリップ数を取得する.
|
45
45
|
#
|
46
46
|
# --------------------------------------------------------------- #
|
47
|
-
def count(uri)
|
47
|
+
def count(uri, proxy_host = nil, proxy_port = nil)
|
48
48
|
begin
|
49
|
-
|
49
|
+
proxy = proxy_host + ':' + proxy_port.to_s if (proxy_host && proxy_port)
|
50
|
+
session = XMLRPC::Client.new2('http://rpc.clip.livedoor.com/count', proxy, 10).proxy('clip')
|
50
51
|
session.getCount(uri).each { |key, value|
|
51
52
|
return value.to_i
|
52
53
|
}
|
data/lib/crown/topsy.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# --------------------------------------------------------------------------- #
|
3
|
+
#
|
4
|
+
# topsy.rb
|
5
|
+
#
|
6
|
+
# Copyright (c) 2008 - 2011, clown.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions
|
10
|
+
# are met:
|
11
|
+
#
|
12
|
+
# - Redistributions of source code must retain the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer.
|
14
|
+
# - Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in the
|
16
|
+
# documentation and/or other materials provided with the distribution.
|
17
|
+
# - No names of its contributors may be used to endorse or promote
|
18
|
+
# products derived from this software without specific prior written
|
19
|
+
# permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
# --------------------------------------------------------------------------- #
|
34
|
+
module Crown
|
35
|
+
module Topsy
|
36
|
+
require 'cgi'
|
37
|
+
require 'net/http'
|
38
|
+
require 'crown/http'
|
39
|
+
require 'rubygems'
|
40
|
+
require 'json'
|
41
|
+
Net::HTTP.version_1_2
|
42
|
+
|
43
|
+
# ------------------------------------------------------------------- #
|
44
|
+
# count
|
45
|
+
# ------------------------------------------------------------------- #
|
46
|
+
def count(uri, proxy_host = nil, proxy_port = nil)
|
47
|
+
begin
|
48
|
+
session = Net::HTTP.new("otter.topsy.com", 80, proxy_host, proxy_port)
|
49
|
+
path = "urlinfo.json?url=" + CGI.escape(uri)
|
50
|
+
response = Crown::HTTP.get(session, path)
|
51
|
+
return nil if (response == nil || response.code.to_i != 200)
|
52
|
+
|
53
|
+
json = JSON.parse(response.body)
|
54
|
+
return json["response"]["trackback_total"].to_i
|
55
|
+
rescue Exception
|
56
|
+
return 0
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module_function :count
|
61
|
+
end # Topsy
|
62
|
+
end # Crown
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# --------------------------------------------------------------------------- #
|
3
|
+
#
|
4
|
+
# tweetmeme.rb
|
5
|
+
#
|
6
|
+
# Copyright (c) 2008 - 2011, clown.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions
|
10
|
+
# are met:
|
11
|
+
#
|
12
|
+
# - Redistributions of source code must retain the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer.
|
14
|
+
# - Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in the
|
16
|
+
# documentation and/or other materials provided with the distribution.
|
17
|
+
# - No names of its contributors may be used to endorse or promote
|
18
|
+
# products derived from this software without specific prior written
|
19
|
+
# permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
# --------------------------------------------------------------------------- #
|
34
|
+
module Crown
|
35
|
+
module TweetMeme
|
36
|
+
require 'cgi'
|
37
|
+
require 'net/http'
|
38
|
+
require 'crown/http'
|
39
|
+
require 'rubygems'
|
40
|
+
require 'json'
|
41
|
+
Net::HTTP.version_1_2
|
42
|
+
|
43
|
+
# ------------------------------------------------------------------- #
|
44
|
+
# count
|
45
|
+
# ------------------------------------------------------------------- #
|
46
|
+
def count(uri, proxy_host = nil, proxy_port = nil)
|
47
|
+
begin
|
48
|
+
session = Net::HTTP.new("api.tweetmeme.com", 80, proxy_host, proxy_port)
|
49
|
+
path = "/url_info.json?url=" + CGI.escape(uri)
|
50
|
+
response = Crown::HTTP.get(session, path)
|
51
|
+
return nil if (response == nil || response.code.to_i != 200)
|
52
|
+
|
53
|
+
json = JSON.parse(response.body)
|
54
|
+
return json["story"]["url_count"].to_i
|
55
|
+
rescue Exception => e
|
56
|
+
return 0
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module_function :count
|
61
|
+
end # TweetMeme
|
62
|
+
end # Crown
|
data/lib/crown/twitter.rb
CHANGED
@@ -32,13 +32,14 @@
|
|
32
32
|
#
|
33
33
|
# --------------------------------------------------------------------------- #
|
34
34
|
module Crown
|
35
|
-
require 'net/http'
|
36
|
-
require 'crown/http'
|
37
|
-
require 'rubygems'
|
38
|
-
require 'json'
|
39
|
-
Net::HTTP.version_1_2
|
40
|
-
|
41
35
|
module Twitter
|
36
|
+
require 'cgi'
|
37
|
+
require 'net/http'
|
38
|
+
require 'crown/http'
|
39
|
+
require 'rubygems'
|
40
|
+
require 'json'
|
41
|
+
Net::HTTP.version_1_2
|
42
|
+
|
42
43
|
# ------------------------------------------------------------------- #
|
43
44
|
# structures
|
44
45
|
# ------------------------------------------------------------------- #
|
@@ -47,10 +48,10 @@ module Crown
|
|
47
48
|
# ------------------------------------------------------------------- #
|
48
49
|
# count
|
49
50
|
# ------------------------------------------------------------------- #
|
50
|
-
def count(screen_name)
|
51
|
+
def count(screen_name, proxy_host = nil, proxy_port = nil)
|
51
52
|
begin
|
52
|
-
session = Net::HTTP.new("api.twitter.com", 80)
|
53
|
-
path = "/1/users/show.json?screen_name=" + screen_name
|
53
|
+
session = Net::HTTP.new("api.twitter.com", 80, proxy_host, proxy_port)
|
54
|
+
path = "/1/users/show.json?screen_name=" + CGI.escape(screen_name)
|
54
55
|
response = Crown::HTTP.get(session, path)
|
55
56
|
return nil if (response == nil || response.code.to_i != 200)
|
56
57
|
|
@@ -65,8 +66,6 @@ module Crown
|
|
65
66
|
rescue Exception
|
66
67
|
return nil
|
67
68
|
end
|
68
|
-
|
69
|
-
return nil
|
70
69
|
end
|
71
70
|
|
72
71
|
module_function :count
|
data/lib/crown/yahoo/bookmark.rb
CHANGED
@@ -49,7 +49,8 @@ module Crown
|
|
49
49
|
# を指定する.
|
50
50
|
#
|
51
51
|
# --------------------------------------------------------------- #
|
52
|
-
def count(uri,
|
52
|
+
def count(uri, proxy_host = nil, proxy_port = nil)
|
53
|
+
session = Net::HTTP.new('num.bookmarks.yahoo.co.jp', 80, proxy_host, proxy_port)
|
53
54
|
path = '/yjnostb.php?urls=' + CGI.escape(uri)
|
54
55
|
|
55
56
|
begin
|
data/test/crown_test.rb
CHANGED
@@ -95,6 +95,47 @@ class CrownTest < Test::Unit::TestCase
|
|
95
95
|
}
|
96
96
|
end
|
97
97
|
|
98
|
+
# ----------------------------------------------------------------------- #
|
99
|
+
# test_facebook_count
|
100
|
+
# ----------------------------------------------------------------------- #
|
101
|
+
def test_facebook_count
|
102
|
+
@@valid_uris.each { |uri|
|
103
|
+
counter = Crown::Facebook.count(uri)
|
104
|
+
assert(counter != nil, "failed in Crown::Facebook.count: " + uri)
|
105
|
+
assert(counter.like > 0, "wrong like count: " + uri)
|
106
|
+
assert(counter.total > 0, "wrong total count: " + uri)
|
107
|
+
assert(counter.share > 0, "wrong share count: " + uri)
|
108
|
+
assert(counter.click > 0, "wrong click count: " + uri)
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
# ----------------------------------------------------------------------- #
|
113
|
+
# test_topsy_count
|
114
|
+
# ----------------------------------------------------------------------- #
|
115
|
+
def test_topsy_count
|
116
|
+
@@valid_uris.each { |uri|
|
117
|
+
assert(Crown::Topsy.count(uri) > 0, "failed in " + uri)
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
# ----------------------------------------------------------------------- #
|
122
|
+
# test_tweetmeme_count
|
123
|
+
# ----------------------------------------------------------------------- #
|
124
|
+
def test_tweetmeme_count
|
125
|
+
@@valid_uris.each { |uri|
|
126
|
+
assert(Crown::TweetMeme.count(uri) > 0, "failed in " + uri)
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
# ----------------------------------------------------------------------- #
|
131
|
+
# test_backtype_count
|
132
|
+
# ----------------------------------------------------------------------- #
|
133
|
+
def test_backtype_count
|
134
|
+
@@valid_uris.each { |uri|
|
135
|
+
assert(Crown::BackType.count(uri, "your_api_key") > 0, "failed in " + uri)
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
98
139
|
# ----------------------------------------------------------------------- #
|
99
140
|
# test_twitter_count
|
100
141
|
# ----------------------------------------------------------------------- #
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- clown
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-19 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -51,15 +51,18 @@ files:
|
|
51
51
|
- Rakefile
|
52
52
|
- VERSION
|
53
53
|
- crown.gemspec
|
54
|
-
- lib/crown.gemspec
|
55
54
|
- lib/crown.rb
|
55
|
+
- lib/crown/backtype.rb
|
56
56
|
- lib/crown/buzzurl.rb
|
57
57
|
- lib/crown/delicious.rb
|
58
|
+
- lib/crown/facebook.rb
|
58
59
|
- lib/crown/hatena.rb
|
59
60
|
- lib/crown/hatena/bookmark.rb
|
60
61
|
- lib/crown/http.rb
|
61
62
|
- lib/crown/livedoor.rb
|
62
63
|
- lib/crown/livedoor/clip.rb
|
64
|
+
- lib/crown/topsy.rb
|
65
|
+
- lib/crown/tweetmeme.rb
|
63
66
|
- lib/crown/twitter.rb
|
64
67
|
- lib/crown/yahoo.rb
|
65
68
|
- lib/crown/yahoo/bookmark.rb
|
data/lib/crown.gemspec
DELETED
File without changes
|