douban-ruby 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +40 -0
- data/Manifest.txt +34 -0
- data/README.txt +25 -0
- data/Rakefile +34 -0
- data/examples/example.rb +21 -0
- data/lib/douban.rb +57 -0
- data/lib/douban/author.rb +41 -0
- data/lib/douban/authorize.rb +1150 -0
- data/lib/douban/collection.rb +69 -0
- data/lib/douban/equal.rb +11 -0
- data/lib/douban/event.rb +80 -0
- data/lib/douban/mail.rb +56 -0
- data/lib/douban/miniblog.rb +59 -0
- data/lib/douban/note.rb +60 -0
- data/lib/douban/people.rb +48 -0
- data/lib/douban/recommendation.rb +47 -0
- data/lib/douban/recommendation_comment.rb +36 -0
- data/lib/douban/review.rb +66 -0
- data/lib/douban/subject.rb +87 -0
- data/lib/douban/tag.rb +39 -0
- data/spec/douban/author_spec.rb +32 -0
- data/spec/douban/authorize_spec.rb +508 -0
- data/spec/douban/collection_spec.rb +77 -0
- data/spec/douban/event_spec.rb +60 -0
- data/spec/douban/mail_spec.rb +98 -0
- data/spec/douban/miniblog_spec.rb +48 -0
- data/spec/douban/note_spec.rb +60 -0
- data/spec/douban/people_spec.rb +49 -0
- data/spec/douban/recommendation_comment_spec.rb +38 -0
- data/spec/douban/recommendation_spec.rb +48 -0
- data/spec/douban/review_spec.rb +76 -0
- data/spec/douban/tag_spec.rb +29 -0
- data/spec/douban_spec.rb +9 -0
- data/spec/spec_helper.rb +3 -0
- metadata +152 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'douban/subject'
|
3
|
+
require 'douban/author'
|
4
|
+
require 'douban/equal'
|
5
|
+
|
6
|
+
module Douban
|
7
|
+
class Review
|
8
|
+
include Douban::Equal
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def attr_names
|
12
|
+
[
|
13
|
+
:updated,
|
14
|
+
:subject,
|
15
|
+
:author,
|
16
|
+
:title,
|
17
|
+
:summary,
|
18
|
+
:link,
|
19
|
+
:id,
|
20
|
+
:rating,
|
21
|
+
:published,
|
22
|
+
:content
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
attr_names.each do |attr|
|
27
|
+
attr_accessor attr
|
28
|
+
end
|
29
|
+
def initialize(atom)
|
30
|
+
doc = case atom
|
31
|
+
when REXML::Document then atom.root
|
32
|
+
when REXML::Element then atom
|
33
|
+
else REXML::Document.new(atom).root
|
34
|
+
end
|
35
|
+
subject=REXML::XPath.first(doc,"./db:subject")
|
36
|
+
@subject=Subject.new(subject) if subject
|
37
|
+
author=REXML::XPath.first(doc,"./author")
|
38
|
+
@author=Author.new(author.to_s) if author
|
39
|
+
title=REXML::XPath.first(doc,"./title")
|
40
|
+
@title=title.text if title
|
41
|
+
updated=REXML::XPath.first(doc,"./updated")
|
42
|
+
@updated=updated.text if updated
|
43
|
+
@published=REXML::XPath.first(doc,"./published/text()").to_s
|
44
|
+
summary=REXML::XPath.first(doc,"./summary")
|
45
|
+
@summary=summary.text if summary
|
46
|
+
@content = REXML::XPath.first(doc, "./content/text()").to_s
|
47
|
+
REXML::XPath.each(doc,"./link") do |link|
|
48
|
+
@link||={}
|
49
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
50
|
+
end
|
51
|
+
id=REXML::XPath.first(doc,"./id")
|
52
|
+
@id=id.text if id
|
53
|
+
rating=REXML::XPath.first(doc,"./gd:rating")
|
54
|
+
if rating
|
55
|
+
@rating={}
|
56
|
+
@rating['min']=rating.attributes['min']
|
57
|
+
@rating['value']=rating.attributes['value']
|
58
|
+
@rating['max']=rating.attributes['max']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def review_id
|
63
|
+
/\/(\d+)$/.match(@id)[1].to_i rescue nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'douban/tag'
|
3
|
+
require 'douban/equal'
|
4
|
+
module Douban
|
5
|
+
class Subject
|
6
|
+
include Douban::Equal
|
7
|
+
class << self
|
8
|
+
def attr_names
|
9
|
+
[
|
10
|
+
:id,
|
11
|
+
:title,
|
12
|
+
:category,
|
13
|
+
:author,
|
14
|
+
:link,
|
15
|
+
:summary,
|
16
|
+
:attribute,
|
17
|
+
:tag,
|
18
|
+
:rating
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
attr_names.each do |attr|
|
23
|
+
attr_accessor attr
|
24
|
+
end
|
25
|
+
def initialize(atom='')
|
26
|
+
doc = atom.kind_of?(REXML::Element) ? atom : REXML::Document.new(atom)
|
27
|
+
id=REXML::XPath.first(doc,".//id")
|
28
|
+
@id=id.text if id
|
29
|
+
title=REXML::XPath.first(doc,".//title")
|
30
|
+
@title=title.text if title
|
31
|
+
@category={}
|
32
|
+
category=REXML::XPath.first(doc,".//category")
|
33
|
+
@category['term']=category.attributes['term'] if category
|
34
|
+
@category['scheme']=category.attributes['scheme'] if category
|
35
|
+
REXML::XPath.each(doc,".//db:tag") do |tag|
|
36
|
+
@tag||=[]
|
37
|
+
t=Tag.new
|
38
|
+
t.title=tag.attributes['name']
|
39
|
+
t.count=tag.attributes['count']
|
40
|
+
@tag<< t
|
41
|
+
end
|
42
|
+
@author||=Author.new
|
43
|
+
name=REXML::XPath.first(doc,".//author/name")
|
44
|
+
@author.name=name.text if name
|
45
|
+
uri=REXML::XPath.first(doc,".//author/uri")
|
46
|
+
@author.uri=uri.text if uri
|
47
|
+
REXML::XPath.each(doc,".//author/link") do |link|
|
48
|
+
@author.link||={}
|
49
|
+
@author.link[link.attributes['rel']]=link.attributes['href']
|
50
|
+
end
|
51
|
+
summary=REXML::XPath.first(doc,".//summary")
|
52
|
+
@summary=summary.text if summary
|
53
|
+
REXML::XPath.each(doc,".//link") do |link|
|
54
|
+
@link||={}
|
55
|
+
@link[link.attributes['rel']]=link.attributes['href']
|
56
|
+
end
|
57
|
+
REXML::XPath.each(doc,".//db:attribute") do |attribute|
|
58
|
+
@attribute||={}
|
59
|
+
@attribute[attribute.attributes['name']]=attribute.text
|
60
|
+
end
|
61
|
+
@rating={}
|
62
|
+
rating=REXML::XPath.first(doc,".//gd:rating")
|
63
|
+
if rating
|
64
|
+
@rating['min']=rating.attributes['min']
|
65
|
+
@rating['numRaters']=rating.attributes['numRaters']
|
66
|
+
@rating['average']=rating.attributes['average']
|
67
|
+
@rating['max']=rating.attributes['max']
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
class Movie<Subject
|
72
|
+
def initialize(atom)
|
73
|
+
super(atom)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
class Book<Subject
|
77
|
+
def initialize(atom)
|
78
|
+
super(atom)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
class Music<Subject
|
82
|
+
def initialize(atom)
|
83
|
+
super(atom)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
data/lib/douban/tag.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
require 'douban/equal'
|
4
|
+
|
5
|
+
module Douban
|
6
|
+
class Tag
|
7
|
+
include Douban::Equal
|
8
|
+
class << self
|
9
|
+
def attr_names
|
10
|
+
[
|
11
|
+
:id,
|
12
|
+
:count,
|
13
|
+
:title
|
14
|
+
]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
attr_names.each do |attr|
|
18
|
+
attr_accessor attr
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(atom="")
|
22
|
+
doc = case atom
|
23
|
+
when REXML::Document then atom.root
|
24
|
+
when REXML::Element then atom
|
25
|
+
when nil then nil
|
26
|
+
else REXML::Document.new(atom).root
|
27
|
+
end
|
28
|
+
|
29
|
+
unless doc.nil?
|
30
|
+
id=REXML::XPath.first(doc,"./id")
|
31
|
+
@id=id.text if id
|
32
|
+
title=REXML::XPath.first(doc,"./title")
|
33
|
+
@title=title.text if title
|
34
|
+
@count=REXML::XPath.first(doc,"./db:count/text()").to_s.to_i rescue nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../spec_helper')
|
2
|
+
|
3
|
+
require 'douban/author'
|
4
|
+
|
5
|
+
module Douban
|
6
|
+
describe Author do
|
7
|
+
before do
|
8
|
+
@s = <<eos
|
9
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
10
|
+
<entry xmlns="http://www.w3.org/2005/Atom">
|
11
|
+
<link href="http://api.douban.com/people/41502874" rel="self"/>
|
12
|
+
<link href="http://www.douban.com/people/41502874/" rel="alternate"/>
|
13
|
+
<name>SJo1pHHJGmCx</name>
|
14
|
+
<uri>http://api.douban.com/people/41502874</uri>
|
15
|
+
</entry>
|
16
|
+
eos
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should correct deserialize" do
|
20
|
+
author = Author.new(@s)
|
21
|
+
author.uri.should == "http://api.douban.com/people/41502874"
|
22
|
+
author.link.should == {"self"=>"http://api.douban.com/people/41502874",
|
23
|
+
"alternate"=>"http://www.douban.com/people/41502874/"}
|
24
|
+
author.name.should == "SJo1pHHJGmCx"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "== should works" do
|
28
|
+
Author.new(@s).should == Author.new(@s)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,508 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../spec_helper')
|
2
|
+
|
3
|
+
require 'douban/authorize'
|
4
|
+
|
5
|
+
module Douban
|
6
|
+
describe Authorize do
|
7
|
+
before(:each) do
|
8
|
+
Authorize.debug = true
|
9
|
+
@api_key = '042bc009d7d4a04d0c83401d877de0e7'
|
10
|
+
@secret_key = 'a9bb2d7f8cc00110'
|
11
|
+
@authorize = Authorize.new(@api_key, @secret_key)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "helper" do
|
15
|
+
context "url_encode" do
|
16
|
+
it "should support integer" do
|
17
|
+
@authorize.send(:url_encode, 1).should == "1"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when oauth login" do
|
23
|
+
it "should return login url and request token" do
|
24
|
+
@authorize.authorized?.should be_false
|
25
|
+
@authorize.get_authorize_url.should =~ %r{^http://.*oauth_token=[0-9a-f]{32}&oauth_callback=.*$}
|
26
|
+
@authorize.authorized?.should be_false
|
27
|
+
@authorize.request_token.token.should =~ /[0-9a-f]{32}/
|
28
|
+
@authorize.request_token.secret.should =~ /[0-9a-f]{16}/
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "oauth verify" do
|
33
|
+
before(:each) do
|
34
|
+
@request_token = "a" * 32
|
35
|
+
@request_secret = "b" * 16
|
36
|
+
|
37
|
+
@access_token = "c"*32
|
38
|
+
@access_secret = "d"*16
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should support set request token" do
|
42
|
+
@authorize.request_token = OAuth::Token.new(@request_token, @request_secret)
|
43
|
+
@authorize.request_token.kind_of?(OAuth::RequestToken).should == true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "auth should works" do
|
47
|
+
request_token_mock = mock("request_token")
|
48
|
+
request_token_mock.stub!(:kind_of?).with(OAuth::RequestToken).and_return(true)
|
49
|
+
request_token_mock.stub!(:get_access_token).and_return(
|
50
|
+
OAuth::Token.new(@access_token, @access_secret)
|
51
|
+
)
|
52
|
+
|
53
|
+
@authorize.request_token = request_token_mock
|
54
|
+
@authorize.auth
|
55
|
+
@authorize.access_token.class.should == OAuth::AccessToken
|
56
|
+
@authorize.access_token.token.should == @access_token
|
57
|
+
@authorize.access_token.secret.should == @access_secret
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "logged in with oauth" do
|
62
|
+
before(:each) do
|
63
|
+
Authorize.debug = true
|
64
|
+
@access_token = '0306646daca492b609132d4905edb822'
|
65
|
+
@access_secret = '22070cec426cb925'
|
66
|
+
@authorize.access_token = OAuth::Token.new(@access_token, @access_secret)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
it "should authorized?" do
|
71
|
+
@authorize.authorized?.should == true
|
72
|
+
end
|
73
|
+
|
74
|
+
context "people" do
|
75
|
+
context "get_people" do
|
76
|
+
it "should works" do
|
77
|
+
people = @authorize.get_people
|
78
|
+
people.nil?.should == false
|
79
|
+
people.uid.should == "41502874"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "get_friends" do
|
84
|
+
it "should works" do
|
85
|
+
friends = @authorize.get_friends
|
86
|
+
friends.size.should >= 2
|
87
|
+
friends[0].id.should_not == friends[-1].id
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "get_contacts" do
|
92
|
+
it "should works" do
|
93
|
+
friends = @authorize.get_contacts
|
94
|
+
friends.size.should >= 2
|
95
|
+
friends[0].id.should_not == friends[-1].id
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "search_people" do
|
100
|
+
it "should works" do
|
101
|
+
friends = @authorize.search_people('li')
|
102
|
+
friends.size.should >= 2
|
103
|
+
friends[0].id.should_not == friends[-1].id
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "miniblog" do
|
109
|
+
context "create_miniblog" do
|
110
|
+
it "should publish miniblog with html characters and return Miniblog" do
|
111
|
+
miniblog = @authorize.create_miniblog("<b>单元测试#{rand}")
|
112
|
+
miniblog.kind_of?(Douban::Miniblog).should == true
|
113
|
+
end
|
114
|
+
|
115
|
+
it "delete miniblog should works" do
|
116
|
+
miniblog = @authorize.create_miniblog("<b>单元测试#{rand}")
|
117
|
+
miniblog.kind_of?(Douban::Miniblog).should == true
|
118
|
+
id = %r{http://api.douban.com/miniblog/(\d+)}.match(miniblog.id)[1]
|
119
|
+
@authorize.delete_miniblog(id).should == true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "get_user_miniblog" do
|
124
|
+
it "should return [Miniblog] with different id" do
|
125
|
+
miniblogs = @authorize.get_user_miniblog
|
126
|
+
miniblogs.size.should >= 2
|
127
|
+
miniblogs[0].class.should == Miniblog
|
128
|
+
miniblogs[0].id.should_not == miniblogs[-1].id
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "get_user_contact_miniblog" do
|
133
|
+
it "should return [Miniblog] with different id" do
|
134
|
+
miniblogs = @authorize.get_user_contact_miniblog
|
135
|
+
miniblogs.size.should >= 2
|
136
|
+
miniblogs[0].class.should == Miniblog
|
137
|
+
miniblogs[0].id.should_not == miniblogs[-1].id
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "recommendation" do
|
143
|
+
before do
|
144
|
+
@recommendation_id = 4312524
|
145
|
+
@recommendation_title = "推荐活动QClub:敏捷在互联网时代产品研发中的实践(12.27 深圳)"
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
context "get_recommendation" do
|
150
|
+
it "should return Recommendation if found" do
|
151
|
+
recommendation = @authorize.get_recommendation(@recommendation_id)
|
152
|
+
recommendation.class.should == Douban::Recommendation
|
153
|
+
recommendation.title.should == @recommendation_title
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should return nil if not found" do
|
157
|
+
@authorize.get_recommendation(28732532).should == nil
|
158
|
+
end
|
159
|
+
end
|
160
|
+
context "get_user_recommendations" do
|
161
|
+
it "should work" do
|
162
|
+
recommendations = @authorize.get_user_recommendations("aka")
|
163
|
+
recommendations.size.should >= 2
|
164
|
+
recommendations[0].class.should == Douban::Recommendation
|
165
|
+
recommendations[0].id.should_not == recommendations[-1].id
|
166
|
+
end
|
167
|
+
end
|
168
|
+
context "get_recommendation_comments" do
|
169
|
+
it "should work" do
|
170
|
+
recommendations = @authorize.get_recommendation_comments(4312524)
|
171
|
+
recommendations.size.should >= 2
|
172
|
+
recommendations[0].class.should == Douban::RecommendationComment
|
173
|
+
recommendations[0].id.should_not == recommendations[-1].id
|
174
|
+
end
|
175
|
+
end
|
176
|
+
context "create_recommendation & delete_recommendation" do
|
177
|
+
it "should return a Recommendation and can be delete" do
|
178
|
+
recommendation = @authorize.create_recommendation("http://api.douban.com/movie/subject/1424406", "标题", "神作")
|
179
|
+
recommendation.class.should == Douban::Recommendation
|
180
|
+
recommendation.comment.should == "神作"
|
181
|
+
@authorize.delete_recommendation(recommendation).should == true
|
182
|
+
end
|
183
|
+
it "should can delete through recommendation_id" do
|
184
|
+
@authorize.delete_recommendation(
|
185
|
+
@authorize.create_recommendation("http://api.douban.com/movie/subject/1424406", "标题", "神作").recommendation_id).should == true
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "create_recommendation_comment & delete_recommendation_comment" do
|
190
|
+
it "should return a RecommendationComment and can be delete" do
|
191
|
+
comment = @authorize.create_recommendation_comment(@recommendation_id, "好文")
|
192
|
+
comment.class.should == Douban::RecommendationComment
|
193
|
+
comment.content.should == "好文"
|
194
|
+
@authorize.delete_recommendation_comment(comment).should == true
|
195
|
+
end
|
196
|
+
it "should can be delete through recommendation and comment_id" do
|
197
|
+
comment = @authorize.create_recommendation_comment(@recommendation_id, "好文")
|
198
|
+
@authorize.delete_recommendation_comment(@authorize.get_recommendation(@recommendation_id),
|
199
|
+
comment.comment_id).should == true
|
200
|
+
end
|
201
|
+
it "should can be delete through recommendation_id and comment_id" do
|
202
|
+
comment = @authorize.create_recommendation_comment(@recommendation_id, "好文")
|
203
|
+
@authorize.delete_recommendation_comment(@recommendation_id, comment.comment_id).should == true
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "collection" do
|
209
|
+
context "create_collection" do
|
210
|
+
it "should return Collection" do
|
211
|
+
collection = @authorize.create_collection("http://api.douban.com/movie/subject/1424406", "a", 5, "watched", ["tag"])
|
212
|
+
collection.class.should == Douban::Collection
|
213
|
+
@authorize.delete_collection(collection).should == true
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context "modify_collection" do
|
218
|
+
it "should return Collection" do
|
219
|
+
collection = @authorize.create_collection("http://api.douban.com/movie/subject/1424406", "a", 5, "watched", ["tag"])
|
220
|
+
collection = @authorize.modify_collection(collection, nil, "b", 5, "watched", ["tag"])
|
221
|
+
collection.class.should == Douban::Collection
|
222
|
+
collection.summary.should == "b"
|
223
|
+
@authorize.delete_collection(collection).should == true
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "get_user_collection" do
|
228
|
+
it "should return [Collection] with different id" do
|
229
|
+
collections = @authorize.get_user_collection
|
230
|
+
collections.size.should >= 2
|
231
|
+
collections[0].class.should == Collection
|
232
|
+
collections[0].id.should_not == collections[-1].id
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "event" do
|
238
|
+
context "create_event" do
|
239
|
+
it "should return Event" do
|
240
|
+
event = @authorize.create_event("douban-ruby 单元测试", "event 好像不能自动删除", "大山子798艺术区 IT馆")
|
241
|
+
event.class.should == Douban::Event
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
context "get_event_participant_people" do
|
246
|
+
it "should return [People] with different id" do
|
247
|
+
event_id = 11723349
|
248
|
+
people = @authorize.get_event_participant_people(event_id)
|
249
|
+
people.size.should >= 2
|
250
|
+
people[0].class.should == People
|
251
|
+
people[0].id.should_not == people[-1].id
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context "get_wisher_people" do
|
256
|
+
it "should return [People] with different id" do
|
257
|
+
event_id = 11723349
|
258
|
+
people = @authorize.get_event_wisher_people(event_id)
|
259
|
+
people.size.should >= 2
|
260
|
+
people[0].class.should == People
|
261
|
+
people[0].id.should_not == people[-1].id
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "get_user_events" do
|
266
|
+
it "should return [Event] with different id" do
|
267
|
+
people_id = 'supernb'
|
268
|
+
events = @authorize.get_user_events(people_id)
|
269
|
+
events.size.should >= 2
|
270
|
+
events[0].class.should == Event
|
271
|
+
events[0].id.should_not == events[-1].id
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context "get_user_initiate_events" do
|
276
|
+
it "should return [Event] with different id" do
|
277
|
+
people_id = 'supernb'
|
278
|
+
events = @authorize.get_user_initiate_events(people_id)
|
279
|
+
events.size.should >= 2
|
280
|
+
events[0].class.should == Event
|
281
|
+
events[0].id.should_not == events[-1].id
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context "get_user_participate_events" do
|
286
|
+
it "should return [Event] with different id" do
|
287
|
+
people_id = 'supernb'
|
288
|
+
events = @authorize.get_user_participate_events(people_id)
|
289
|
+
events.size.should >= 2
|
290
|
+
events[0].class.should == Event
|
291
|
+
events[0].id.should_not == events[-1].id
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context "get_user_wish_events" do
|
296
|
+
it "should return [Event] with different id" do
|
297
|
+
people_id = 'supernb'
|
298
|
+
events = @authorize.get_user_wish_events(people_id)
|
299
|
+
events.size.should >= 2
|
300
|
+
events[0].class.should == Event
|
301
|
+
events[0].id.should_not == events[-1].id
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context "get_city_events" do
|
306
|
+
it "should return [Event] with different id" do
|
307
|
+
city_id = 'beijing'
|
308
|
+
events = @authorize.get_city_events(city_id)
|
309
|
+
events.size.should >= 2
|
310
|
+
events[0].class.should == Event
|
311
|
+
events[0].id.should_not == events[-1].id
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context "search_events" do
|
316
|
+
it "should return [Event] with different id" do
|
317
|
+
q = '电影'
|
318
|
+
events = @authorize.search_events(q)
|
319
|
+
events.size.should >= 2
|
320
|
+
events[0].class.should == Event
|
321
|
+
events[0].id.should_not == events[-1].id
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
=begin
|
326
|
+
context "modify_event" do
|
327
|
+
it "should return Event" do
|
328
|
+
event = @authorize.create_event("douban-ruby 单元测试", "event 好像不能自动删除", "大山子798艺术区 IT馆")
|
329
|
+
event = @authorize.modify_event(event, "douban-ruby 单元测试", "event 好像不能自动删除", "大山子798艺术区 IT馆")
|
330
|
+
event.class.should == Douban::Event
|
331
|
+
event.title.should == "douban-ruby 单元测试2"
|
332
|
+
end
|
333
|
+
end
|
334
|
+
=end
|
335
|
+
end
|
336
|
+
|
337
|
+
context "mail" do
|
338
|
+
context "get_mail_inbox" do
|
339
|
+
it "should works" do
|
340
|
+
@mails = @authorize.get_mail_inbox
|
341
|
+
@mails.size.should >= 2
|
342
|
+
@mails[0].id.should_not == @mails[-1].id
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context "send_mail" do
|
347
|
+
it "should success or return captcha_token" do
|
348
|
+
res = @authorize.send_mail("lidaobing", "hello", "world")
|
349
|
+
if res.class != Hash
|
350
|
+
res.should == true
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
context "get_mail" do
|
356
|
+
it "should work" do
|
357
|
+
mail = @authorize.get_mail(82937520)
|
358
|
+
mail.class.should == Mail
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context "get_unread_mail" do
|
363
|
+
it "should return [Mail] with different id" do
|
364
|
+
mails = @authorize.get_unread_mail
|
365
|
+
mails.size.should >= 2
|
366
|
+
mails[0].class.should == Mail
|
367
|
+
mails[0].id.should_not == mails[-1].id
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context "get_mail_outbox" do
|
372
|
+
it "should return [Mail] with different id" do
|
373
|
+
mails = @authorize.get_mail_outbox
|
374
|
+
mails.size.should >= 2
|
375
|
+
mails[0].class.should == Mail
|
376
|
+
mails[0].id.should_not == mails[-1].id
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
context "note" do
|
382
|
+
context "create_note" do
|
383
|
+
it "should return Note" do
|
384
|
+
note = @authorize.create_note("a", "b")
|
385
|
+
note.class.should == Note
|
386
|
+
@authorize.delete_note(note).should == true
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
context "modify_note" do
|
391
|
+
it "should return Note" do
|
392
|
+
note = @authorize.create_note("a", "b")
|
393
|
+
note = @authorize.modify_note(note, "c", "d")
|
394
|
+
note.class.should == Note
|
395
|
+
note.title.should == "c"
|
396
|
+
@authorize.delete_note(note).should == true
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
context "get_user_notes" do
|
401
|
+
it "should return notes with different id" do
|
402
|
+
notes = @authorize.get_user_notes
|
403
|
+
notes.size.should >= 2
|
404
|
+
notes[0].id.should_not == notes[-1].id
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
context "review" do
|
410
|
+
|
411
|
+
context "create review" do
|
412
|
+
it "should return Review" do
|
413
|
+
@subject = @authorize.get_book(1088840)
|
414
|
+
review = @authorize.create_review(@subject, "douban-ruby 单元测试",
|
415
|
+
"douban-ruby 单元测试"*10)
|
416
|
+
review.class.should == Review
|
417
|
+
@authorize.delete_review(review).should == true
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
context "modify review" do
|
422
|
+
it "should return Review" do
|
423
|
+
@subject = @authorize.get_book(1088840)
|
424
|
+
review = @authorize.create_review(@subject, "douban-ruby 单元测试",
|
425
|
+
"douban-ruby 单元测试"*10)
|
426
|
+
review = @authorize.modify_review(review, nil, "douban-ruby 单元测试", "douban-ruby 单元测试"*11)
|
427
|
+
review.class.should == Review
|
428
|
+
review.content.should == "douban-ruby 单元测试"*11
|
429
|
+
@authorize.delete_review(review).should == true
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
context "get_book_reviews" do
|
434
|
+
it "should return [Review] with different id" do
|
435
|
+
reviews = @authorize.get_book_reviews(1258490)
|
436
|
+
reviews.size.should >= 2
|
437
|
+
reviews[0].id.should_not == reviews[-1].id
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
context "get_user_reviews" do
|
442
|
+
it "should return [Review] with different id" do
|
443
|
+
reviews = @authorize.get_user_reviews('40896712')
|
444
|
+
reviews.size.should >= 2
|
445
|
+
reviews[0].id.should_not == reviews[-1].id
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
context "subject" do
|
451
|
+
|
452
|
+
context "get_book" do
|
453
|
+
it "should return Book" do
|
454
|
+
book = @authorize.get_book(1088840)
|
455
|
+
book.class.should == Book
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
context "search_book" do
|
460
|
+
it "should return [Book] with different id" do
|
461
|
+
books = @authorize.search_book("ruby")
|
462
|
+
books.size.should >= 2
|
463
|
+
books[0].class.should == Book
|
464
|
+
books[0].id.should_not == books[-1].id
|
465
|
+
end
|
466
|
+
end
|
467
|
+
context "search_movie" do
|
468
|
+
it "should return [Movie] with different id" do
|
469
|
+
movies = @authorize.search_movie("america")
|
470
|
+
movies.size.should >= 2
|
471
|
+
movies[0].class.should == Movie
|
472
|
+
movies[0].id.should_not == movies[-1].id
|
473
|
+
end
|
474
|
+
end
|
475
|
+
context "search_music" do
|
476
|
+
it "should return [Music] with different id" do
|
477
|
+
musics = @authorize.search_music("america")
|
478
|
+
musics.size.should >= 2
|
479
|
+
musics[0].class.should == Music
|
480
|
+
musics[0].id.should_not == musics[-1].id
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
context "get_book_tags" do
|
485
|
+
it "should return [Tag] with different id" do
|
486
|
+
book_id = 4741216
|
487
|
+
tags = @authorize.get_book_tags(book_id)
|
488
|
+
tags.size.should >= 2
|
489
|
+
tags[0].class.should == Tag
|
490
|
+
tags[0].id.should_not == tags[-1].id
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
context "get_user_tags" do
|
495
|
+
it "should return [Tag] with different id" do
|
496
|
+
tags = @authorize.get_user_tags()
|
497
|
+
tags.size.should >= 2
|
498
|
+
tags[0].class.should == Tag
|
499
|
+
tags[0].id.should_not == tags[-1].id
|
500
|
+
end
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
|
505
|
+
end # context "logged in with oauth"
|
506
|
+
end #describe
|
507
|
+
end #Module
|
508
|
+
|