crown 0.0.11 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/ChangeLog +11 -3
  2. data/README.rdoc +23 -1
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/crown.gemspec +28 -7
  6. data/example/cgmcount.rb +65 -0
  7. data/example/feedcount.rb +50 -0
  8. data/example/sbmcount.rb +5 -1
  9. data/lib/crown.rb +4 -14
  10. data/lib/crown/backtype.rb +29 -25
  11. data/lib/crown/backtype/counter.rb +79 -0
  12. data/lib/crown/buzzurl.rb +15 -28
  13. data/lib/crown/buzzurl/counter.rb +88 -0
  14. data/lib/crown/cgm.rb +98 -0
  15. data/lib/crown/cgm/countable.rb +130 -0
  16. data/lib/crown/cgm/summarizable.rb +130 -0
  17. data/lib/crown/delicious.rb +14 -29
  18. data/lib/crown/delicious/counter.rb +88 -0
  19. data/lib/crown/facebook.rb +32 -27
  20. data/lib/crown/facebook/counter.rb +76 -0
  21. data/lib/crown/facebook/entry.rb +86 -0
  22. data/lib/crown/hatena/bookmark.rb +26 -168
  23. data/lib/crown/hatena/bookmark/counter.rb +82 -0
  24. data/lib/crown/hatena/bookmark/entry.rb +108 -0
  25. data/lib/crown/hatena/bookmark/linktrace.rb +135 -0
  26. data/lib/crown/http-wrapper.rb +201 -0
  27. data/lib/crown/livedoor/clip.rb +15 -18
  28. data/lib/crown/livedoor/clip/counter.rb +96 -0
  29. data/lib/crown/livedoor/reader.rb +16 -19
  30. data/lib/crown/livedoor/reader/counter.rb +82 -0
  31. data/lib/crown/topsy.rb +20 -21
  32. data/lib/crown/topsy/counter.rb +78 -0
  33. data/lib/crown/tweetmeme.rb +20 -21
  34. data/lib/crown/tweetmeme/counter.rb +78 -0
  35. data/lib/crown/twitter.rb +14 -31
  36. data/lib/crown/{http.rb → twitter/uri.rb} +24 -39
  37. data/lib/crown/twitter/uri/counter.rb +86 -0
  38. data/lib/crown/twitter/user.rb +76 -0
  39. data/lib/crown/twitter/user/counter.rb +85 -0
  40. data/lib/crown/twitter/user/entry.rb +96 -0
  41. data/lib/crown/yahoo.rb +7 -3
  42. data/lib/crown/yahoo/bookmark.rb +23 -28
  43. data/lib/crown/yahoo/bookmark/counter.rb +84 -0
  44. data/test/{crown_test.rb → crown-test.rb} +46 -21
  45. data/test/{test_helper.rb → test-helper.rb} +1 -1
  46. metadata +30 -9
  47. data/lib/crown/amazon.rb +0 -157
  48. data/lib/crown/amazon/ecs.rb +0 -385
@@ -32,44 +32,29 @@
32
32
  #
33
33
  # --------------------------------------------------------------------------- #
34
34
  module Crown
35
- module Delicious
36
- require 'digest/md5'
37
- require 'net/http'
38
- require 'crown/http'
39
- require 'rubygems'
40
- require 'json'
41
- Net::HTTP.version_1_2
35
+ class Delicious
36
+ require 'crown/delicious/counter'
42
37
 
43
38
  # ------------------------------------------------------------------- #
44
39
  #
45
- # count
40
+ # Delicious.count
46
41
  #
47
- # uri に指定したページのブックマーク数を取得する.session
48
- # には Net::HTTP クラス,またはその派生クラスのインスタンス
49
- # を指定する.
42
+ # 指定した URL のブックマーク数を取得する.
50
43
  #
51
44
  # ------------------------------------------------------------------- #
52
- def count(uri, proxy_host = nil, proxy_port = nil)
53
- session = Net::HTTP.new('feeds.delicious.com', 80, proxy_host, proxy_port)
54
- path = '/v2/json/urlinfo/blogbadge?hash=' + Digest::MD5.hexdigest(uri)
55
-
56
- begin
57
- result = Crown::HTTP.get(session, path)
58
- return 0 if (result == nil || result.code.to_i != 200)
59
- json = JSON.parse(result.body)
60
- json.each { |elem|
61
- return elem['total_posts'].to_i
62
- }
63
- rescue Exception
64
- return 0
65
- end
66
-
67
- return 0
45
+ def Delicious.count(uri, options = nil)
46
+ return Crown::Delicious::BookmarkCounter.new.count(uri, options)
68
47
  end
69
48
 
70
49
  # ------------------------------------------------------------------- #
71
- # module functions
50
+ #
51
+ # count
52
+ #
53
+ # 指定した URL のブックマーク数を取得する.
54
+ #
72
55
  # ------------------------------------------------------------------- #
73
- module_function :count
56
+ def count(uri, options = nil)
57
+ return Crown::Delicious::BookmarkCounter.new.count(uri, options)
58
+ end
74
59
  end # Delicious
75
60
  end # Crown
@@ -0,0 +1,88 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # delicious/counter.rb
5
+ #
6
+ # Copyright (c) 2008 - 2012, 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
+ class Delicious
36
+ # --------------------------------------------------------------- #
37
+ #
38
+ # BookmarkCounter
39
+ #
40
+ # 指定した URL のブックマーク数を取得するクラス.
41
+ #
42
+ # --------------------------------------------------------------- #
43
+ class BookmarkCounter
44
+ require 'cgi'
45
+ require 'crown/cgm/countable'
46
+ require 'rubygems'
47
+ require 'json'
48
+
49
+ # --------------------------------------------------------------- #
50
+ # Mix-in modules
51
+ # --------------------------------------------------------------- #
52
+ include Crown::CGM::Countable
53
+
54
+ private
55
+ # --------------------------------------------------------------- #
56
+ # address
57
+ # --------------------------------------------------------------- #
58
+ def address()
59
+ return 'feeds.delicious.com'
60
+ end
61
+
62
+ # --------------------------------------------------------------- #
63
+ # path
64
+ # --------------------------------------------------------------- #
65
+ def path()
66
+ return '/v2/json/urlinfo/data'
67
+ end
68
+
69
+ # --------------------------------------------------------------- #
70
+ # query
71
+ # --------------------------------------------------------------- #
72
+ def query(uri, options)
73
+ return '?url=' + CGI.escape(uri)
74
+ end
75
+
76
+ # --------------------------------------------------------------- #
77
+ # parse
78
+ # --------------------------------------------------------------- #
79
+ def parse(body)
80
+ json = JSON.parse(body)
81
+ json.each { |elem|
82
+ return elem['total_posts'].to_i
83
+ }
84
+ return error_value()
85
+ end
86
+ end # BookmarkCounter
87
+ end # Delicious
88
+ end # Crown
@@ -32,41 +32,46 @@
32
32
  #
33
33
  # --------------------------------------------------------------------------- #
34
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
35
+ class Facebook
36
+ require 'crown/facebook/counter'
37
+ require 'crown/facebook/entry'
41
38
 
42
39
  # ------------------------------------------------------------------- #
43
- # structures
40
+ #
41
+ # Facebook.count
42
+ #
43
+ # 指定した URL に対する「いいね!」数(「いいね!」と「シェア」の
44
+ # 合計数)を取得する.
45
+ #
44
46
  # ------------------------------------------------------------------- #
45
- Counter = Struct.new(:like, :total, :share, :click)
47
+ def Facebook.count(uri, options = nil)
48
+ return Crown::FacebookCounter.new.count(uri, options)
49
+ end
50
+
51
+ # ------------------------------------------------------------------- #
52
+ # Facebook.summary
53
+ # ------------------------------------------------------------------- #
54
+ def Facebook.summary(uri, options = nil)
55
+ return Crown::FacebookEntry.new.summary(uri, options)
56
+ end
46
57
 
47
58
  # ------------------------------------------------------------------- #
59
+ #
48
60
  # count
61
+ #
62
+ # 指定した URL に対する「いいね!」数(「いいね!」と「シェア」の
63
+ # 合計数)を取得する.
64
+ #
49
65
  # ------------------------------------------------------------------- #
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
66
+ def count(uri, options = nil)
67
+ return Crown::FacebookCounter.new.count(uri, options)
68
68
  end
69
69
 
70
- module_function :count
70
+ # ------------------------------------------------------------------- #
71
+ # summary
72
+ # ------------------------------------------------------------------- #
73
+ def summary(uri, options = nil)
74
+ return Crown::FacebookEntry.new.summary(uri, options)
75
+ end
71
76
  end # Facebook
72
77
  end # Crown
@@ -0,0 +1,76 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # facebook/counter.rb
5
+ #
6
+ # Copyright (c) 2008 - 2012, 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
+ class FacebookCounter
36
+ require 'cgi'
37
+ require 'rexml/document'
38
+ require 'crown/cgm/countable'
39
+
40
+ # ------------------------------------------------------------------- #
41
+ # Mix-in modules
42
+ # ------------------------------------------------------------------- #
43
+ include Crown::CGM::Countable
44
+
45
+ private
46
+ # --------------------------------------------------------------- #
47
+ # address
48
+ # --------------------------------------------------------------- #
49
+ def address()
50
+ return 'api.facebook.com'
51
+ end
52
+
53
+ # --------------------------------------------------------------- #
54
+ # path
55
+ # --------------------------------------------------------------- #
56
+ def path()
57
+ return '/method/fql.query'
58
+ end
59
+
60
+ # --------------------------------------------------------------- #
61
+ # query
62
+ # --------------------------------------------------------------- #
63
+ def query(uri, options)
64
+ str = 'select total_count from link_stat where url="' + uri + '"'
65
+ return '?query=' + CGI.escape(str)
66
+ end
67
+
68
+ # --------------------------------------------------------------- #
69
+ # parse
70
+ # --------------------------------------------------------------- #
71
+ def parse(body)
72
+ xml = REXML::Document.new(body)
73
+ return xml.elements['/fql_query_response/link_stat/total_count'].text.to_i
74
+ end
75
+ end # FacebookCounter
76
+ end # Crown
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # facebook/entry.rb
5
+ #
6
+ # Copyright (c) 2008 - 2012, 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
+ class FacebookEntry
36
+ require 'cgi'
37
+ require 'rexml/document'
38
+ require 'crown/cgm/summarizable'
39
+
40
+ # ------------------------------------------------------------------- #
41
+ # Mix-in modules
42
+ # ------------------------------------------------------------------- #
43
+ include Crown::CGM::Summarizable
44
+
45
+ # ------------------------------------------------------------------- #
46
+ # structures
47
+ # ------------------------------------------------------------------- #
48
+ Response = Struct.new(:like, :total, :share, :click)
49
+
50
+ private
51
+ # --------------------------------------------------------------- #
52
+ # address
53
+ # --------------------------------------------------------------- #
54
+ def address()
55
+ return 'api.facebook.com'
56
+ end
57
+
58
+ # --------------------------------------------------------------- #
59
+ # path
60
+ # --------------------------------------------------------------- #
61
+ def path()
62
+ return '/method/fql.query'
63
+ end
64
+
65
+ # --------------------------------------------------------------- #
66
+ # query
67
+ # --------------------------------------------------------------- #
68
+ def query(uri, options)
69
+ str = 'select like_count, total_count, share_count, click_count from link_stat where url="' + uri + '"'
70
+ return '?query=' + CGI.escape(str)
71
+ end
72
+
73
+ # --------------------------------------------------------------- #
74
+ # parse
75
+ # --------------------------------------------------------------- #
76
+ def parse(body)
77
+ xml = REXML::Document.new(body)
78
+ result = Response.new
79
+ result.like = xml.elements['/fql_query_response/link_stat/like_count'].text.to_i
80
+ result.total = xml.elements['/fql_query_response/link_stat/total_count'].text.to_i
81
+ result.share = xml.elements['/fql_query_response/link_stat/share_count'].text.to_i
82
+ result.click = xml.elements['/fql_query_response/link_stat/click_count'].text.to_i
83
+ return result
84
+ end
85
+ end # FacebookCounter
86
+ end # Crown
@@ -33,202 +33,60 @@
33
33
  # --------------------------------------------------------------------------- #
34
34
  module Crown
35
35
  module Hatena
36
- module Bookmark
37
- require 'cgi'
38
- require 'net/http'
39
- require 'crown/http'
40
- require 'rubygems'
41
- require 'json'
42
- require 'nokogiri'
43
- Net::HTTP.version_1_2
36
+ # --------------------------------------------------------------- #
37
+ #
38
+ # Bookmark
39
+ #
40
+ # はてなブックマーク API 経由の各種情報を取得するクラス.
41
+ #
42
+ # --------------------------------------------------------------- #
43
+ class Bookmark
44
+ require 'crown/hatena/bookmark/counter'
45
+ require 'crown/hatena/bookmark/entry'
44
46
 
45
47
  # --------------------------------------------------------------- #
46
48
  #
47
- # LinkTrace
49
+ # Bookmark.count
48
50
  #
49
- # 指定した Web サイトのはてなブックマーク一覧から順に URL
50
- # 取得するクラス.2 ページ目以降の結果は,html のヘッダ情報の
51
- # next 属性からページの URL を推測して取得する.
51
+ # 指定した URL のブックマーク数を取得する
52
52
  #
53
53
  # --------------------------------------------------------------- #
54
- class LinkTrace
55
- @@reserved = [ "/hotentry", "/entrylist", "/news", "/video", "/asin" ]
56
-
57
- # ----------------------------------------------------------- #
58
- # initialize
59
- # ----------------------------------------------------------- #
60
- def initialize(path, proxy_host = nil, proxy_port = nil)
61
- @session = Net::HTTP.new("b.hatena.ne.jp", 80, proxy_host, proxy_port)
62
- @basename = String.new
63
- @basename.concat("/") if (path[0] != 47)
64
- @basename.concat(path)
65
- @basename.concat("/") if (@basename.match(/^\/[\w\-]+$/) != nil && !@@reserved.include?(@basename))
66
- @path = String.new(@basename)
67
- end
68
-
69
- # ----------------------------------------------------------- #
70
- # reset
71
- # ----------------------------------------------------------- #
72
- def reset()
73
- @path = String.new(@basename)
74
- @session.finish if (@session.active?)
75
- return self
76
- end
77
-
78
- # ----------------------------------------------------------- #
79
- #
80
- # more?
81
- #
82
- # まだ取得できる URL が存在するかどうかを判定する.next?()
83
- # は html の next 属性から次のページが推測できているか
84
- # どうかで判定している.
85
- #
86
- # ----------------------------------------------------------- #
87
- def more?()
88
- return @path != nil
89
- end
90
-
91
- # ----------------------------------------------------------- #
92
- #
93
- # get
94
- #
95
- # 対象となるはてなブックマーク URL を返す.get() は html の
96
- # next 属性から推測された「現在のページ」に列挙されてある
97
- # 全てのはてなブックマーク URL を配列に格納して返す.
98
- #
99
- # ----------------------------------------------------------- #
100
- def get()
101
- result = Array.new
102
-
103
- return result if (@path == nil)
104
- response = Crown::HTTP.get(@session, @path)
105
- return result if (response == nil || response.code.to_i != 200)
106
- guess(response.body)
107
-
108
- html = Nokogiri::HTML.parse(response.body)
109
- block = html.search('//ul[starts-with(@class, "hotentry")]')
110
- block = html.search('//ul[starts-with(@class, "videolist")]') if block.empty?
111
- return result if block.empty?
112
- block[0].search("h3/a").each { |node|
113
- result.push(node['href'])
114
- }
115
-
116
- # 無限ループする場合があるので,現在のページから 1件も結果が
117
- # 取得できないときはこれ以上の検索を止める.
118
- @path = nil if (result.empty?)
119
-
120
- return result
121
- end
122
-
123
- private
124
- # ----------------------------------------------------------- #
125
- # guess
126
- # ----------------------------------------------------------- #
127
- def guess(str)
128
- link = str.scan(/<link rel="next" href="(.+?)".*?>/m).to_s
129
- if (link.empty?)
130
- @path = nil
131
- elsif (link[0] == 47)
132
- @path = link
133
- elsif (link[0] == 63)
134
- @path.gsub!(/\?.*$/, "")
135
- @path.concat(link)
136
- else
137
- @path = @basename + link
138
- end
139
- end
54
+ def Bookmark.count(uri, options = nil)
55
+ return Crown::Hatena::BookmarkCounter.new.count(uri, options)
140
56
  end
141
57
 
142
- # --------------------------------------------------------------- #
143
- # structures
144
- # --------------------------------------------------------------- #
145
- User = Struct.new(:tags, :date, :comment)
146
- Related = Struct.new(:eid, :uri, :title, :count)
147
- Response = Struct.new(:eid, :uri, :image, :title, :count, :users, :related)
148
-
149
58
  # --------------------------------------------------------------- #
150
59
  #
151
- # count
60
+ # Bookmark.summary
152
61
  #
153
- # uri に指定したページのブックマーク数を取得する.
62
+ # 指定した URL のブックマーク情報を取得する
154
63
  #
155
64
  # --------------------------------------------------------------- #
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)
158
- path = '/entry.count?url=' + CGI.escape(uri)
159
- begin
160
- result = Crown::HTTP.get(session, path)
161
- return 0 if (result == nil || result.code.to_i != 200)
162
- return result.body.to_i
163
- rescue Exception => e
164
- return 0
165
- end
65
+ def Bookmark.summary(uri, options = nil)
66
+ return Crown::Hatena::BookmarkEntry.new.summary(uri, options)
166
67
  end
167
68
 
168
69
  # --------------------------------------------------------------- #
169
70
  #
170
- # get
71
+ # count
171
72
  #
172
- # uri に指定したページのブックマーク情報を取得する.
73
+ # 指定した URL のブックマーク数を取得する
173
74
  #
174
75
  # --------------------------------------------------------------- #
175
- def get(uri, proxy_host = nil, proxy_port = nil)
176
- session = Net::HTTP.new('b.hatena.ne.jp', 80, proxy_host, proxy_port)
177
- path = '/entry/json/?url=' + CGI.escape(uri)
178
-
179
- begin
180
- result = Crown::HTTP.get(session, path)
181
- return nil if (result == nil || result.code.to_i != 200)
182
- json = JSON.parse(result.body)
183
-
184
- users = Hash.new
185
- json['bookmarks'].each { |item|
186
- tags = Array.new
187
- item['tags'].each { |tag|
188
- tags.push(tag)
189
- }
190
- date = Time.local(*item['timestamp'].split(/\W/))
191
- entry = User.new(tags, date, item['comment'])
192
- users[item['user']] = entry
193
- }
194
-
195
- related = Array.new()
196
- json['related'].each { |item|
197
- entry = Related.new(item['eid'].to_i, item['url'], item['title'], item['count'].to_i)
198
- related.push(entry)
199
- }
200
- rescue Exception
201
- return nil
202
- end
203
-
204
- return Response.new(json['eid'].to_i, json['url'], json['screenshot'], json['title'], json['count'].to_i, users, related)
76
+ def count(uri, options = nil)
77
+ return Crown::Hatena::BookmarkCounter.new.count(uri, options)
205
78
  end
206
79
 
207
80
  # --------------------------------------------------------------- #
208
81
  #
209
- # each
82
+ # summary
210
83
  #
211
- # LinkTrace クラスを使用してブックマークされている記事の URL
212
- # 一覧を取得し,それらのブックマーク情報を順に返す.
84
+ # 指定した URL のブックマーク情報を取得する
213
85
  #
214
86
  # --------------------------------------------------------------- #
215
- def each(query, proxy_host = nil, proxy_port = nil)
216
- tracer = LinkTrace.new(query, proxy_host, proxy_port)
217
- while (tracer.more?)
218
- uris = tracer.get
219
- uris.each { |uri|
220
- result = Bookmark.get(uri, proxy_host, proxy_port)
221
- yield(result) if (result != nil)
222
- }
223
- end
87
+ def summary(uri, options = nil)
88
+ return Crown::Hatena::BookmarkEntry.new.summary(uri, options)
224
89
  end
225
-
226
- # --------------------------------------------------------------- #
227
- # module functions
228
- # --------------------------------------------------------------- #
229
- module_function :count
230
- module_function :get
231
- module_function :each
232
90
  end # Bookmark
233
91
  end # Hatena
234
92
  end # Crown