Module: Douban::Client::Book
- Included in:
- Douban::Client
- Defined in:
- lib/douban_api/client/book.rb
Overview
图书Api V2
Instance Method Summary collapse
-
#annotation(id, options = {}) ⇒ Hashie::Mash
获取某篇笔记的信息.
-
#book(id) ⇒ Hashie::Mash
获取图书信息.
-
#book_annotations(id, options = {}) ⇒ Array<Hashie::Mash>
获取某本图书的所有笔记.
-
#book_tags(id, optins = {}) ⇒ Array<Hashie::Mash>
某个图书中标记最多的标签, 最多返回前50个tag.
-
#books(name = nil, options = {}) ⇒ Array<Hashie::Mash>
获取某个用户的所有图书收藏信息.
-
#change_book_collection(id, status, options = {}) ⇒ Hashie::Mash
获取某个用户的所有图书收藏信息.
-
#create_book_annotation(id, options = {}) ⇒ Hashie::Mash
用户给某本图书写笔记.
-
#create_book_collection(id, status, options = {}) ⇒ Hashie::Mash
获取某个用户的所有图书收藏信息.
-
#create_book_review(id, options = {}) ⇒ Hashie::Mash
发表新评论.
-
#edit_book_annotation(id, options = {}) ⇒ Hashie::Mash
用户修改某篇笔记.
-
#edit_book_review(id, options = {}) ⇒ Hashie::Mash
修改评论.
-
#isbn(id) ⇒ Hashie::Mash
根据isbn获取图书信息.
-
#remove_book_annotation(id) ⇒ Boolean
用户删除某篇笔记.
-
#remove_book_collection(id) ⇒ Boolean
用户删除某篇笔记.
-
#remove_book_review(id) ⇒ Boolean
删除评论.
-
#search_books(q, options = {}) ⇒ Hashie::Mash
通过关键字搜索图书.
-
#search_books_by_tag(tag, options = {}) ⇒ Array<Hashie::Mash>
通过tag搜索图书.
-
#user_book(id) ⇒ Hashie::Mash
获取用户对某本图书的收藏信息.
-
#user_book_annotations(name = nil, options = {}) ⇒ Array<Hashie::Mash>
获取某个用户的所有笔记.
-
#user_book_tags(name = nil, options = {}) ⇒ Array<Hashie::Mash>
获取用户对图书的所有标签.
Instance Method Details
#annotation(id, options = {}) ⇒ Hashie::Mash
获取某篇笔记的信息
170 171 172 |
# File 'lib/douban_api/client/book.rb', line 170 def annotation(id, ={}) response = get "v2/book/annotation/#{id}", end |
#book(id) ⇒ Hashie::Mash
获取图书信息
17 18 19 |
# File 'lib/douban_api/client/book.rb', line 17 def book(id) response = get "v2/book/#{id}" end |
#book_annotations(id, options = {}) ⇒ Array<Hashie::Mash>
获取某本图书的所有笔记
190 191 192 193 |
# File 'lib/douban_api/client/book.rb', line 190 def book_annotations(id, ={}) response = get "v2/book/#{id}/annotations" response["annotations"] end |
#book_tags(id, optins = {}) ⇒ Array<Hashie::Mash>
某个图书中标记最多的标签, 最多返回前50个tag
71 72 73 74 |
# File 'lib/douban_api/client/book.rb', line 71 def (id, optins={}) response = get "v2/book/#{id}/tags", responses["tags"] end |
#books(name = nil, options = {}) ⇒ Array<Hashie::Mash>
获取某个用户的所有图书收藏信息
TODO 可以允许options和options传入ruby日期对象
320 321 322 323 324 325 326 327 328 |
# File 'lib/douban_api/client/book.rb', line 320 def books(name=nil, ={}) if name.nil? response = get("v2/book/user/#{get_user_id}/collections", ) else response = get("v2/book/user/#{name}/collections", ) end response["collections"] end |
#change_book_collection(id, status, options = {}) ⇒ Hashie::Mash
获取某个用户的所有图书收藏信息
375 376 377 |
# File 'lib/douban_api/client/book.rb', line 375 def change_book_collection(id, status, ={}) post "v2/book/#{id}/collection", .merge(:status => status) end |
#create_book_annotation(id, options = {}) ⇒ Hashie::Mash
用户给某本图书写笔记
TODO 支持图片
216 217 218 |
# File 'lib/douban_api/client/book.rb', line 216 def create_book_annotation(id, ={}) post "v2/book/reviews", end |
#create_book_collection(id, status, options = {}) ⇒ Hashie::Mash
获取某个用户的所有图书收藏信息
350 351 352 |
# File 'lib/douban_api/client/book.rb', line 350 def create_book_collection(id, status, ={}) post "v2/book/#{id}/collection", .merge(:status => status) end |
#create_book_review(id, options = {}) ⇒ Hashie::Mash
发表新评论
115 116 117 |
# File 'lib/douban_api/client/book.rb', line 115 def create_book_review(id, ={}) post "v2/book/reviews", .merge(:book => id) end |
#edit_book_annotation(id, options = {}) ⇒ Hashie::Mash
用户修改某篇笔记
TODO 支持图片
241 242 243 |
# File 'lib/douban_api/client/book.rb', line 241 def edit_book_annotation(id, ={}) put "v2/book/annotation/#{id}", end |
#edit_book_review(id, options = {}) ⇒ Hashie::Mash
修改评论
137 138 139 |
# File 'lib/douban_api/client/book.rb', line 137 def edit_book_review(id, ={}) put "v2/book/reviews/#{id}", end |
#isbn(id) ⇒ Hashie::Mash
根据isbn获取图书信息
30 31 32 |
# File 'lib/douban_api/client/book.rb', line 30 def isbn(id) response = get "v2/book/isbn/#{id}" end |
#remove_book_annotation(id) ⇒ Boolean
用户删除某篇笔记
254 255 256 257 258 259 260 261 |
# File 'lib/douban_api/client/book.rb', line 254 def remove_book_annotation(id) begin delete "v2/book/annotation/#{id}" return true rescue Douban::NotFound return false end end |
#remove_book_collection(id) ⇒ Boolean
用户删除某篇笔记
388 389 390 391 392 393 394 395 |
# File 'lib/douban_api/client/book.rb', line 388 def remove_book_collection(id) begin delete "v2/book/#{id}/collection" return true rescue Douban::NotFound return false end end |
#remove_book_review(id) ⇒ Boolean
删除评论
150 151 152 153 154 155 156 157 |
# File 'lib/douban_api/client/book.rb', line 150 def remove_book_review(id) begin delete "v2/book/review/#{id}" return true rescue Douban::NotFound return false end end |
#search_books(q, options = {}) ⇒ Hashie::Mash
通过关键字搜索图书
43 44 45 46 |
# File 'lib/douban_api/client/book.rb', line 43 def search_books(q, ={}) response = get "v2/book/search", .merge(:q => q) response["books"] end |
#search_books_by_tag(tag, options = {}) ⇒ Array<Hashie::Mash>
通过tag搜索图书
57 58 59 60 |
# File 'lib/douban_api/client/book.rb', line 57 def search_books_by_tag(tag, ={}) response = get "v2/book/search", .merge(:tag => tag) response["books"] end |
#user_book(id) ⇒ Hashie::Mash
获取用户对某本图书的收藏信息
293 294 295 |
# File 'lib/douban_api/client/book.rb', line 293 def user_book(id) response = get "v2/book/#{id}/collection" end |
#user_book_annotations(name = nil, options = {}) ⇒ Array<Hashie::Mash>
获取某个用户的所有笔记
274 275 276 277 278 279 280 281 282 |
# File 'lib/douban_api/client/book.rb', line 274 def user_book_annotations(name=nil, ={}) if name.nil? response = get("v2/book/user/#{get_user_id}/annotations", ) else response = get("v2/book/user/#{name}/annotations", ) end response["annotations"] end |
#user_book_tags(name = nil, options = {}) ⇒ Array<Hashie::Mash>
获取用户对图书的所有标签
87 88 89 90 91 92 93 94 95 |
# File 'lib/douban_api/client/book.rb', line 87 def (name=nil, ={}) if name.nil? response = get("v2/book/user/#{get_user_id}/tags", ) else response = get("v2/book/user/#{name}/tags", ) end response["tags"] end |