crown 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
@@ -0,0 +1,4 @@
1
+ == 0.0.1 / 2011-02-18
2
+
3
+ * initial release
4
+
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2008 - 2011, clown
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name of the <ORGANIZATION> nor the names of its contributors
13
+ may be used to endorse or promote products derived from this software
14
+ without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,22 @@
1
+ = crown
2
+
3
+ crown は Ruby で書かれた雑多なライブラリです.各種 Web サービスの API 実装を
4
+ メインに作者の気分で追加されていきます:-D
5
+
6
+ ライセンスは修正 BSD ライセンスです.
7
+
8
+ == Install
9
+
10
+ gem install crown
11
+
12
+ == Note on Patches/Pull Requests
13
+
14
+ * Fork the project.
15
+ * Make your feature addition or bug fix.
16
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
17
+ * Commit, do not mess with rakefile, version, or history.(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
18
+ * Send me a pull request. Bonus points for topic branches.
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2008 - 2011 clown. See LICENSE for details.
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "crown"
8
+ gem.summary = %Q{uncategorized ruby libraries.}
9
+ gem.description = %Q{crown is uncategorized ruby libraries, which is added according to author's mood :-D}
10
+ gem.email = "tt.clown@gmail.com"
11
+ gem.homepage = "http://github.com/clown/crown"
12
+ gem.authors = ["clown"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "crown #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{crown}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["clown"]
12
+ s.date = %q{2011-02-18}
13
+ s.description = %q{crown is uncategorized ruby libraries, which is added according to author's mood :-D}
14
+ s.email = %q{tt.clown@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "ChangeLog",
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "ChangeLog",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "crown.gemspec",
29
+ "lib/crown.gemspec",
30
+ "lib/crown.rb",
31
+ "lib/crown/buzzurl.rb",
32
+ "lib/crown/delicious.rb",
33
+ "lib/crown/hatena.rb",
34
+ "lib/crown/hatena/bookmark.rb",
35
+ "lib/crown/http.rb",
36
+ "lib/crown/livedoor.rb",
37
+ "lib/crown/livedoor/clip.rb",
38
+ "lib/crown/twitter.rb",
39
+ "lib/crown/yahoo.rb",
40
+ "lib/crown/yahoo/bookmark.rb",
41
+ "test/crown_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/clown/crown}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.5.2}
48
+ s.summary = %q{uncategorized ruby libraries.}
49
+ s.test_files = [
50
+ "test/crown_test.rb",
51
+ "test/test_helper.rb"
52
+ ]
53
+
54
+ if s.respond_to? :specification_version then
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
+ end
65
+ end
File without changes
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # buzzurl.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
+ $:.unshift(File.dirname(__FILE__))
35
+
36
+ require 'crown/http'
37
+ require 'crown/delicious'
38
+ require 'crown/hatena'
39
+ require 'crown/livedoor'
40
+ require 'crown/buzzurl'
41
+ require 'crown/yahoo'
42
+ require 'crown/twitter'
43
+
44
+ module Crown
45
+ VERSION = '0.0.1'
46
+ end
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # buzzurl.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 Buzzurl
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
+ #
45
+ # count
46
+ #
47
+ # uri に指定したページのブックマーク数を取得する.session
48
+ # には Net::HTTP クラス,またはその派生クラスのインスタンス
49
+ # を指定する.
50
+ #
51
+ # ------------------------------------------------------------------- #
52
+ def count(uri, session = Net::HTTP.new('api.buzzurl.jp', 80))
53
+ path = '/api/counter/v1/json?url=' + CGI.escape(uri)
54
+
55
+ begin
56
+ result = Crown::HTTP.get(session, path)
57
+ return 0 if (result == nil || result.code.to_i != 200)
58
+ json = JSON.parse(result.body)
59
+ json.each { |elem|
60
+ return elem['users'].to_i
61
+ }
62
+ rescue Exception
63
+ return 0
64
+ end
65
+
66
+ return 0
67
+ end
68
+
69
+ # ------------------------------------------------------------------- #
70
+ # module functions
71
+ # ------------------------------------------------------------------- #
72
+ module_function :count
73
+ end # Buzzurl
74
+ end # Crown
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # delicious.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 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
42
+
43
+ # ------------------------------------------------------------------- #
44
+ #
45
+ # count
46
+ #
47
+ # uri に指定したページのブックマーク数を取得する.session
48
+ # には Net::HTTP クラス,またはその派生クラスのインスタンス
49
+ # を指定する.
50
+ #
51
+ # ------------------------------------------------------------------- #
52
+ def count(uri, session = Net::HTTP.new('feeds.delicious.com', 80))
53
+ path = '/v2/json/urlinfo/blogbadge?hash=' + Digest::MD5.hexdigest(uri)
54
+
55
+ begin
56
+ result = Crown::HTTP.get(session, path)
57
+ return 0 if (result == nil || result.code.to_i != 200)
58
+ json = JSON.parse(result.body)
59
+ json.each { |elem|
60
+ return elem['total_posts'].to_i
61
+ }
62
+ rescue Exception
63
+ return 0
64
+ end
65
+
66
+ return 0
67
+ end
68
+
69
+ # ------------------------------------------------------------------- #
70
+ # module functions
71
+ # ------------------------------------------------------------------- #
72
+ module_function :count
73
+ end # Delicious
74
+ end # Crown
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # hatena.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
+ require 'crown/hatena/bookmark'
@@ -0,0 +1,238 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # hatena/bookmark.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 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
44
+
45
+ # --------------------------------------------------------------- #
46
+ #
47
+ # LinkTrace
48
+ #
49
+ # 指定した Web サイトのはてなブックマーク一覧から順に URL を
50
+ # 取得するクラス.2 ページ目以降の結果は,html のヘッダ情報の
51
+ # next 属性からページの URL を推測して取得する.
52
+ #
53
+ # --------------------------------------------------------------- #
54
+ class LinkTrace
55
+ @@reserved = [ "/hotentry", "/entrylist", "/news", "/video", "/asin" ]
56
+
57
+ # ----------------------------------------------------------- #
58
+ # initialize
59
+ # ----------------------------------------------------------- #
60
+ def initialize(path, session = Net::HTTP.new("b.hatena.ne.jp", 80))
61
+ @basename = String.new
62
+ @basename.concat("/") if (path[0] != 47)
63
+ @basename.concat(path)
64
+ @basename.concat("/") if (@basename.match(/^\/[\w\-]+$/) != nil && !@@reserved.include?(@basename))
65
+ @path = String.new(@basename)
66
+ @session = session
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
140
+ end
141
+
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
+ # --------------------------------------------------------------- #
150
+ #
151
+ # count
152
+ #
153
+ # uri に指定したページのブックマーク数を取得する.session
154
+ # には Net::HTTP クラス,またはその派生クラスのインスタンス
155
+ # を指定する.
156
+ #
157
+ # --------------------------------------------------------------- #
158
+ def count(uri, session = Net::HTTP.new('api.b.st-hatena.com', 80))
159
+ path = "/entry.count?url=" + CGI.escape(uri)
160
+ begin
161
+ result = Crown::HTTP.get(session, path)
162
+ return 0 if (result == nil || result.code.to_i != 200)
163
+ return result.body.to_i
164
+ rescue Exception => e
165
+ return 0
166
+ end
167
+ end
168
+
169
+ # --------------------------------------------------------------- #
170
+ #
171
+ # get
172
+ #
173
+ # uri に指定したページのブックマーク情報を取得する.session
174
+ # には Net::HTTP クラス,またはその派生クラスのインスタンス
175
+ # を指定する.
176
+ #
177
+ # --------------------------------------------------------------- #
178
+ def get(uri, session = Net::HTTP.new('b.hatena.ne.jp', 80))
179
+ path = '/entry/json/?url=' + CGI.escape(uri)
180
+
181
+ begin
182
+ result = Crown::HTTP.get(session, path)
183
+ return nil if (result == nil || result.code.to_i != 200)
184
+ json = JSON.parse(result.body)
185
+
186
+ users = Hash.new
187
+ json['bookmarks'].each { |item|
188
+ tags = Array.new
189
+ item['tags'].each { |tag|
190
+ tags.push(tag)
191
+ }
192
+ date = Time.local(*item['timestamp'].split(/\W/))
193
+ entry = User.new(tags, date, item['comment'])
194
+ users[item['user']] = entry
195
+ }
196
+
197
+ related = Array.new()
198
+ json['related'].each { |item|
199
+ entry = Related.new(item['eid'].to_i, item['url'], item['title'], item['count'].to_i)
200
+ related.push(entry)
201
+ }
202
+ rescue Exception
203
+ return nil
204
+ end
205
+
206
+ return Response.new(json['eid'].to_i, json['url'], json['screenshot'], json['title'], json['count'].to_i, users, related)
207
+ end
208
+
209
+ # --------------------------------------------------------------- #
210
+ #
211
+ # each
212
+ #
213
+ # LinkTrace クラスを使用してブックマークされている記事の URL
214
+ # 一覧を取得し,それらのブックマーク情報を順に返す.session
215
+ # には Net::HTTP クラス,またはその派生クラスのインスタンス
216
+ # を指定する.
217
+ #
218
+ # --------------------------------------------------------------- #
219
+ def each(query, session = Net::HTTP.new('b.hatena.ne.jp', 80))
220
+ tracer = LinkTrace.new(query, session)
221
+ while (tracer.more?)
222
+ uris = tracer.get
223
+ uris.each { |uri|
224
+ result = Bookmark.get(uri, session)
225
+ yield(result) if (result != nil)
226
+ }
227
+ end
228
+ end
229
+
230
+ # --------------------------------------------------------------- #
231
+ # module functions
232
+ # --------------------------------------------------------------- #
233
+ module_function :count
234
+ module_function :get
235
+ module_function :each
236
+ end # Bookmark
237
+ end # Hatena
238
+ end # Crown
@@ -0,0 +1,76 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # http.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 HTTP
36
+ require 'net/http'
37
+ Net::HTTP.version_1_2
38
+
39
+ # ------------------------------------------------------------------- #
40
+ #
41
+ # get
42
+ #
43
+ # �T�[�o�̏󋵂ɂ���Ď��s���鎖������̂ŁC�ő�� limit �� get()
44
+ # �������Dsession �ɂ� Net::HTTP �N���X�C�܂��͂��̔h���N���X��
45
+ # �C���X�^���X���w�肷��D
46
+ #
47
+ # ------------------------------------------------------------------- #
48
+ def get(session, path, limit = 3)
49
+ n = 0
50
+ begin
51
+ session.start if (!session.active?)
52
+ response = session.get(path)
53
+ while (response.code.to_i == 301)
54
+ session.finish if (session.active?)
55
+ uri = URI.parse(response['Location'])
56
+ session = Net::HTTP.new(uri.host, uri.port, session.proxy_address, session.proxy_port)
57
+ path = String.new(uri.path)
58
+ if (uri.query != nil)
59
+ path.concat("?")
60
+ path.concat(uri.query)
61
+ end
62
+ response = session.get(path)
63
+ end
64
+ return response
65
+ rescue Exception
66
+ session.finish if (session.active?)
67
+ if (n < limit)
68
+ n += 1
69
+ retry
70
+ end
71
+ return nil
72
+ end
73
+ end
74
+ module_function :get
75
+ end # HTTP
76
+ end # Crown
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # livedoor.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
+ require 'crown/livedoor/clip'
@@ -0,0 +1,64 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # livedoor/clip.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 Livedoor
36
+ module Clip
37
+ require 'cgi'
38
+ require 'xmlrpc/client'
39
+
40
+ # --------------------------------------------------------------- #
41
+ #
42
+ # count
43
+ #
44
+ # uri に指定したページのクリップ数を取得する.
45
+ #
46
+ # --------------------------------------------------------------- #
47
+ def count(uri)
48
+ begin
49
+ session = XMLRPC::Client.new2('http://rpc.clip.livedoor.com/count', nil, 10).proxy('clip')
50
+ session.getCount(uri).each { |key, value|
51
+ return value.to_i
52
+ }
53
+ rescue Exception
54
+ return 0
55
+ end
56
+ end
57
+
58
+ # --------------------------------------------------------------- #
59
+ # module functions
60
+ # --------------------------------------------------------------- #
61
+ module_function :count
62
+ end # Clip
63
+ end # Livedoor
64
+ end # Crown
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # twitter.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
+ require 'net/http'
36
+ require 'crown/http'
37
+ require 'rubygems'
38
+ require 'json'
39
+ Net::HTTP.version_1_2
40
+
41
+ module Twitter
42
+ # ------------------------------------------------------------------- #
43
+ # structures
44
+ # ------------------------------------------------------------------- #
45
+ Counter = Struct.new(:status, :favorite, :friend, :follower, :list)
46
+
47
+ # ------------------------------------------------------------------- #
48
+ # count
49
+ # ------------------------------------------------------------------- #
50
+ def count(screen_name)
51
+ begin
52
+ session = Net::HTTP.new("api.twitter.com", 80)
53
+ path = "/1/users/show.json?screen_name=" + screen_name
54
+ response = Crown::HTTP.get(session, path)
55
+ return nil if (response == nil || response.code.to_i != 200)
56
+
57
+ json = JSON.parse(response.body)
58
+ result = Counter.new
59
+ result.status = json["statuses_count"].to_i
60
+ result.favorite = json["favourites_count"].to_i
61
+ result.friend = json["friends_count"].to_i
62
+ result.follower = json["followers_count"].to_i
63
+ result.list = json["listed_count"].to_i
64
+ return result
65
+ rescue Exception
66
+ return nil
67
+ end
68
+
69
+ return nil
70
+ end
71
+
72
+ module_function :count
73
+ end # Twitter
74
+ end # Crown
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # livedoor.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
+ require 'crown/yahoo/bookmark'
@@ -0,0 +1,73 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # hatena/bookmark.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 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
42
+
43
+ # --------------------------------------------------------------- #
44
+ #
45
+ # get
46
+ #
47
+ # uri に指定したページのブックマーク情報を取得する.session
48
+ # には Net::HTTP クラス,またはその派生クラスのインスタンス
49
+ # を指定する.
50
+ #
51
+ # --------------------------------------------------------------- #
52
+ def count(uri, session = Net::HTTP.new('num.bookmarks.yahoo.co.jp', 80))
53
+ path = '/yjnostb.php?urls=' + CGI.escape(uri)
54
+
55
+ begin
56
+ result = Crown::HTTP.get(session, path)
57
+ return 0 if (result == nil || result.code.to_i != 200)
58
+ doc = REXML::Document.new(result.body)
59
+ return REXML::XPath.first(doc, '//SAVE_COUNT/@ct').value.to_i
60
+ rescue Exception
61
+ return 0
62
+ end
63
+
64
+ return 0
65
+ end
66
+
67
+ # --------------------------------------------------------------- #
68
+ # module functions
69
+ # --------------------------------------------------------------- #
70
+ module_function :count
71
+ end # Bookmark
72
+ end # Yahoo
73
+ end # Crown
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/ruby -Ku
2
+ # -*- coding: utf-8 -*-
3
+ # --------------------------------------------------------------------------- #
4
+ #
5
+ # crown_test.rb
6
+ #
7
+ # Copyright (c) 2008 - 2011, clown.
8
+ #
9
+ # Redistribution and use in source and binary forms, with or without
10
+ # modification, are permitted provided that the following conditions
11
+ # are met:
12
+ #
13
+ # - Redistributions of source code must retain the above copyright
14
+ # notice, this list of conditions and the following disclaimer.
15
+ # - Redistributions in binary form must reproduce the above copyright
16
+ # notice, this list of conditions and the following disclaimer in the
17
+ # documentation and/or other materials provided with the distribution.
18
+ # - No names of its contributors may be used to endorse or promote
19
+ # products derived from this software without specific prior written
20
+ # permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ #
34
+ # --------------------------------------------------------------------------- #
35
+ require File.dirname(__FILE__) + '/test_helper.rb'
36
+ require 'test/unit'
37
+
38
+ # --------------------------------------------------------------------------- #
39
+ # CrownTest
40
+ # --------------------------------------------------------------------------- #
41
+ class CrownTest < Test::Unit::TestCase
42
+ # ----------------------------------------------------------------------- #
43
+ # variables
44
+ # ----------------------------------------------------------------------- #
45
+ @@valid_uris = [
46
+ "http://www.google.co.jp/",
47
+ ]
48
+
49
+ @@valid_users = [
50
+ "tt_clown",
51
+ ]
52
+
53
+ # ----------------------------------------------------------------------- #
54
+ # test_hatena_count
55
+ # ----------------------------------------------------------------------- #
56
+ def test_hatena_count
57
+ @@valid_uris.each { |uri|
58
+ assert(Crown::Hatena::Bookmark.count(uri) > 0, "failed in " + uri)
59
+ }
60
+ end
61
+
62
+ # ----------------------------------------------------------------------- #
63
+ # test_delicious_count
64
+ # ----------------------------------------------------------------------- #
65
+ def test_delicious_count
66
+ @@valid_uris.each { |uri|
67
+ assert(Crown::Delicious.count(uri) > 0, "failed in " + uri)
68
+ }
69
+ end
70
+
71
+ # ----------------------------------------------------------------------- #
72
+ # test_livedoor_count
73
+ # ----------------------------------------------------------------------- #
74
+ def test_livedoor_count
75
+ @@valid_uris.each { |uri|
76
+ assert(Crown::Delicious.count(uri) > 0, "failed in " + uri)
77
+ }
78
+ end
79
+
80
+ # ----------------------------------------------------------------------- #
81
+ # test_buzzurl_count
82
+ # ----------------------------------------------------------------------- #
83
+ def test_buzzurl_count
84
+ @@valid_uris.each { |uri|
85
+ assert(Crown::Buzzurl.count(uri) > 0, "failed in " + uri)
86
+ }
87
+ end
88
+
89
+ # ----------------------------------------------------------------------- #
90
+ # test_yahoo_count
91
+ # ----------------------------------------------------------------------- #
92
+ def test_yahoo_count
93
+ @@valid_uris.each { |uri|
94
+ assert(Crown::Yahoo::Bookmark.count(uri) > 0, "failed in " + uri)
95
+ }
96
+ end
97
+
98
+ # ----------------------------------------------------------------------- #
99
+ # test_twitter_count
100
+ # ----------------------------------------------------------------------- #
101
+ def test_twitter_count
102
+ @@valid_users.each { |screen_name|
103
+ counter = Crown::Twitter.count(screen_name)
104
+ assert(counter != nil, "failed in Crown::Twitter.count: " + screen_name)
105
+ assert(counter.status > 0, "wrong statuses count: " + screen_name)
106
+ assert(counter.favorite > 0, "wrong favorites count: " + screen_name)
107
+ assert(counter.friend > 0, "wrong friends count: " + screen_name)
108
+ assert(counter.follower > 0, "wrong followers count: " + screen_name)
109
+ assert(counter.list > 0, "wrong listed count: " + screen_name)
110
+ }
111
+ end
112
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # test_helper.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
+ require 'test/unit'
35
+ require File.dirname(__FILE__) + '/../lib/crown'
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crown
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - clown
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-18 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: crown is uncategorized ruby libraries, which is added according to author's mood :-D
36
+ email: tt.clown@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - ChangeLog
43
+ - LICENSE
44
+ - README.rdoc
45
+ files:
46
+ - .document
47
+ - .gitignore
48
+ - ChangeLog
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - crown.gemspec
54
+ - lib/crown.gemspec
55
+ - lib/crown.rb
56
+ - lib/crown/buzzurl.rb
57
+ - lib/crown/delicious.rb
58
+ - lib/crown/hatena.rb
59
+ - lib/crown/hatena/bookmark.rb
60
+ - lib/crown/http.rb
61
+ - lib/crown/livedoor.rb
62
+ - lib/crown/livedoor/clip.rb
63
+ - lib/crown/twitter.rb
64
+ - lib/crown/yahoo.rb
65
+ - lib/crown/yahoo/bookmark.rb
66
+ - test/crown_test.rb
67
+ - test/test_helper.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/clown/crown
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.5.2
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: uncategorized ruby libraries.
102
+ test_files:
103
+ - test/crown_test.rb
104
+ - test/test_helper.rb