douban_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ *.rbc
3
+ .DS_Store
4
+ .bundle
5
+ .rvmrc
6
+ .yardoc
7
+ .rake_tasks~
8
+ Gemfile.lock
9
+ coverage/*
10
+ doc/*
11
+ log/*
12
+ pkg/*
13
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2012 Sean Lee
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+
23
+ Copyright (c) 2011 Instagram (Burbn, Inc.) (from https://github.com/Instagram/instagram-ruby-gem/)
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+
9
+ namespace :doc do
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new do |task|
12
+ task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
13
+ task.options = [
14
+ '--output-dir', 'doc/yard',
15
+ '--markup', 'markdown',
16
+ '--charset', 'UTF-8',
17
+ ]
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/douban_api/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.add_runtime_dependency('faraday', ['>= 0.7', '< 0.9'])
6
+ s.add_runtime_dependency('faraday_middleware', '~> 0.8')
7
+ s.add_runtime_dependency('multi_json', '>= 1.0.3', '~> 1.0')
8
+ s.add_runtime_dependency('hashie', '>= 0.4.0')
9
+ s.add_development_dependency('json', '~> 1.7')
10
+ s.add_development_dependency('rspec', '~> 2.4')
11
+ s.add_development_dependency('webmock', '~> 1.6')
12
+ s.add_development_dependency('bluecloth', '~> 2.0.11')
13
+ s.add_development_dependency('rake')
14
+ s.add_development_dependency('yard')
15
+ s.add_development_dependency('pry')
16
+ s.authors = ["Sean Lee"]
17
+ s.description = %q{A Ruby wrapper for the Douban API v2 based on instagram's official ruby gem}
18
+ s.email = ['iseansay@gmail.com']
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.files = `git ls-files`.split("\n")
21
+ s.name = 'douban_api'
22
+ s.platform = Gem::Platform::RUBY
23
+ s.require_paths = ['lib']
24
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
25
+ s.summary = %q{Ruby wrapper for the Douban API v2}
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.version = Douban::VERSION.dup
28
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../connection', __FILE__)
2
+ require File.expand_path('../request', __FILE__)
3
+ require File.expand_path('../oauth', __FILE__)
4
+
5
+ module Douban
6
+ # @private
7
+ class API
8
+ # @private
9
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
10
+
11
+ # Creates a new API
12
+ def initialize(options={})
13
+ options = Douban.options.merge(options)
14
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ include Connection
20
+ include Request
21
+ include OAuth
22
+ end
23
+ end
@@ -0,0 +1,102 @@
1
+ module Douban
2
+ class Client
3
+ # 豆瓣日记 API V2 http://developers.douban.com/wiki/?title=note_v2
4
+ module Album
5
+ def album(id)
6
+ get "v2/album/#{id}"
7
+ end
8
+
9
+ def create_album(options={})
10
+ post "v2/albums", options
11
+ end
12
+
13
+ def update_album(id, options={})
14
+ put "v2/album/#{id}", options
15
+ end
16
+
17
+ def remove_album(id)
18
+ delete "v2/album/#{id}"
19
+ end
20
+
21
+ def album_photos(id, options)
22
+ response = get("v2/album/#{id}/photos", options)
23
+ response["photos"]
24
+ end
25
+
26
+ def like_album(id)
27
+ post "v2/album/#{id}/like"
28
+ end
29
+
30
+ def unline_album(id)
31
+ delete "v2/album/#{id}/like"
32
+ end
33
+
34
+ def albums(user_id, options)
35
+ if user_id.nil?
36
+ response = get("v2/album/user_created/#{get_user_id}", options)
37
+ else
38
+ response = get("v2/album/user_created/#{user_id}", options)
39
+ end
40
+ response["albums"]
41
+ end
42
+
43
+ def liked_albums(user_id, options)
44
+ if user_id.nil?
45
+ response = get("v2/album/user_liked/#{get_user_id}", options)
46
+ else
47
+ response = get("v2/album/user_liked/#{user_id}", options)
48
+ end
49
+ response["albums"]
50
+ end
51
+
52
+ def photo(id)
53
+ get "v2/photo/#{id}"
54
+ end
55
+
56
+ def upload_photo(album_id, image_path, options={})
57
+ file = Faraday::UploadIO.new(image_path, options[:content_type])
58
+ post "v2/album/#{album_id}", options.merge(:image => file)
59
+ end
60
+
61
+ def update_photo(id, desc)
62
+ put "v2/photo/#{id}", {:desc => desc}
63
+ end
64
+
65
+ def delete_photo(id)
66
+ delete "v2/photo/#{id}"
67
+ end
68
+
69
+ def like_photo(id)
70
+ post "v2/photo/#{id}/like"
71
+ end
72
+
73
+ def unlike_photo(id)
74
+ delete "v2/photo/#{id}/like"
75
+ end
76
+
77
+ # 照片回复列表
78
+ # @scope community_basic_photo
79
+ def photo_comments(id, options={})
80
+ comments('photo', id, options={})
81
+ end
82
+
83
+ # 回复照片
84
+ # @scope community_advanced_photo
85
+ def create_photo_comment(id, content)
86
+ create_comment('photo', id, content)
87
+ end
88
+
89
+ # 获得照片单条回复
90
+ # @scope community_basic_photo
91
+ def photo_comment(photo_id, comment_id)
92
+ comment('photo', photo_id, comment_id)
93
+ end
94
+
95
+ # 删除照片单条回复
96
+ # @scope community_advanced_photo
97
+ def remove_photo_comment(photo_id, comment_id)
98
+ remove_comment('photo', photo_id, comment_id)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,397 @@
1
+ module Douban
2
+ class Client
3
+ # 图书Api V2
4
+ # @see http://developers.douban.com/wiki/?title=book_v2
5
+ module Book
6
+
7
+ # 获取图书信息
8
+ #
9
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_book
10
+ # @scope book_basic_r
11
+ # @authenticated false
12
+ # @param id [String] 图书的id
13
+ # @return [Hashie::Mash] 图书信息
14
+ # @example 获取 id为3821057 的图书信息
15
+ # Douban.book('3821057')
16
+ def book(id)
17
+ response = get "v2/book/#{id}"
18
+ end
19
+
20
+ # 根据isbn获取图书信息
21
+ #
22
+ # @scope book_basic_r
23
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_isbn_book
24
+ # @authenticated false
25
+ # @param id [String] 图书的id
26
+ # @return [Hashie::Mash]
27
+ # @example 获取 ISBN为9787208083950 的图书信息
28
+ # Douban.isbn('9787208083950')
29
+ def isbn(id)
30
+ response = get "v2/book/isbn/#{id}"
31
+ end
32
+
33
+ # 通过关键字搜索图书
34
+ #
35
+ # @scope book_basic_r
36
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_book_search
37
+ # @authenticated false
38
+ # @param q [String] 查询关键字
39
+ # @return [Hashie::Mash] 符合查询条件的图书列表
40
+ # @example 搜索 的图书信息
41
+ # Douban.search_books("搏击俱乐部")
42
+ def search_books(q, options={})
43
+ response = get "v2/book/search", options.merge(:q => q)
44
+ response["books"]
45
+ end
46
+
47
+ # 通过tag搜索图书
48
+ #
49
+ # @scope book_basic_r
50
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_book_search
51
+ # @authenticated false
52
+ # @param tag [String] 查询的tag
53
+ # @return [Array<Hashie::Mash>] 符合查询条件的图书列表
54
+ # @example 搜索tag包含"美国文学"的图书信息
55
+ # Douban.search_books_by_tag("美国文学")
56
+ def search_books_by_tag(tag, options={})
57
+ response = get "v2/book/search", options.merge(:tag => tag)
58
+ response["books"]
59
+ end
60
+
61
+ # 某个图书中标记最多的标签, 最多返回前50个tag
62
+ #
63
+ # @scope book_basic_r
64
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_book_tags
65
+ # @authenticated false
66
+ # @param id [String] 图书的id
67
+ # @return [Array<Hashie::Mash>] 标签的列表
68
+ # @example 获取 id为3821057 的图书的标记最多的标签
69
+ # Douban.book_tags("3821057")
70
+ def book_tags(id, optins={})
71
+ response = get "v2/book/#{id}/tags", options
72
+ responses["tags"]
73
+ end
74
+
75
+ # 获取用户对图书的所有标签
76
+ #
77
+ # @scope book_basic_r
78
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_user_book_tags
79
+ # @authenticated false
80
+ # @param name [String] 用户uid或者数字id
81
+ # @return [Array<Hashie::Mash>] 标签列表
82
+ # @example 获取ahbei图书收藏的所有标签
83
+ # Douban.user_book_tags('ahbei')
84
+ # @example 获取已认证用户的图书收藏的所有标签
85
+ # client.user_book_tags
86
+ def user_book_tags(name=nil, options={})
87
+ if name.nil?
88
+ response = get("v2/book/user/#{get_user_id}/tags", options)
89
+ else
90
+ response = get("v2/book/user/#{name}/tags", options)
91
+ end
92
+
93
+ response["tags"]
94
+ end
95
+
96
+ # 发表新评论
97
+ #
98
+ # @scope douban_basic_common
99
+ # @see http://developers.douban.com/wiki/?title=book_v2#post_book_review
100
+ # @authenticated true
101
+ # @param id [String] 图书的id
102
+ # @option options [String] :title 必传
103
+ # @option options [String] :content 必传,且多于150字
104
+ # @option options [Integer] :rating 非必传,数字1~5为合法值,其他信息默认为不打分
105
+ # @return [Hashie::Mash] 图书评论Review信息
106
+ # @example 给 id为3821057 的图书添加评论
107
+ # client.create_book_review("3821057", {
108
+ # :title => "我们的萧条就是我们的生活",
109
+ # :content => "嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
110
+ # 嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
111
+ # 嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻...(省略一些嘻)",
112
+ # :rating => 5
113
+ # })
114
+ def create_book_review(book_id, options={})
115
+ post "v2/book/reviews", options.merge(:book => book_id)
116
+ end
117
+
118
+ # 修改评论
119
+ #
120
+ # @scope douban_basic_common
121
+ # @see http://developers.douban.com/wiki/?title=book_v2#put_book_review
122
+ # @authenticated true
123
+ # @param id [String] 评论的id
124
+ # @option options [String] :title 必传
125
+ # @option options [String] :content 必传,且多于150字
126
+ # @option options [Integer] :rating 非必传,数字1~5为合法值,其他信息默认为不打分
127
+ # @return [Hashie::Mash] 图书评论Review信息
128
+ # @example 修改id为5669920的评论
129
+ # client.edit_book_review("5669920", {
130
+ # :title => "我们读故事,看电影,不过是因为我们懦弱",
131
+ # :content => "嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
132
+ # 嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
133
+ # 嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻...(省略一些嘻)",
134
+ # :rating => 5
135
+ # })
136
+ def edit_book_review(id, options={})
137
+ put "v2/book/reviews/#{id}", options
138
+ end
139
+
140
+ # 删除评论
141
+ #
142
+ # @scope douban_basic_common
143
+ # @see http://developers.douban.com/wiki/?title=book_v2#delete_book_review
144
+ # @authenticated true
145
+ # @param id [String] 图书的id
146
+ # @return [Boolean] 删除成功则返回true, 否则false
147
+ # @example 删除 id为5669920 图书评论
148
+ # client.remove_book_review('5669920')
149
+ def remove_book_review(id)
150
+ begin
151
+ delete "v2/book/review/#{id}"
152
+ return true
153
+ rescue Douban::NotFound
154
+ return false
155
+ end
156
+ end
157
+
158
+ # 获取某篇笔记的信息
159
+ #
160
+ # @scope book_basic_r
161
+ # @see http://developers.douban.com/wiki/?title=book_v2#delete_book_review
162
+ # @authenticated true
163
+ # @param id [String] 笔记的id
164
+ # @option options [String] :format
165
+ # 返回content字段格式,选填(编辑伪标签格式:text,HTML格式:html)默认为text
166
+ # @return [Hashie::Mash] 笔记的信息
167
+ # @example 获取id为5963722的笔记的信息
168
+ # client.annotation('5963722')
169
+ def annotation(id, options={})
170
+ response = get "v2/book/annotation/#{id}", options
171
+ end
172
+
173
+
174
+ # 获取某本图书的所有笔记
175
+ #
176
+ # @scope book_basic_r
177
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_book_annotations
178
+ # @authenticated false
179
+ # @param id [String] 图书的id
180
+ # @option options [String] :format
181
+ # 返回content字段格式: 选填(编辑伪标签格式:text,HTML格式:html)默认为text
182
+ # @option options [String] :order
183
+ # 排序: 选填(最新笔记:collect, 按有用程度:rank, 按页码先后:page),默认为rank
184
+ # @option options [Integer] :page
185
+ # 按页码过滤: 选填
186
+ # @return [Array<Hashie::Mash>] 笔记的列表
187
+ # @example 获取 id为3821057的图书 的笔记
188
+ # client.book_annotations('3821057')
189
+ def book_annotations(id, options={})
190
+ response = get "v2/book/#{id}/annotations"
191
+ response["annotations"]
192
+ end
193
+
194
+ # 用户给某本图书写笔记
195
+ #
196
+ # @scope book_basic_w
197
+ # @see http://developers.douban.com/wiki/?title=book_v2#post_book_annotation
198
+ # @authenticated true
199
+ # @param id [String] 图书的id
200
+ # @param options [String] :content
201
+ # 笔记内容: 必填,需多于15字
202
+ # @option options [Integer] :page
203
+ # 页码: 页码或章节名选填其一,最多6位正整数
204
+ # @option options [String] :chapter
205
+ # 章节名: 页码或章节名选填其一,最多100字
206
+ # @option options [String] :privacy
207
+ # 隐私设 选填: 值为'private'为设置成仅自己可见,其他默认为公开
208
+ # @return [Hashie::Mash] 该笔记内容
209
+ # @example 给id3821057的图书的第10页添加笔记
210
+ # client.create_book_annotations('3821057',{
211
+ # :content =>"据说是现在新浪共享上是有下载的",
212
+ # :page => 10
213
+ # })
214
+ # TODO 支持图片
215
+ def create_book_annotation(id, options={})
216
+ post "v2/book/reviews", options
217
+ end
218
+
219
+ # 用户修改某篇笔记
220
+ #
221
+ # @scope book_basic_w
222
+ # @see http://developers.douban.com/wiki/?title=book_v2#put_annotation
223
+ # @authenticated true
224
+ # @param id [String] 图书的id
225
+ # @param options [String] :content
226
+ # 笔记内容: 必填,需多于15字
227
+ # @option options [Integer] :page
228
+ # 页码: 页码或章节名选填其一,最多6位正整数
229
+ # @option options [String] :chapter
230
+ # 章节名: 页码或章节名选填其一,最多100字
231
+ # @option options [String] :privacy
232
+ # 隐私设 选填: 值为'private'为设置成仅自己可见,其他默认为公开
233
+ # @return [Hashie::Mash] 该笔记内容
234
+ # @example 给id3821057的图书的第10页添加笔记
235
+ # client.create_book_annotations('3821057',{
236
+ # :content =>"据说是现在新浪共享上是有下载的",
237
+ # :page => 10
238
+ # })
239
+ # TODO 支持图片
240
+ def edit_book_annotation(id, options={})
241
+ put "v2/book/annotation/#{id}", options
242
+ end
243
+
244
+ # 用户删除某篇笔记
245
+ #
246
+ # @scope book_basic_w
247
+ # @see http://developers.douban.com/wiki/?title=book_v2#delete_annotation
248
+ # @authenticated true
249
+ # @param id [String] 笔记的id
250
+ # @return [Boolean] 删除成功则返回true, 否则false
251
+ # @example 删除id为15143201的笔记 (只能删除用户自己的笔记)
252
+ # client.remove_book_annotation('15143201')
253
+ def remove_book_annotation(id)
254
+ begin
255
+ delete "v2/book/annotation/#{id}"
256
+ return true
257
+ rescue Douban::NotFound
258
+ return false
259
+ end
260
+ end
261
+
262
+ # 获取某个用户的所有笔记
263
+ #
264
+ # @scope book_basic_r
265
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_user_annotations
266
+ # @authenticated false
267
+ # @param name [String] 用户uid或者数字id
268
+ # @return [Array<Hashie::Mash>] 该用户的笔记列表
269
+ # @example 获取ahbei的所有笔记
270
+ # Douban.user_book_annotations('ahbei')
271
+ # @example 获取已认证用户的所有笔记
272
+ # client.user_book_annotations()
273
+ def user_book_annotations(name=nil, options={})
274
+ if name.nil?
275
+ response = get("v2/book/user/#{get_user_id}/annotations", options)
276
+ else
277
+ response = get("v2/book/user/#{name}/annotations", options)
278
+ end
279
+
280
+ response["annotations"]
281
+ end
282
+
283
+ # 获取用户对某本图书的收藏信息
284
+ #
285
+ # @scope book_basic_r
286
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_book_collection
287
+ # @authenticated true
288
+ # @param id [String] 图书的id
289
+ # @return [Hashie::Mash] 用户对这本书的收藏信息
290
+ # @example 获取已认证用户的对id为3821057的书的收藏信息
291
+ # client.user_book('3821057')
292
+ def user_book(id)
293
+ response = get "v2/book/#{id}/collection"
294
+ end
295
+
296
+ # 获取某个用户的所有图书收藏信息
297
+ #
298
+ # @scope book_basic_r
299
+ # @see http://developers.douban.com/wiki/?title=book_v2#get_user_collections
300
+ # @authenticated false
301
+ # @param name [String] 用户uid或者数字id
302
+ # @option options [String] :status
303
+ # 收藏状态: 选填(想读:wish 在读:reading 读过:read)默认为所有状态
304
+ # @option options [String] :tag
305
+ # 收藏标签: 选填
306
+ # @option options [String] :from
307
+ # 收藏更新时间过滤的起始时间
308
+ # 选填,格式为符合rfc3339的字符串,例如"2012-10-19T17:14:11",其他信息默认为不传此项
309
+ # @option options [String] :to
310
+ # 收藏更新时间过滤的结束时间:同上
311
+ # @option options [Integer] :rating
312
+ # 星评: 选填,数字1~5为合法值,其他信息默认为不区分星评
313
+ # @return [Array<Hashie::Mash>] 该用户的图书收藏列表
314
+ # @example 获取ahbei的所有图书收藏
315
+ # Douban.books('ahbei')
316
+ # @example 获取已认证用户的所有图书收藏
317
+ # client.books()
318
+ # TODO 可以允许options[:from]和options[:to]传入ruby日期对象
319
+ def books(name=nil, options={})
320
+ if user_id.nil?
321
+ response = get("v2/book/user/#{get_user_id}/collections", options)
322
+ else
323
+ response = get("v2/book/user/#{name}/collections", options)
324
+ end
325
+
326
+ response["collections"]
327
+ end
328
+
329
+ # 获取某个用户的所有图书收藏信息
330
+ #
331
+ # @scope book_basic_w
332
+ # @see http://developers.douban.com/wiki/?title=book_v2#post_book_collection
333
+ # @authenticated true
334
+ # @param id [String] 图书的id
335
+ # @param status [String] 收藏状态(想读:wish 在读:reading 读过:read)
336
+ # @option options [String] :tag
337
+ # 收藏标签字符串: 选填,用空格分隔
338
+ # @option options [String] :comment
339
+ # 短评文本: 选填,最多350字
340
+ # @option options [String] :privacy
341
+ # 隐私设置: 选填,值为'private'为设置成仅自己可见,其他默认为公开
342
+ # @option options [Integer] :rating
343
+ # 星评: 选填,数字1~5为合法值,其他信息默认为不区分星评
344
+ # @return [Hashie::Mash] 返回创建的图书收藏信息
345
+ # @example 想读id为3821057的图书,并标记标签
346
+ # client.create_book_collection('3821057', 'wish', {
347
+ # :tag => "小说 美国 文学"
348
+ # })
349
+ def create_book_collection(id, status, options={})
350
+ post "v2/book/#{id}/collection", options.merge(:status => status)
351
+ end
352
+
353
+ # 获取某个用户的所有图书收藏信息
354
+ #
355
+ # @scope book_basic_w
356
+ # @see http://developers.douban.com/wiki/?title=book_v2#put_book_collection
357
+ # @authenticated true
358
+ # @param id [String] 图书的id
359
+ # @param status [String] 收藏状态(想读:wish 在读:reading 读过:read)
360
+ # @option options [String] :tag
361
+ # 收藏标签字符串: 选填,用空格分隔
362
+ # @option options [String] :comment
363
+ # 短评文本: 选填,最多350字
364
+ # @option options [String] :privacy
365
+ # 隐私设置: 选填,值为'private'为设置成仅自己可见,其他默认为公开
366
+ # @option options [Integer] :rating
367
+ # 星评: 选填,数字1~5为合法值,其他信息默认为不区分星评
368
+ # @return [Hashie::Mash] 返回创建的图书收藏信息
369
+ # @example 度过id为3821057的图书,并标记为5星
370
+ # client.change_book_collection('3821057', 'read', {
371
+ # :rating => 5
372
+ # :tag => "小说 美国 文学"
373
+ # })
374
+ def change_book_collection(id, status, options={})
375
+ post "v2/book/#{id}/collection", options.merge(:status => status)
376
+ end
377
+
378
+ # 用户删除某篇笔记
379
+ #
380
+ # @scope book_basic_w
381
+ # @see http://developers.douban.com/wiki/?title=book_v2#delete_book_collection
382
+ # @authenticated true
383
+ # @param id [String] 图书的id
384
+ # @return [Boolean] 删除成功则返回true, 否则false
385
+ # @example 删除用户对id为3821057的图书收藏
386
+ # client.remove_book_collection('3821057')
387
+ def remove_book_collection(id)
388
+ begin
389
+ delete "v2/book/#{id}/collection"
390
+ return true
391
+ rescue Douban::NotFound
392
+ return false
393
+ end
394
+ end
395
+ end
396
+ end
397
+ end
@@ -0,0 +1,33 @@
1
+ module Douban
2
+ class Client
3
+ # 回复Api V2
4
+ # @see http://developers.douban.com/wiki/?title=comment_v2
5
+ module Comment
6
+ private
7
+ # 获取回复列表
8
+ # @see http://developers.douban.com/wiki/?title=comment_v2#list
9
+ def comments(target, id, options={})
10
+ response = get("v2/#{target}/#{id}/comments", options)
11
+ response["comments"]
12
+ end
13
+
14
+ # 新发讨论
15
+ # @see http://developers.douban.com/wiki/?title=comment_v2#new
16
+ def create_comment(target, id, content)
17
+ post "v2/#{target}/#{id}/comments", {:content => content}
18
+ end
19
+
20
+ # 获取单条回复
21
+ # @see http://developers.douban.com/wiki/?title=comment_v2#get
22
+ def comment(target, target_id, comment_id)
23
+ get "v2/#{target}/#{target_id}/comment/#{comment_id}"
24
+ end
25
+
26
+ # 删除回复
27
+ # @see http://developers.douban.com/wiki/?title=comment_v2#delete
28
+ def remove_comment(target, target_id, comment_id)
29
+ delete("v2/#{target}/#{target_id}/comment/#{comment_id}")[:status] == 200
30
+ end
31
+ end
32
+ end
33
+ end