crown 0.0.11 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,96 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # twitter/user/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
+ module Twitter
36
+ # --------------------------------------------------------------- #
37
+ #
38
+ # UserEntry
39
+ #
40
+ # ���郆�[�U�Ɋւ�������擾����N���X�D
41
+ #
42
+ # --------------------------------------------------------------- #
43
+ class UserEntry
44
+ require 'cgi'
45
+ require 'crown/cgm/summarizable'
46
+ require 'rubygems'
47
+ require 'json'
48
+
49
+ # ------------------------------------------------------------------- #
50
+ # structures
51
+ # ------------------------------------------------------------------- #
52
+ Response = Struct.new(:status, :favorite, :friend, :follower, :list)
53
+
54
+ # ------------------------------------------------------------------- #
55
+ # Mix-in
56
+ # ------------------------------------------------------------------- #
57
+ include Crown::CGM::Summarizable
58
+
59
+ private
60
+ # --------------------------------------------------------------- #
61
+ # address
62
+ # --------------------------------------------------------------- #
63
+ def address()
64
+ return 'api.twitter.com'
65
+ end
66
+
67
+ # --------------------------------------------------------------- #
68
+ # path
69
+ # --------------------------------------------------------------- #
70
+ def path()
71
+ return '/1/users/show.json'
72
+ end
73
+
74
+ # --------------------------------------------------------------- #
75
+ # query
76
+ # --------------------------------------------------------------- #
77
+ def query(screen_name, options)
78
+ return '?screen_name=' + CGI.escape(screen_name)
79
+ end
80
+
81
+ # --------------------------------------------------------------- #
82
+ # parse
83
+ # --------------------------------------------------------------- #
84
+ def parse(body)
85
+ json = JSON.parse(body)
86
+ result = Response.new
87
+ result.status = json["statuses_count"].to_i
88
+ result.favorite = json["favourites_count"].to_i
89
+ result.friend = json["friends_count"].to_i
90
+ result.follower = json["followers_count"].to_i
91
+ result.list = json["listed_count"].to_i
92
+ return result
93
+ end
94
+ end # UserEntry
95
+ end # Twitter
96
+ end # Crown
data/lib/crown/yahoo.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # --------------------------------------------------------------------------- #
3
3
  #
4
- # livedoor.rb
4
+ # yahoo.rb
5
5
  #
6
- # Copyright (c) 2008 - 2011, clown.
6
+ # Copyright (c) 2008 - 2012, clown.
7
7
  #
8
8
  # Redistribution and use in source and binary forms, with or without
9
9
  # modification, are permitted provided that the following conditions
@@ -31,4 +31,8 @@
31
31
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
32
  #
33
33
  # --------------------------------------------------------------------------- #
34
- require 'crown/yahoo/bookmark'
34
+ module Crown
35
+ module Yahoo
36
+ require 'crown/yahoo/bookmark'
37
+ end # Yahoo
38
+ end # Crown
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # --------------------------------------------------------------------------- #
3
3
  #
4
- # hatena/bookmark.rb
4
+ # yahoo/bookmark.rb
5
5
  #
6
- # Copyright (c) 2008 - 2011, clown.
6
+ # Copyright (c) 2008 - 2012, clown.
7
7
  #
8
8
  # Redistribution and use in source and binary forms, with or without
9
9
  # modification, are permitted provided that the following conditions
@@ -33,42 +33,37 @@
33
33
  # --------------------------------------------------------------------------- #
34
34
  module Crown
35
35
  module Yahoo
36
- module Bookmark
37
- require 'cgi'
38
- require 'net/http'
39
- require 'crown/http'
40
- require 'rexml/document'
41
- Net::HTTP.version_1_2
36
+ # ------------------------------------------------------------------- #
37
+ #
38
+ # BookmarkCounter
39
+ #
40
+ # Yahoo! Japan ブックマーク API 経由の各種情報を取得するクラス.
41
+ #
42
+ # ------------------------------------------------------------------- #
43
+ class Bookmark
44
+ require 'crown/yahoo/bookmark/counter'
42
45
 
43
46
  # --------------------------------------------------------------- #
44
47
  #
45
- # get
48
+ # Bookmark.count
46
49
  #
47
- # uri に指定したページのブックマーク情報を取得する.session
48
- # には Net::HTTP クラス,またはその派生クラスのインスタンス
49
- # を指定する.
50
+ # 指定した URL のブックマーク数を取得する
50
51
  #
51
52
  # --------------------------------------------------------------- #
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)
54
- path = '/yjnostb.php?urls=' + CGI.escape(uri)
55
-
56
- begin
57
- result = Crown::HTTP.get(session, path)
58
- return 0 if (result == nil || result.code.to_i != 200)
59
- doc = REXML::Document.new(result.body)
60
- return REXML::XPath.first(doc, '//SAVE_COUNT/@ct').value.to_i
61
- rescue Exception
62
- return 0
63
- end
64
-
65
- return 0
53
+ def Bookmark.count(uri, options = nil)
54
+ return Crown::Yahoo::BookmarkCounter.new.count(uri, options)
66
55
  end
67
56
 
68
57
  # --------------------------------------------------------------- #
69
- # module functions
58
+ #
59
+ # count
60
+ #
61
+ # 指定した URL のブックマーク数を取得する
62
+ #
70
63
  # --------------------------------------------------------------- #
71
- module_function :count
64
+ def count(uri, options = nil)
65
+ return Crown::Yahoo::BookmarkCounter.new.count(uri, options)
66
+ end
72
67
  end # Bookmark
73
68
  end # Yahoo
74
69
  end # Crown
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # yahoo/bookmark/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 Yahoo
36
+ # --------------------------------------------------------------- #
37
+ #
38
+ # BookmarkCounter
39
+ #
40
+ # 指定した URL のブックマーク数を取得するクラス.
41
+ #
42
+ # --------------------------------------------------------------- #
43
+ class BookmarkCounter
44
+ require 'cgi'
45
+ require 'rexml/document'
46
+ require 'crown/cgm/countable'
47
+
48
+ # --------------------------------------------------------------- #
49
+ # Mix-in modules
50
+ # --------------------------------------------------------------- #
51
+ include Crown::CGM::Countable
52
+
53
+ private
54
+ # --------------------------------------------------------------- #
55
+ # address
56
+ # --------------------------------------------------------------- #
57
+ def address()
58
+ return 'num.bookmarks.yahoo.co.jp'
59
+ end
60
+
61
+ # --------------------------------------------------------------- #
62
+ # path
63
+ # --------------------------------------------------------------- #
64
+ def path()
65
+ return '/yjnostb.php'
66
+ end
67
+
68
+ # --------------------------------------------------------------- #
69
+ # query
70
+ # --------------------------------------------------------------- #
71
+ def query(uri, options)
72
+ return '?urls=' + CGI.escape(uri)
73
+ end
74
+
75
+ # --------------------------------------------------------------- #
76
+ # parse
77
+ # --------------------------------------------------------------- #
78
+ def parse(body)
79
+ doc = REXML::Document.new(body)
80
+ return REXML::XPath.first(doc, '//SAVE_COUNT/@ct').value.to_i
81
+ end
82
+ end # BookmarkCounter
83
+ end # Yahoo
84
+ end # Crown
@@ -2,7 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
  # --------------------------------------------------------------------------- #
4
4
  #
5
- # crown_test.rb
5
+ # crown-test.rb
6
6
  #
7
7
  # Copyright (c) 2008 - 2011, clown.
8
8
  #
@@ -32,7 +32,7 @@
32
32
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
33
  #
34
34
  # --------------------------------------------------------------------------- #
35
- require File.dirname(__FILE__) + '/test_helper.rb'
35
+ require File.dirname(__FILE__) + '/test-helper.rb'
36
36
  require 'test/unit'
37
37
 
38
38
  # --------------------------------------------------------------------------- #
@@ -52,7 +52,7 @@ class CrownTest < Test::Unit::TestCase
52
52
  def test_hatena_count
53
53
  # normal test
54
54
  @@valid_uris.each { |uri|
55
- assert(Crown::Hatena::Bookmark.count(uri) > 0, "failed in " + uri)
55
+ assert(Crown::Hatena::Bookmark.count(uri) >= 0, "failed in " + uri)
56
56
  }
57
57
  end
58
58
 
@@ -62,7 +62,7 @@ class CrownTest < Test::Unit::TestCase
62
62
  def test_delicious_count
63
63
  # normal test
64
64
  @@valid_uris.each { |uri|
65
- assert(Crown::Delicious.count(uri) > 0, "failed in " + uri)
65
+ assert(Crown::Delicious.count(uri) != nil, "failed in " + uri)
66
66
  }
67
67
  end
68
68
 
@@ -72,7 +72,7 @@ class CrownTest < Test::Unit::TestCase
72
72
  def test_livedoor_count
73
73
  # normal test
74
74
  @@valid_uris.each { |uri|
75
- assert(Crown::Delicious.count(uri) > 0, "failed in " + uri)
75
+ assert(Crown::Livedoor::Clip.count(uri) != nil, "failed in " + uri)
76
76
  }
77
77
  end
78
78
 
@@ -82,7 +82,7 @@ class CrownTest < Test::Unit::TestCase
82
82
  def test_buzzurl_count
83
83
  # normal test
84
84
  @@valid_uris.each { |uri|
85
- assert(Crown::Buzzurl.count(uri) > 0, "failed in " + uri)
85
+ assert(Crown::Buzzurl.count(uri) != nil, "failed in " + uri)
86
86
  }
87
87
  end
88
88
 
@@ -92,7 +92,7 @@ class CrownTest < Test::Unit::TestCase
92
92
  def test_yahoo_count
93
93
  # normal test
94
94
  @@valid_uris.each { |uri|
95
- assert(Crown::Yahoo::Bookmark.count(uri) > 0, "failed in " + uri)
95
+ assert(Crown::Yahoo::Bookmark.count(uri) != nil, "failed in " + uri)
96
96
  }
97
97
  end
98
98
 
@@ -102,12 +102,12 @@ class CrownTest < Test::Unit::TestCase
102
102
  def test_facebook_count
103
103
  # normal test
104
104
  @@valid_uris.each { |uri|
105
- counter = Crown::Facebook.count(uri)
106
- assert(counter != nil, "failed in Crown::Facebook.count: " + uri)
107
- assert(counter.like > 0, "wrong like count: " + uri)
108
- assert(counter.total > 0, "wrong total count: " + uri)
109
- assert(counter.share > 0, "wrong share count: " + uri)
110
- assert(counter.click > 0, "wrong click count: " + uri)
105
+ summary = Crown::Facebook.summary(uri)
106
+ assert(summary != nil, "failed in Crown::Facebook.count: " + uri)
107
+ assert(summary.like > 0, "wrong like count: " + uri)
108
+ assert(summary.total > 0, "wrong total count: " + uri)
109
+ assert(summary.share > 0, "wrong share count: " + uri)
110
+ assert(summary.click > 0, "wrong click count: " + uri)
111
111
  }
112
112
  end
113
113
 
@@ -117,7 +117,7 @@ class CrownTest < Test::Unit::TestCase
117
117
  def test_topsy_count
118
118
  # normal test
119
119
  @@valid_uris.each { |uri|
120
- assert(Crown::Topsy.count(uri) > 0, "failed in " + uri)
120
+ assert(Crown::Topsy.count(uri) != nil, "failed in " + uri)
121
121
  }
122
122
  end
123
123
 
@@ -127,7 +127,7 @@ class CrownTest < Test::Unit::TestCase
127
127
  def test_tweetmeme_count
128
128
  # normal test
129
129
  @@valid_uris.each { |uri|
130
- assert(Crown::TweetMeme.count(uri) > 0, "failed in " + uri)
130
+ assert(Crown::TweetMeme.count(uri) != nil, "failed in " + uri)
131
131
  }
132
132
  end
133
133
 
@@ -140,11 +140,36 @@ class CrownTest < Test::Unit::TestCase
140
140
  #
141
141
  # ----------------------------------------------------------------------- #
142
142
  #def test_backtype_count
143
+ # Crown::BackType.api_key = "your_api_key"
143
144
  # @@valid_uris.each { |uri|
144
- # assert(Crown::BackType.count(uri, "your_api_key") > 0, "failed in " + uri)
145
+ # assert(Crown::BackType.count(uri) != nil, "failed in " + uri)
145
146
  # }
146
147
  #end
147
148
 
149
+ # ----------------------------------------------------------------------- #
150
+ # test_cgm
151
+ # ----------------------------------------------------------------------- #
152
+ def test_cgm
153
+ services = [
154
+ :twitter_uri, # Twitter
155
+ :topsy, # Topsy
156
+ :tweetmeme, # TweetMeme
157
+ # :backtype, # BackTweets (要 API key)
158
+ :facebook, # Facebook
159
+ :hatena_bookmark, # はてなブックマーク
160
+ :livedoor_clip, # Livedoor クリップ
161
+ :delicious, # Delicious
162
+ :buzzurl, # Buzzurl
163
+ :yahoo_bookmark, # Yahoo! ブックマーク
164
+ ]
165
+
166
+ @@valid_uris.each { |uri|
167
+ services.each { |service|
168
+ assert(Crown::CGM.proxy(service).count(uri) >= 0, "failed in " + uri)
169
+ }
170
+ }
171
+ end
172
+
148
173
  # ----------------------------------------------------------------------- #
149
174
  # test_twitter_count
150
175
  # ----------------------------------------------------------------------- #
@@ -152,12 +177,12 @@ class CrownTest < Test::Unit::TestCase
152
177
  # normal test
153
178
  @@valid_users.each { |screen_name|
154
179
  counter = Crown::Twitter.count(screen_name)
155
- assert(counter != nil, "failed in Crown::Twitter.count: " + screen_name)
156
- assert(counter.status > 0, "wrong statuses count: " + screen_name)
180
+ assert(counter != nil, "failed in Crown::Twitter.count: " + screen_name)
181
+ assert(counter.status > 0, "wrong statuses count: " + screen_name)
157
182
  assert(counter.favorite > 0, "wrong favorites count: " + screen_name)
158
- assert(counter.friend > 0, "wrong friends count: " + screen_name)
183
+ assert(counter.friend > 0, "wrong friends count: " + screen_name)
159
184
  assert(counter.follower > 0, "wrong followers count: " + screen_name)
160
- assert(counter.list > 0, "wrong listed count: " + screen_name)
185
+ assert(counter.list > 0, "wrong listed count: " + screen_name)
161
186
  }
162
187
  end
163
188
 
@@ -167,7 +192,7 @@ class CrownTest < Test::Unit::TestCase
167
192
  def test_ldr_count
168
193
  # normal test
169
194
  @@valid_feeds.each { |feed_uri|
170
- assert(Crown::Livedoor::Reader.count(feed_uri) > 0, "failed in " + feed_uri)
195
+ assert(Crown::Livedoor::Reader.count(feed_uri) != nil, "failed in " + feed_uri)
171
196
  }
172
197
  end
173
198
  end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # --------------------------------------------------------------------------- #
3
3
  #
4
- # test_helper.rb
4
+ # test-helper.rb
5
5
  #
6
6
  # Copyright (c) 2008 - 2011, clown.
7
7
  #