crown 0.0.3 → 0.0.4

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.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.0.4 / 2011-02-19
2
+
3
+ * bug fix
4
+ * add Livedoor Reader module
5
+
1
6
  == 0.0.3 / 2011-02-19
2
7
 
3
8
  * add Facebook module
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/crown.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{crown}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["clown"]
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "lib/crown/http.rb",
37
37
  "lib/crown/livedoor.rb",
38
38
  "lib/crown/livedoor/clip.rb",
39
+ "lib/crown/livedoor/reader.rb",
39
40
  "lib/crown/topsy.rb",
40
41
  "lib/crown/tweetmeme.rb",
41
42
  "lib/crown/twitter.rb",
data/lib/crown.rb CHANGED
@@ -46,5 +46,5 @@ require 'crown/backtype'
46
46
  require 'crown/facebook'
47
47
 
48
48
  module Crown
49
- VERSION = '0.0.3'
49
+ VERSION = '0.0.4'
50
50
  end
data/lib/crown/buzzurl.rb CHANGED
@@ -44,18 +44,16 @@ module Crown
44
44
  #
45
45
  # count
46
46
  #
47
- # uri に指定したページのブックマーク数を取得する.session
48
- # には Net::HTTP クラス,またはその派生クラスのインスタンス
49
- # を指定する.
47
+ # uri に指定したページのブックマーク数を取得する.
50
48
  #
51
49
  # ------------------------------------------------------------------- #
52
50
  def count(uri, proxy_host = nil, proxy_port = nil)
53
- session = Net::HTTP.new('api.buzzurl.jp', 80, proxy_host, proxy_port)
54
- path = '/api/counter/v1/json?url=' + CGI.escape(uri)
55
-
56
51
  begin
52
+ session = Net::HTTP.new('api.buzzurl.jp', 80, proxy_host, proxy_port)
53
+ path = '/api/counter/v1/json?url=' + CGI.escape(uri)
57
54
  result = Crown::HTTP.get(session, path)
58
55
  return 0 if (result == nil || result.code.to_i != 200)
56
+
59
57
  json = JSON.parse(result.body)
60
58
  json.each { |elem|
61
59
  return elem['users'].to_i
data/lib/crown/http.rb CHANGED
@@ -40,9 +40,9 @@ module Crown
40
40
  #
41
41
  # get
42
42
  #
43
- # �T�[�o�̏󋵂ɂ���Ď��s���鎖������̂ŁC�ő�� limit �� get()
44
- # �������Dsession �ɂ� Net::HTTP �N���X�C�܂��͂��̔h���N���X��
45
- # �C���X�^���X���w�肷��D
43
+ # サーバの状況によって失敗する事があるので,最大で limit get()
44
+ # を試す.session には Net::HTTP クラス,またはその派生クラスの
45
+ # インスタンスを指定する.
46
46
  #
47
47
  # ------------------------------------------------------------------- #
48
48
  def get(session, path, limit = 3)
@@ -32,3 +32,4 @@
32
32
  #
33
33
  # --------------------------------------------------------------------------- #
34
34
  require 'crown/livedoor/clip'
35
+ require 'crown/livedoor/reader'
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ # --------------------------------------------------------------------------- #
3
+ #
4
+ # livedoor/reader.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 Reader
37
+ require 'cgi'
38
+ require 'net/http'
39
+ require 'crown/http'
40
+ Net::HTTP.version_1_2
41
+
42
+ # ------------------------------------------------------------------- #
43
+ #
44
+ # count
45
+ #
46
+ # feed_uri に指定したフィード URL の Livedoor Reader での購読数
47
+ # を取得する.
48
+ #
49
+ # ------------------------------------------------------------------- #
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
60
+ end
61
+
62
+ module_function :count
63
+ end # Reader
64
+ end # Livedoor
65
+ end # Crown
data/test/crown_test.rb CHANGED
@@ -42,13 +42,9 @@ class CrownTest < Test::Unit::TestCase
42
42
  # ----------------------------------------------------------------------- #
43
43
  # variables
44
44
  # ----------------------------------------------------------------------- #
45
- @@valid_uris = [
46
- "http://www.google.co.jp/",
47
- ]
48
-
49
- @@valid_users = [
50
- "tt_clown",
51
- ]
45
+ @@valid_uris = [ "http://www.google.co.jp/" ]
46
+ @@valid_feeds = [ "http://d.hatena.ne.jp/tt_clown/rss" ]
47
+ @@valid_users = [ "tt_clown" ]
52
48
 
53
49
  # ----------------------------------------------------------------------- #
54
50
  # test_hatena_count
@@ -136,14 +132,18 @@ class CrownTest < Test::Unit::TestCase
136
132
  end
137
133
 
138
134
  # ----------------------------------------------------------------------- #
135
+ #
139
136
  # test_backtype_count
140
- # ----------------------------------------------------------------------- #
141
- def test_backtype_count
142
- # normal test
143
- @@valid_uris.each { |uri|
144
- assert(Crown::BackType.count(uri, "your_api_key") > 0, "failed in " + uri)
145
- }
146
- end
137
+ #
138
+ # NOTE: BackType (BackTweets) のテストをする場合は,API key を
139
+ # 取得して "your_api_key" の部分を置き換える.
140
+ #
141
+ # ----------------------------------------------------------------------- #
142
+ #def test_backtype_count
143
+ # @@valid_uris.each { |uri|
144
+ # assert(Crown::BackType.count(uri, "your_api_key") > 0, "failed in " + uri)
145
+ # }
146
+ #end
147
147
 
148
148
  # ----------------------------------------------------------------------- #
149
149
  # test_twitter_count
@@ -160,4 +160,14 @@ class CrownTest < Test::Unit::TestCase
160
160
  assert(counter.list > 0, "wrong listed count: " + screen_name)
161
161
  }
162
162
  end
163
+
164
+ # ----------------------------------------------------------------------- #
165
+ # test_ldr_count
166
+ # ----------------------------------------------------------------------- #
167
+ def test_ldr_count
168
+ # normal test
169
+ @@valid_feeds.each { |feed_uri|
170
+ assert(Crown::Livedoor::Reader.count(feed_uri) > 0, "failed in " + feed_uri)
171
+ }
172
+ end
163
173
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crown
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - clown
@@ -61,6 +61,7 @@ files:
61
61
  - lib/crown/http.rb
62
62
  - lib/crown/livedoor.rb
63
63
  - lib/crown/livedoor/clip.rb
64
+ - lib/crown/livedoor/reader.rb
64
65
  - lib/crown/topsy.rb
65
66
  - lib/crown/tweetmeme.rb
66
67
  - lib/crown/twitter.rb