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
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # livedoor/clip.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,33 +33,30 @@
33
33
  # --------------------------------------------------------------------------- #
34
34
  module Crown
35
35
  module Livedoor
36
- module Clip
37
- require 'cgi'
38
- require 'xmlrpc/client'
36
+ class Clip
37
+ require 'crown/livedoor/clip/counter'
39
38
 
40
39
  # --------------------------------------------------------------- #
41
40
  #
42
- # count
41
+ # Clip.count
43
42
  #
44
- # uri に指定したページのクリップ数を取得する.
43
+ # 指定した URL のクリップ数(ブックマーク数)を取得する.
45
44
  #
46
45
  # --------------------------------------------------------------- #
47
- def count(uri, proxy_host = nil, proxy_port = nil)
48
- begin
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')
51
- session.getCount(uri).each { |key, value|
52
- return value.to_i
53
- }
54
- rescue Exception
55
- return 0
56
- end
46
+ def Clip.count(uri, options = nil)
47
+ return Crown::Livedoor::ClipCounter.new.count(uri, options)
57
48
  end
58
49
 
59
50
  # --------------------------------------------------------------- #
60
- # module functions
51
+ #
52
+ # count
53
+ #
54
+ # 指定した URL のクリップ数(ブックマーク数)を取得する.
55
+ #
61
56
  # --------------------------------------------------------------- #
62
- module_function :count
57
+ def count(uri, options = nil)
58
+ return Crown::Livedoor::ClipCounter.new.count(uri, options)
59
+ end
63
60
  end # Clip
64
61
  end # Livedoor
65
62
  end # Crown
@@ -0,0 +1,96 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # livedoor/clip/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 Livedoor
36
+ # --------------------------------------------------------------- #
37
+ #
38
+ # BookmarkCounter
39
+ #
40
+ # �w�肵�� URL �̃N���b�v���i�u�b�N�}�[�N���j���擾����N���X�D
41
+ #
42
+ # --------------------------------------------------------------- #
43
+ class ClipCounter
44
+ require 'cgi'
45
+ require 'xmlrpc/client'
46
+
47
+ # --------------------------------------------------------------- #
48
+ # Mix-in modules
49
+ # --------------------------------------------------------------- #
50
+ include Crown::CGM::Countable
51
+
52
+ # --------------------------------------------------------------- #
53
+ #
54
+ # count
55
+ #
56
+ # �w�肵�� URL �̃N���b�v���i�u�b�N�}�[�N���j���擾����D
57
+ # NOTE: Livedoor �N���b�v�� �N���b�v���擾 API �� RPC �`��
58
+ # �ł��邽�߁Ccount ���\�b�h�𒼐ڍĒ�`����D
59
+ #
60
+ # --------------------------------------------------------------- #
61
+ def count(uri, options = nil)
62
+ begin
63
+ proxy_addr = nil
64
+ proxy_port = nil
65
+ if (options.class == Hash)
66
+ proxy_addr = options[:proxy_address] if (options.has_key?(:proxy_address))
67
+ proxy_port = options[:proxy_port] if (options.has_key?(:proxy_port))
68
+ end
69
+
70
+ proxy = proxy_addr + ':' + proxy_port.to_s if (proxy_addr && proxy_port)
71
+ session = XMLRPC::Client.new2('http://rpc.clip.livedoor.com/count', proxy, 10).proxy('clip')
72
+ session.getCount(uri).each { |key, value|
73
+ return value.to_i
74
+ }
75
+ rescue Exception
76
+ return error_value()
77
+ end
78
+
79
+ return error_value()
80
+ end
81
+
82
+ private
83
+ # --------------------------------------------------------------- #
84
+ #
85
+ # NOTE: Crown::CGM::Countable �ɒ�`����Ă���e�탁�\�b�h��
86
+ # �g�p���Ȃ��̂ŁC���������Ă����D
87
+ #
88
+ # --------------------------------------------------------------- #
89
+ def address(); return nil; end
90
+ def port(); return nil; end
91
+ def path(); return nil; end
92
+ def query(uri, options); return nil; end
93
+ def parse(body); return nil; end
94
+ end # ClipCounter
95
+ end # Livedoor
96
+ end # Crown
@@ -33,33 +33,30 @@
33
33
  # --------------------------------------------------------------------------- #
34
34
  module Crown
35
35
  module Livedoor
36
- module Reader
37
- require 'cgi'
38
- require 'net/http'
39
- require 'crown/http'
40
- Net::HTTP.version_1_2
36
+ class Reader
37
+ require 'crown/livedoor/reader/counter'
41
38
 
42
39
  # ------------------------------------------------------------------- #
43
40
  #
44
- # count
41
+ # Reader.count
45
42
  #
46
- # feed_uri に指定したフィード URL の Livedoor Reader での購読数
47
- # を取得する.
43
+ # 指定したフィード URL の購読者数を取得する.
48
44
  #
49
45
  # ------------------------------------------------------------------- #
50
- def count(feed_uri, proxy_host = nil, proxy_port = nil)
51
- begin
52
- session = Net::HTTP.new('rpc.reader.livedoor.com', 80, proxy_host, proxy_port)
53
- path = '/count?feedlink=' + CGI.escape(feed_uri)
54
- response = Crown::HTTP.get(session, path)
55
- return 0 if (response == nil || response.code.to_i != 200)
56
- return response.body.to_i
57
- rescue Exception
58
- return 0
59
- end
46
+ def Reader.count(feed_uri, options = nil)
47
+ return Crown::Livedoor::ReadCounter.new.count(feed_uri, options)
60
48
  end
61
49
 
62
- module_function :count
50
+ # ------------------------------------------------------------------- #
51
+ #
52
+ # count
53
+ #
54
+ # 指定したフィード URL の購読者数を取得する.
55
+ #
56
+ # ------------------------------------------------------------------- #
57
+ def count(feed_uri, options = nil)
58
+ return Crown::Livedoor::ReadCounter.new.count(feed_uri, options)
59
+ end
63
60
  end # Reader
64
61
  end # Livedoor
65
62
  end # Crown
@@ -0,0 +1,82 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # livedoor/reader/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 Livedoor
36
+ # --------------------------------------------------------------- #
37
+ #
38
+ # ReadCounter
39
+ #
40
+ # �w�肵���t�B�[�h URL �̍w�ǎҐ����擾����N���X�D
41
+ #
42
+ # --------------------------------------------------------------- #
43
+ class ReadCounter
44
+ require 'cgi'
45
+ require 'crown/cgm/countable'
46
+
47
+ # --------------------------------------------------------------- #
48
+ # Mix-in modules
49
+ # --------------------------------------------------------------- #
50
+ include Crown::CGM::Countable
51
+
52
+ private
53
+ # --------------------------------------------------------------- #
54
+ # address
55
+ # --------------------------------------------------------------- #
56
+ def address()
57
+ return 'rpc.reader.livedoor.com'
58
+ end
59
+
60
+ # --------------------------------------------------------------- #
61
+ # path
62
+ # --------------------------------------------------------------- #
63
+ def path()
64
+ return '/count'
65
+ end
66
+
67
+ # --------------------------------------------------------------- #
68
+ # query
69
+ # --------------------------------------------------------------- #
70
+ def query(feed_uri, options)
71
+ return '?feedlink=' + CGI.escape(feed_uri)
72
+ end
73
+
74
+ # --------------------------------------------------------------- #
75
+ # parse
76
+ # --------------------------------------------------------------- #
77
+ def parse(body)
78
+ return body.to_i
79
+ end
80
+ end # BookmarkCounter
81
+ end # Hatena
82
+ end # Crown
data/lib/crown/topsy.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # topsy.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
@@ -32,31 +32,30 @@
32
32
  #
33
33
  # --------------------------------------------------------------------------- #
34
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
35
+ class Topsy
36
+ require 'crown/topsy/counter'
42
37
 
43
38
  # ------------------------------------------------------------------- #
39
+ #
40
+ # Topsy.count
41
+ #
42
+ # Topsy の API を介して,指定した URL へのツイート数を取得する.
43
+ #
44
+ # ------------------------------------------------------------------- #
45
+ def Topsy.count(uri, options = nil)
46
+ return Crown::Topsy::URICounter.new.count(uri, options)
47
+ end
48
+
49
+ # ------------------------------------------------------------------- #
50
+ #
44
51
  # count
52
+ #
53
+ # Topsy の API を介して,指定した URL へのツイート数を取得する.
54
+ #
45
55
  # ------------------------------------------------------------------- #
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 0 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
56
+ def count(uri, options = nil)
57
+ return Crown::Topsy::URICounter.new.count(uri, options)
58
58
  end
59
59
 
60
- module_function :count
61
60
  end # Topsy
62
61
  end # Crown
@@ -0,0 +1,78 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # topsy/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 Topsy
36
+ class URICounter
37
+ require 'cgi'
38
+ require 'crown/cgm/countable'
39
+ require 'rubygems'
40
+ require 'json'
41
+
42
+ # ------------------------------------------------------------------- #
43
+ # Mix-in modules
44
+ # ------------------------------------------------------------------- #
45
+ include Crown::CGM::Countable
46
+
47
+ private
48
+ # --------------------------------------------------------------- #
49
+ # address
50
+ # --------------------------------------------------------------- #
51
+ def address()
52
+ return 'otter.topsy.com'
53
+ end
54
+
55
+ # --------------------------------------------------------------- #
56
+ # path
57
+ # --------------------------------------------------------------- #
58
+ def path()
59
+ return '/urlinfo.json'
60
+ end
61
+
62
+ # --------------------------------------------------------------- #
63
+ # query
64
+ # --------------------------------------------------------------- #
65
+ def query(uri, options)
66
+ return '?url=' + CGI.escape(uri)
67
+ end
68
+
69
+ # --------------------------------------------------------------- #
70
+ # parse
71
+ # --------------------------------------------------------------- #
72
+ def parse(body)
73
+ json = JSON.parse(body)
74
+ return json["response"]["trackback_total"].to_i
75
+ end
76
+ end # URICounter
77
+ end # Topsy
78
+ end # Crown
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # tweetmeme.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
@@ -32,31 +32,30 @@
32
32
  #
33
33
  # --------------------------------------------------------------------------- #
34
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
35
+ class TweetMeme
36
+ require 'crown/tweetmeme/counter'
42
37
 
43
38
  # ------------------------------------------------------------------- #
39
+ #
40
+ # TweetMeme.count
41
+ #
42
+ # TweetMeme の API を介して,指定した URL へのツイート数を取得する.
43
+ #
44
+ # ------------------------------------------------------------------- #
45
+ def TweetMeme.count(uri, options = nil)
46
+ return Crown::TweetMeme::URICounter.new.count(uri, options)
47
+ end
48
+
49
+ # ------------------------------------------------------------------- #
50
+ #
44
51
  # count
52
+ #
53
+ # TweetMeme の API を介して,指定した URL へのツイート数を取得する.
54
+ #
45
55
  # ------------------------------------------------------------------- #
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
56
+ def count(uri, options = nil)
57
+ return Crown::TweetMeme::URICounter.new.count(uri, options)
58
58
  end
59
59
 
60
- module_function :count
61
60
  end # TweetMeme
62
61
  end # Crown