crown 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/ChangeLog +4 -0
  2. data/README.rdoc +14 -11
  3. data/VERSION +1 -1
  4. data/crown.gemspec +15 -5
  5. data/example/entrylist.rb +69 -0
  6. data/example/fbcount.rb +1 -1
  7. data/example/hbentry.rb +1 -1
  8. data/example/rtcount.rb +1 -0
  9. data/example/twcount.rb +1 -1
  10. data/example/{annual.rb → urilist.rb} +21 -26
  11. data/lib/crown.rb +1 -1
  12. data/{example/hbtrace.rb → lib/crown/amazon.rb} +8 -23
  13. data/lib/crown/amazon/crawler.rb +159 -0
  14. data/lib/crown/amazon/ecs.rb +385 -0
  15. data/lib/crown/amazon/entrylist.rb +171 -0
  16. data/lib/crown/backtype.rb +2 -2
  17. data/lib/crown/buzzurl.rb +2 -2
  18. data/lib/crown/cgm.rb +8 -0
  19. data/lib/crown/cgm/countable.rb +1 -1
  20. data/lib/crown/cgm/summarizable.rb +1 -1
  21. data/lib/crown/delicious.rb +2 -2
  22. data/lib/crown/facebook.rb +4 -4
  23. data/lib/crown/facebook/entry.rb +5 -3
  24. data/lib/crown/google.rb +38 -0
  25. data/lib/crown/google/plusone.rb +65 -0
  26. data/lib/crown/google/plusone/counter.rb +102 -0
  27. data/lib/crown/hatena/bookmark.rb +7 -7
  28. data/lib/crown/hatena/bookmark/entry.rb +70 -68
  29. data/lib/crown/hatena/bookmark/entrylist.rb +98 -0
  30. data/lib/crown/hatena/bookmark/urilist.rb +349 -0
  31. data/lib/crown/http-wrapper.rb +0 -1
  32. data/lib/crown/linkedin.rb +60 -0
  33. data/lib/crown/linkedin/counter.rb +81 -0
  34. data/lib/crown/livedoor/clip.rb +2 -2
  35. data/lib/crown/livedoor/clip/counter.rb +1 -1
  36. data/lib/crown/livedoor/reader.rb +2 -2
  37. data/lib/crown/topsy.rb +2 -3
  38. data/lib/crown/tweetmeme.rb +2 -2
  39. data/lib/crown/twitter.rb +1 -1
  40. data/lib/crown/twitter/uri.rb +2 -2
  41. data/lib/crown/twitter/user.rb +4 -4
  42. data/lib/crown/twitter/user/entry.rb +26 -6
  43. data/lib/crown/yahoo/bookmark.rb +3 -7
  44. data/test/crown-test.rb +34 -12
  45. metadata +17 -7
  46. data/lib/crown/hatena/bookmark/linktrace.rb +0 -135
@@ -46,7 +46,7 @@ module Crown
46
46
  # BackType で取得した API key).
47
47
  #
48
48
  # ------------------------------------------------------------------- #
49
- def Topsy.count(uri, options = nil)
49
+ def Topsy.count(uri, options = {})
50
50
  return Crown::BackType::URICounter.new.count(uri, options)
51
51
  end
52
52
 
@@ -61,7 +61,7 @@ module Crown
61
61
  # BackType で取得した API key).
62
62
  #
63
63
  # ------------------------------------------------------------------- #
64
- def count(uri, options = nil)
64
+ def count(uri, options = {})
65
65
  return Crown::BackType::URICounter.new.count(uri, options)
66
66
  end
67
67
  end # BackType
@@ -42,7 +42,7 @@ module Crown
42
42
  # 指定した URL のブックマーク数を取得する.
43
43
  #
44
44
  # ------------------------------------------------------------------- #
45
- def Buzzurl.count(uri, options = nil)
45
+ def Buzzurl.count(uri, options = {})
46
46
  return Crown::Buzzurl::BookmarkCounter.new.count(uri, options)
47
47
  end
48
48
 
@@ -53,7 +53,7 @@ module Crown
53
53
  # 指定した URL のブックマーク数を取得する.
54
54
  #
55
55
  # ------------------------------------------------------------------- #
56
- def count(uri, options = nil)
56
+ def count(uri, options = {})
57
57
  return Crown::Buzzurl::BookmarkCounter.new.count(uri, options)
58
58
  end
59
59
  end # Buzzurl
@@ -38,6 +38,8 @@ module Crown
38
38
  require 'crown/tweetmeme'
39
39
  require 'crown/backtype'
40
40
  require 'crown/facebook'
41
+ require 'crown/google'
42
+ require 'crown/linkedin'
41
43
  require 'crown/hatena/bookmark'
42
44
  require 'crown/livedoor/clip'
43
45
  require 'crown/livedoor/reader'
@@ -62,6 +64,10 @@ module Crown
62
64
  # http://backtweets.com/
63
65
  # - Facebook
64
66
  # http://www.facebook.com/
67
+ # - Google+1
68
+ # http://www.google.com/intl/ja/+1/button/
69
+ # - LinkedIn
70
+ # http://www.linkedin.com/
65
71
  # - はてなブックマーク
66
72
  # http://b.hatena.ne.jp/
67
73
  # - Livedoor クリップ
@@ -84,6 +90,8 @@ module Crown
84
90
  when :tweetmeme then return Crown::TweetMeme.new
85
91
  when :backtype then return Crown::BackType.new
86
92
  when :facebook then return Crown::Facebook.new
93
+ when :google_plus1 then return Crown::Google::PlusOne.new
94
+ when :linkedin then return Crown::LinkedIn.new
87
95
  when :hatena_bookmark then return Crown::Hatena::Bookmark.new
88
96
  when :livedoor_clip then return Crown::Livedoor::Clip.new
89
97
  when :livedoor_reader then return Crown::Livedoor::Reader.new
@@ -106,7 +106,7 @@ module Crown
106
106
  # --------------------------------------------------------------- #
107
107
  # count
108
108
  # --------------------------------------------------------------- #
109
- def count(uri, options = nil)
109
+ def count(uri, options = {})
110
110
  begin
111
111
  proxy_addr = nil
112
112
  proxy_port = nil
@@ -106,7 +106,7 @@ module Crown
106
106
  # --------------------------------------------------------------- #
107
107
  # summary
108
108
  # --------------------------------------------------------------- #
109
- def summary(uri, options = nil)
109
+ def summary(uri, options = {})
110
110
  begin
111
111
  proxy_addr = nil
112
112
  proxy_port = nil
@@ -42,7 +42,7 @@ module Crown
42
42
  # 指定した URL のブックマーク数を取得する.
43
43
  #
44
44
  # ------------------------------------------------------------------- #
45
- def Delicious.count(uri, options = nil)
45
+ def Delicious.count(uri, options = {})
46
46
  return Crown::Delicious::BookmarkCounter.new.count(uri, options)
47
47
  end
48
48
 
@@ -53,7 +53,7 @@ module Crown
53
53
  # 指定した URL のブックマーク数を取得する.
54
54
  #
55
55
  # ------------------------------------------------------------------- #
56
- def count(uri, options = nil)
56
+ def count(uri, options = {})
57
57
  return Crown::Delicious::BookmarkCounter.new.count(uri, options)
58
58
  end
59
59
  end # Delicious
@@ -44,14 +44,14 @@ module Crown
44
44
  # 合計数)を取得する.
45
45
  #
46
46
  # ------------------------------------------------------------------- #
47
- def Facebook.count(uri, options = nil)
47
+ def Facebook.count(uri, options = {})
48
48
  return Crown::FacebookCounter.new.count(uri, options)
49
49
  end
50
50
 
51
51
  # ------------------------------------------------------------------- #
52
52
  # Facebook.summary
53
53
  # ------------------------------------------------------------------- #
54
- def Facebook.summary(uri, options = nil)
54
+ def Facebook.summary(uri, options = {})
55
55
  return Crown::FacebookEntry.new.summary(uri, options)
56
56
  end
57
57
 
@@ -63,14 +63,14 @@ module Crown
63
63
  # 合計数)を取得する.
64
64
  #
65
65
  # ------------------------------------------------------------------- #
66
- def count(uri, options = nil)
66
+ def count(uri, options = {})
67
67
  return Crown::FacebookCounter.new.count(uri, options)
68
68
  end
69
69
 
70
70
  # ------------------------------------------------------------------- #
71
71
  # summary
72
72
  # ------------------------------------------------------------------- #
73
- def summary(uri, options = nil)
73
+ def summary(uri, options = {})
74
74
  return Crown::FacebookEntry.new.summary(uri, options)
75
75
  end
76
76
  end # Facebook
@@ -45,7 +45,7 @@ module Crown
45
45
  # ------------------------------------------------------------------- #
46
46
  # structures
47
47
  # ------------------------------------------------------------------- #
48
- Response = Struct.new(:like, :total, :share, :click)
48
+ Response = Struct.new(:like, :total, :share, :click, :comment, :commentsbox)
49
49
 
50
50
  private
51
51
  # --------------------------------------------------------------- #
@@ -66,7 +66,7 @@ module Crown
66
66
  # query
67
67
  # --------------------------------------------------------------- #
68
68
  def query(uri, options)
69
- str = 'select like_count, total_count, share_count, click_count from link_stat where url="' + uri + '"'
69
+ str = 'select like_count, total_count, share_count, click_count, comment_count, commentsbox_count from link_stat where url="' + uri + '"'
70
70
  return '?query=' + CGI.escape(str)
71
71
  end
72
72
 
@@ -76,10 +76,12 @@ module Crown
76
76
  def parse(body)
77
77
  xml = REXML::Document.new(body)
78
78
  result = Response.new
79
- result.like = xml.elements['/fql_query_response/link_stat/like_count'].text.to_i
79
+ result.like = xml.elements['/fql_query_response/link_stat/like_count'].text.to_i
80
80
  result.total = xml.elements['/fql_query_response/link_stat/total_count'].text.to_i
81
81
  result.share = xml.elements['/fql_query_response/link_stat/share_count'].text.to_i
82
82
  result.click = xml.elements['/fql_query_response/link_stat/click_count'].text.to_i
83
+ result.comment = xml.elements['/fql_query_response/link_stat/comment_count'].text.to_i
84
+ result.commentsbox = xml.elements['/fql_query_response/link_stat/commentsbox_count'].text.to_i
83
85
  return result
84
86
  end
85
87
  end # FacebookCounter
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # google.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
+ module Google
36
+ require 'crown/google/plusone'
37
+ end # Google
38
+ end # Crown
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # google/plusone.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
+ module Google
36
+ # ------------------------------------------------------------------- #
37
+ # PlusOne
38
+ # ------------------------------------------------------------------- #
39
+ class PlusOne
40
+ require 'crown/google/plusone/counter'
41
+
42
+ # --------------------------------------------------------------- #
43
+ #
44
+ # PlusOne.count
45
+ #
46
+ # 指定した URL のカウント数を取得する
47
+ #
48
+ # --------------------------------------------------------------- #
49
+ def PlusOne.count(uri, options = {})
50
+ return Crown::Google::PlusOne::URICounter.new.count(uri, options)
51
+ end
52
+
53
+ # --------------------------------------------------------------- #
54
+ #
55
+ # count
56
+ #
57
+ # 指定した URL のカウント数を取得する
58
+ #
59
+ # --------------------------------------------------------------- #
60
+ def count(uri, options = {})
61
+ return Crown::Google::PlusOne::URICounter.new.count(uri, options)
62
+ end
63
+ end # Bookmark
64
+ end # Google
65
+ end # Crown
@@ -0,0 +1,102 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # google/plusone/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
+ module Google
36
+ class PlusOne
37
+ # --------------------------------------------------------------- #
38
+ #
39
+ # URICounter
40
+ #
41
+ # NOTE: 現在,Google+1 のカウント数を取得するためには API key
42
+ # を要求される.そのため,暫定的な回避策としてサードパーティ
43
+ # から提供されている API を経由してカウント数を取得している.
44
+ #
45
+ # Google+1 counts are retrieved via a JSON-RPC POST call.
46
+ # POST URL:
47
+ # https://clients6.google.com/rpc?key=<your_api_key>
48
+ # POST Body:
49
+ # [{"method":"pos.plusones.get","id":"p",
50
+ # "params":{"nolog":true,"id":"%%URL%%","source":"widget",
51
+ # "userId":"@viewer","groupId":"@self"
52
+ # },
53
+ # "jsonrpc":"2.0","key":"p","apiVersion":"v1"
54
+ # }]
55
+ #
56
+ # see also: http://sharedcount.com/
57
+ #
58
+ # --------------------------------------------------------------- #
59
+ class URICounter
60
+ require 'cgi'
61
+ require 'crown/cgm/countable'
62
+ require 'rubygems'
63
+ require 'json'
64
+
65
+ # ----------------------------------------------------------- #
66
+ # Mix-in modules
67
+ # ----------------------------------------------------------- #
68
+ include Crown::CGM::Countable
69
+
70
+ private
71
+ # ----------------------------------------------------------- #
72
+ # address
73
+ # ----------------------------------------------------------- #
74
+ def address()
75
+ return 'api.sharedcount.com'
76
+ end
77
+
78
+ # ----------------------------------------------------------- #
79
+ # path
80
+ # ----------------------------------------------------------- #
81
+ def path()
82
+ return '/'
83
+ end
84
+
85
+ # ----------------------------------------------------------- #
86
+ # query
87
+ # ----------------------------------------------------------- #
88
+ def query(uri, options)
89
+ return '?url=' + CGI.escape(uri)
90
+ end
91
+
92
+ # ----------------------------------------------------------- #
93
+ # parse
94
+ # ----------------------------------------------------------- #
95
+ def parse(body)
96
+ json = JSON.parse(body)
97
+ return json["GooglePlusOne"].to_i
98
+ end
99
+ end # URICounter
100
+ end # PlusOne
101
+ end # Google
102
+ end # Crown
@@ -42,7 +42,7 @@ module Crown
42
42
  # --------------------------------------------------------------- #
43
43
  class Bookmark
44
44
  require 'crown/hatena/bookmark/counter'
45
- require 'crown/hatena/bookmark/entry'
45
+ require 'crown/hatena/bookmark/entrylist'
46
46
 
47
47
  # --------------------------------------------------------------- #
48
48
  #
@@ -51,7 +51,7 @@ module Crown
51
51
  # 指定した URL のブックマーク数を取得する
52
52
  #
53
53
  # --------------------------------------------------------------- #
54
- def Bookmark.count(uri, options = nil)
54
+ def Bookmark.count(uri, options = {})
55
55
  return Crown::Hatena::BookmarkCounter.new.count(uri, options)
56
56
  end
57
57
 
@@ -62,8 +62,8 @@ module Crown
62
62
  # 指定した URL のブックマーク情報を取得する
63
63
  #
64
64
  # --------------------------------------------------------------- #
65
- def Bookmark.summary(uri, options = nil)
66
- return Crown::Hatena::BookmarkEntry.new.summary(uri, options)
65
+ def Bookmark.summary(uri, options = {})
66
+ return Crown::Hatena::Bookmark::Entry.new.summary(uri, options)
67
67
  end
68
68
 
69
69
  # --------------------------------------------------------------- #
@@ -73,7 +73,7 @@ module Crown
73
73
  # 指定した URL のブックマーク数を取得する
74
74
  #
75
75
  # --------------------------------------------------------------- #
76
- def count(uri, options = nil)
76
+ def count(uri, options = {})
77
77
  return Crown::Hatena::BookmarkCounter.new.count(uri, options)
78
78
  end
79
79
 
@@ -84,8 +84,8 @@ module Crown
84
84
  # 指定した URL のブックマーク情報を取得する
85
85
  #
86
86
  # --------------------------------------------------------------- #
87
- def summary(uri, options = nil)
88
- return Crown::Hatena::BookmarkEntry.new.summary(uri, options)
87
+ def summary(uri, options = {})
88
+ return Crown::Hatena::Bookmark::Entry.new.summary(uri, options)
89
89
  end
90
90
  end # Bookmark
91
91
  end # Hatena
@@ -33,76 +33,78 @@
33
33
  # --------------------------------------------------------------------------- #
34
34
  module Crown
35
35
  module Hatena
36
- # --------------------------------------------------------------- #
37
- # BookmarkEntry
38
- # --------------------------------------------------------------- #
39
- class BookmarkEntry
40
- require 'cgi'
41
- require 'crown/cgm/summarizable'
42
- require 'rubygems'
43
- require 'json'
44
-
36
+ class Bookmark
45
37
  # --------------------------------------------------------------- #
46
- # Mix-in modules
38
+ # Entry
47
39
  # --------------------------------------------------------------- #
48
- include Crown::CGM::Summarizable
49
-
50
- # --------------------------------------------------------------- #
51
- # structures
52
- # --------------------------------------------------------------- #
53
- User = Struct.new(:tags, :date, :comment)
54
- Related = Struct.new(:eid, :uri, :title, :count)
55
- Response = Struct.new(:eid, :uri, :image, :title, :count, :users, :related)
56
-
57
- private
58
- # --------------------------------------------------------------- #
59
- # address
60
- # --------------------------------------------------------------- #
61
- def address()
62
- return 'b.hatena.ne.jp'
63
- end
64
-
65
- # --------------------------------------------------------------- #
66
- # path
67
- # --------------------------------------------------------------- #
68
- def path()
69
- return '/entry/json/'
70
- end
71
-
72
- # --------------------------------------------------------------- #
73
- # query
74
- # --------------------------------------------------------------- #
75
- def query(uri, options)
76
- return '?url=' + CGI.escape(uri)
77
- end
78
-
79
- # --------------------------------------------------------------- #
80
- # parse
81
- # --------------------------------------------------------------- #
82
- def parse(body)
83
- json = JSON.parse(body)
84
-
85
- # ���[�U���̉��
86
- users = Hash.new
87
- json['bookmarks'].each { |item|
88
- tags = Array.new
89
- item['tags'].each { |tag|
90
- tags.push(tag)
40
+ class Entry
41
+ require 'cgi'
42
+ require 'crown/cgm/summarizable'
43
+ require 'rubygems'
44
+ require 'json'
45
+
46
+ # ----------------------------------------------------------- #
47
+ # Mix-in modules
48
+ # ----------------------------------------------------------- #
49
+ include Crown::CGM::Summarizable
50
+
51
+ # ----------------------------------------------------------- #
52
+ # structures
53
+ # ----------------------------------------------------------- #
54
+ User = Struct.new(:tags, :date, :comment)
55
+ Related = Struct.new(:eid, :uri, :title, :count)
56
+ Response = Struct.new(:eid, :uri, :image, :title, :count, :users, :related)
57
+
58
+ private
59
+ # ----------------------------------------------------------- #
60
+ # address
61
+ # ----------------------------------------------------------- #
62
+ def address()
63
+ return 'b.hatena.ne.jp'
64
+ end
65
+
66
+ # ----------------------------------------------------------- #
67
+ # path
68
+ # ----------------------------------------------------------- #
69
+ def path()
70
+ return '/entry/json/'
71
+ end
72
+
73
+ # ----------------------------------------------------------- #
74
+ # query
75
+ # ----------------------------------------------------------- #
76
+ def query(uri, options)
77
+ return '?url=' + CGI.escape(uri)
78
+ end
79
+
80
+ # ----------------------------------------------------------- #
81
+ # parse
82
+ # ----------------------------------------------------------- #
83
+ def parse(body)
84
+ json = JSON.parse(body)
85
+
86
+ # ���[�U���̉��
87
+ users = Hash.new
88
+ json['bookmarks'].each { |item|
89
+ tags = Array.new
90
+ item['tags'].each { |tag|
91
+ tags.push(tag)
92
+ }
93
+ date = Time.local(*item['timestamp'].split(/\W/))
94
+ entry = User.new(tags, date, item['comment'])
95
+ users[item['user']] = entry
96
+ }
97
+
98
+ # �֘A�L���̉��
99
+ related = Array.new()
100
+ json['related'].each { |item|
101
+ entry = Related.new(item['eid'].to_i, item['url'], item['title'], item['count'].to_i)
102
+ related.push(entry)
91
103
  }
92
- date = Time.local(*item['timestamp'].split(/\W/))
93
- entry = User.new(tags, date, item['comment'])
94
- users[item['user']] = entry
95
- }
96
-
97
- # �֘A�L���̉��
98
- related = Array.new()
99
- json['related'].each { |item|
100
- entry = Related.new(item['eid'].to_i, item['url'], item['title'], item['count'].to_i)
101
- related.push(entry)
102
- }
103
-
104
- return Response.new(json['eid'].to_i, json['url'], json['screenshot'], json['title'], json['count'].to_i, users, related)
105
- end
106
- end # BookmarkEntry
104
+
105
+ return Response.new(json['eid'].to_i, json['url'], json['screenshot'], json['title'], json['count'].to_i, users, related)
106
+ end
107
+ end # Entry
108
+ end # Bookmark
107
109
  end # Hatena
108
110
  end # Crown