Class: Douban::Authorize
- Inherits:
-
Object
- Object
- Douban::Authorize
- Defined in:
- lib/douban/authorize.rb
Constant Summary collapse
- @@debug =
false- @@default_oauth_request_options =
{ :signature_method=>"HMAC-SHA1", :site=>"http://www.douban.com", :request_token_path=>"/service/auth/request_token", :access_token_path=>"/service/auth/access_token", :authorize_path=>"/service/auth/authorize", :scheme=>:header, :realm=>"http://www.example.com/" }
- @@default_oauth_access_options =
{ :site=>"http://api.douban.com", :scheme=>:header, :signature_method=>"HMAC-SHA1", :realm=>"http://www.example.com/" }
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#authorize_url ⇒ Object
readonly
Returns the value of attribute authorize_url.
-
#consumer ⇒ Object
readonly
Returns the value of attribute consumer.
Class Method Summary collapse
Instance Method Summary collapse
-
#access_token(arg = nil) ⇒ Object
:call-seq: access_token => OAuth::AccessToken access_token :as_token => OAuth::Token access_token :as_hash => Hash.
- #access_token=(token) ⇒ Object
- #auth ⇒ Object
- #authorized? ⇒ Boolean
- #create_collection(subject_id = "", content = "", rating = 5, status = "", tag = [], option = { :privacy=>"public"}) ⇒ Object
- #create_event(title = "", content = "", where = "", option = {:kind=>"party",:invite_only=>"no",:can_invite=>"yes",:when=>{"endTime"=>(Time.now+60*60*24*5).strftime("%Y-%m-%dT%H:%M:%S+08:00"),"startTime"=>Time.now.strftime("%Y-%m-%dT%H:%M:%S+08:00")}}) ⇒ Object
-
#create_mail(*args) ⇒ Object
DEPRECATED: Please use
send_mailinstead. - #create_miniblog(content = "") ⇒ Object
-
#create_miniblog_comment(miniblog, content) ⇒ Object
:call-seq: create_miniblog_comment(aMiniblog, aString) => MiniblogComment or nil create_miniblog_comment(obj, aString) => MiniblogComment or nil.
- #create_note(title = "", content = "", option = {:privacy=>"public",:can_reply=>"yes"}) ⇒ Object
- #create_recommendation(subject, title, comment) ⇒ Object
- #create_recommendation_comment(recommendation, content) ⇒ Object
- #create_review(subject_link = "", title = "", content = "", rating = 5) ⇒ Object
- #delete_collection(collection) ⇒ Object
- #delete_event(event_id = "") ⇒ Object
- #delete_mail(mail_id = "") ⇒ Object
- #delete_mails(mail_ids = []) ⇒ Object
- #delete_miniblog(miniblog_id = "") ⇒ Object
-
#delete_miniblog_comment(*args) ⇒ Object
:call-seq: delete_miniblog_comment(aMiniblogComment) => true or false delete_miniblog_comment(miniblog_id, comment_id) => true or false 删除我说.
- #delete_note(note_id = "") ⇒ Object
- #delete_recommendation(recommendation_id) ⇒ Object
-
#delete_recommendation_comment(recommendation, comment_id = nil) ⇒ Object
delete_recommendation_comment(comment:RecommendationComment) delete_recommendation_comment(recommendation:Recommendation, comment_id:Integer) delete_recommendation_comment(recommendation_id:Integer, comment_id:Integer).
- #delete_review(review) ⇒ Object
-
#delete_token ⇒ Object
(also: #logout)
注销一个Access Token goo.gl/0JAB.
- #get_authorize_url(oauth_callback = nil) {|@request_token| ... } ⇒ Object
-
#get_book(id) ⇒ Object
获取书籍信息 goo.gl/HaG5.
- #get_book_reviews(subject_id = "", option = {:start_index=>1,:max_results=>10,:orderby=>'score'}) ⇒ Object
- #get_book_tags(subject_id = "", flag = :book) ⇒ Object
- #get_city_events(location_id = nil, option = {:type=>"all",:start_index=>1,:max_results=>10}) ⇒ Object
- #get_collection(collection_id = "") ⇒ Object
- #get_contacts(uid = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_event(event_id = "") ⇒ Object
- #get_event_participant_people(event_id = nil, option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_event_wisher_people(event_id = nil, option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_friends(uid = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_mail(mail_id = "", keep_unread = "false") ⇒ Object
- #get_mail_inbox(option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_mail_outbox(option = {:start_index=>1,:max_results=>10}) ⇒ Object
-
#get_miniblog_comments(miniblog, options = {}) ⇒ Object
:call-seq: get_miniblog_comments(aMiniblog, options) => MiniblogComments or nil get_miniblog_comments(miniblog_id, options) => MiniblogComments or nil.
-
#get_movie(id) ⇒ Object
获取电影信息 goo.gl/2fZ4.
- #get_movie_reviews(subject_id = "", option = {:start_index=>1,:max_results=>10,:orderby=>'score'}) ⇒ Object
- #get_music(id = nil) ⇒ Object
- #get_music_reviews(subject_id = "", option = {:start_index=>1,:max_results=>10,:orderby=>'score'}) ⇒ Object
- #get_note(note_id = "") ⇒ Object
-
#get_participant_people(*args) ⇒ Object
DEPRECATED: Please use
get_event_participant_peopleinstead. - #get_people(uid = "@me") ⇒ Object
- #get_recommendation(id) ⇒ Object
- #get_recommendation_comments(recommendation_id) ⇒ Object
- #get_review(id = "") ⇒ Object
- #get_unread_mail(option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_user_collection(user_id = "@me", option = { :cat=>'', :tag=>'', :status=>'', :start_index=>1, :max_results=>10, :updated_max=>'', :updated_min=>'' }) ⇒ Object
- #get_user_contact_miniblog(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_user_events(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_user_initiate_events(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_user_miniblog(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_user_notes(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_user_participate_events(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_user_recommendations(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #get_user_reviews(user_id = "@me", option = {:start_index=>1,:max_results=>10,:orderby=>'score'}) ⇒ Object
- #get_user_tags(user_id = "@me", flag = :book, option = {:max_results=>10}) ⇒ Object
- #get_user_wish_events(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
-
#get_wisher_people(*args) ⇒ Object
DEPRECATED: Please use
get_event_wisher_peopleinstead. -
#initialize(api_key, secret_key, options = {}) {|_self| ... } ⇒ Authorize
constructor
A new instance of Authorize.
- #modify_collection(collection, subject_id = "", content = "", rating = 5, status = "", tag = [], option = {:privacy=>"public"}) ⇒ Object
- #modify_event(event, title = nil, content = nil, where = nil, option = nil) ⇒ Object
- #modify_note(note, title = "", content = "", option = {:privacy=>"public",:can_reply=>"yes"}) ⇒ Object
- #modify_review(review, subject_link = nil, title = "", content = "", rating = 5) ⇒ Object
- #read_mail(mail_id = "") ⇒ Object
- #read_mails(mail_ids = []) ⇒ Object
-
#request_token(arg = nil) ⇒ Object
:call-seq: request_token => OAuth::RequestToken request_token :as_token => OAuth::Token request_token :as_hash => Hash.
- #request_token=(token) ⇒ Object
-
#search_book(*args) ⇒ Object
:call-seq: search_book(:q => “search word”) => [Book] or nil search_book(:tag => “tag name”) => [Book] or nil search_book(“search word”) => [Book] or nil.
- #search_events(q = "", option = {:location=>"all",:start_index=>1,:max_results=>10}) ⇒ Object
- #search_movie(*args) ⇒ Object
- #search_music(tag = "", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #search_people(q = "", option = {:start_index=>1,:max_results=>10}) ⇒ Object
- #send_mail(id = "", title = "", content = "", captcha_token = "", captcha_string = "") ⇒ Object
-
#verify_token ⇒ Object
验证Access Token是否可用 goo.gl/8v8d.
Constructor Details
#initialize(api_key, secret_key, options = {}) {|_self| ... } ⇒ Authorize
Returns a new instance of Authorize.
51 52 53 54 55 56 57 58 |
# File 'lib/douban/authorize.rb', line 51 def initialize(api_key, secret_key, ={}) @api_key=api_key @secret_key=secret_key @oauth_request_option = @@default_oauth_request_options.merge() @oauth_access_option = @@default_oauth_access_options.merge() yield self if block_given? self end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
22 23 24 |
# File 'lib/douban/authorize.rb', line 22 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
23 24 25 |
# File 'lib/douban/authorize.rb', line 23 def api_secret @api_secret end |
#authorize_url ⇒ Object (readonly)
Returns the value of attribute authorize_url.
24 25 26 |
# File 'lib/douban/authorize.rb', line 24 def @authorize_url end |
#consumer ⇒ Object (readonly)
Returns the value of attribute consumer.
25 26 27 |
# File 'lib/douban/authorize.rb', line 25 def consumer @consumer end |
Class Method Details
.debug=(val) ⇒ Object
47 48 49 |
# File 'lib/douban/authorize.rb', line 47 def self.debug=(val) @@debug = val end |
Instance Method Details
#access_token(arg = nil) ⇒ Object
:call-seq:
access_token => OAuth::AccessToken
access_token :as_token => OAuth::Token
access_token :as_hash => Hash
if you want to serialize access_token, use :as_token or :as_hash
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 |
# File 'lib/douban/authorize.rb', line 1180 def access_token(arg=nil) if arg.nil? @access_token elsif arg == :as_token @access_token.nil? ? nil : OAuth::Token.new(@access_token.token, @access_token.secret) elsif arg == :as_hash @access_token.nil? ? nil : {:token => @access_token.token, :secret => @access_token.secret} else raise ArgumentError end end |
#access_token=(token) ⇒ Object
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 |
# File 'lib/douban/authorize.rb', line 1155 def access_token=(token) case token when OAuth::AccessToken @access_token = token when OAuth::Token @access_token = OAuth::AccessToken.new( new_access_consumer, token.token, token.secret) when Hash @access_token = OAuth::AccessToken.new( new_access_consumer, token[:token], token[:secret]) else raise ArgumentError end end |
#auth ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/douban/authorize.rb', line 74 def auth begin @access_token=@request_token.get_access_token @access_token=OAuth::AccessToken.new(new_access_consumer, @access_token.token, @access_token.secret ) rescue #raise $! ensure yield self if block_given? return self end end |
#authorized? ⇒ Boolean
60 61 62 |
# File 'lib/douban/authorize.rb', line 60 def ! @access_token.nil? end |
#create_collection(subject_id = "", content = "", rating = 5, status = "", tag = [], option = { :privacy=>"public"}) ⇒ Object
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/douban/authorize.rb', line 447 def create_collection( subject_id="",content="",=5,status="",tag=[],option={ :privacy=>"public"}) db_tag="" if tag.size==0 db_tag='<db:tag name="" />' else tag.each do |t| db_tag+=%Q{<db:tag name="#{h t}" />} end end entry=%Q{<?xml version='1.0' encoding='UTF-8'?> <entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/"> <db:status>#{h status}</db:status> #{db_tag} <gd:rating xmlns:gd="http://schemas.google.com/g/2005" value="#{h }" /> <content>#{h content}</content> <db:subject> <id>#{h subject_id}</id> </db:subject> <db:attribute name="privacy">#{h option[:privacy]}</db:attribute> </entry> } resp=post("/collection",entry,{"Content-Type"=>"application/atom+xml"}) if resp.code=="201" Collection.new(resp.body) else debug(resp) end end |
#create_event(title = "", content = "", where = "", option = {:kind=>"party",:invite_only=>"no",:can_invite=>"yes",:when=>{"endTime"=>(Time.now+60*60*24*5).strftime("%Y-%m-%dT%H:%M:%S+08:00"),"startTime"=>Time.now.strftime("%Y-%m-%dT%H:%M:%S+08:00")}}) ⇒ Object
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/douban/authorize.rb', line 871 def create_event(title="",content="",where="",option={:kind=>"party",:invite_only=>"no",:can_invite=>"yes",:when=>{"endTime"=>(Time.now+60*60*24*5).strftime("%Y-%m-%dT%H:%M:%S+08:00"),"startTime"=>Time.now.strftime("%Y-%m-%dT%H:%M:%S+08:00")}}) entry=%Q{<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/"> <title>#{h title}</title> <category scheme="http://www.douban.com/2007#kind" term="http://www.douban.com/2007#event.#{option[:kind]}"/> <content>#{h content}</content> <db:attribute name="invite_only">#{h option[:invite_only]}</db:attribute> <db:attribute name="can_invite">#{h option[:can_invite]}</db:attribute> <gd:when endTime="#{h option[:when]["endTime"]}" startTime="#{h option[:when]["startTime"]}"/> <gd:where valueString="#{h where}" /> </entry> } resp=post("/events",entry,{"Content-Type"=>"application/atom+xml"}) if resp.code=="201" Event.new(resp.body) else debug(resp) end end |
#create_mail(*args) ⇒ Object
DEPRECATED: Please use send_mail instead.
977 978 979 980 |
# File 'lib/douban/authorize.rb', line 977 def create_mail(*args) warn "[DEPRECATION] `create_mail` is deprecated. Please use `send_mail` instead." send_mail(*args) end |
#create_miniblog(content = "") ⇒ Object
561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'lib/douban/authorize.rb', line 561 def create_miniblog(content="") entry=%Q{<?xml version='1.0' encoding='UTF-8'?> <entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/"> <content>#{h content}</content> </entry>} resp=post("/miniblog/saying",entry,{"Content-Type"=>"application/atom+xml"}) if resp.code=="201" Miniblog.new(resp.body) else nil end end |
#create_miniblog_comment(miniblog, content) ⇒ Object
:call-seq:
create_miniblog_comment(aMiniblog, aString) => MiniblogComment or nil
create_miniblog_comment(obj, aString) => MiniblogComment or nil
回应我说 (goo.gl/j43Z)
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# File 'lib/douban/authorize.rb', line 616 def create_miniblog_comment(miniblog, content) miniblog_id = case miniblog when Miniblog then miniblog.miniblog_id else miniblog end entry = %Q{<?xml version='1.0' encoding='UTF-8'?> <entry> <content>#{h content}</content> </entry>} resp = post("/miniblog/#{u miniblog_id}/comments", entry) if resp.code == "201" MiniblogComment.new(resp.body) else debug(resp) end end |
#create_note(title = "", content = "", option = {:privacy=>"public",:can_reply=>"yes"}) ⇒ Object
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 |
# File 'lib/douban/authorize.rb', line 686 def create_note(title="",content="",option={:privacy=>"public",:can_reply=>"yes"}) entry=%Q{<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/"> <title>#{h title}</title> <content>#{h content}</content> <db:attribute name="privacy">#{h option[:privacy]}</db:attribute> <db:attribute name="can_reply">#{h option[:can_reply]}</db:attribute> </entry> } resp=post("/notes",entry,{"Content-Type"=>"application/atom+xml"}) if resp.code=="201" Note.new(resp.body) else debug(resp) end end |
#create_recommendation(subject, title, comment) ⇒ Object
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 |
# File 'lib/douban/authorize.rb', line 1234 def create_recommendation(subject, title, comment) subject = subject.kind_of?(Douban::Subject) ? subject.id : subject entry = %Q{<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:db="http://www.douban.com/xmlns/"> <title>#{h title}</title> <db:attribute name="comment">#{h comment}</db:attribute> <link href="#{h subject}" rel="related" /> </entry>} resp = post("/recommendations", entry, {"Content-Type"=>"application/atom+xml"}) if resp.code == '201' Recommendation.new(resp.body) else debug(resp) end end |
#create_recommendation_comment(recommendation, content) ⇒ Object
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 |
# File 'lib/douban/authorize.rb', line 1266 def create_recommendation_comment(recommendation, content) recommendation_id = recommendation.kind_of?(Douban::Recommendation) \ ? recommendation.recommendation_id : recommendation entry = %Q{<?xml version='1.0' encoding='UTF-8'?> <entry> <content>#{h content}</content> </entry>} resp = post("/recommendation/#{u recommendation_id}/comments", entry, {"Content-Type"=>"application/atom+xml"}) if resp.code == '201' RecommendationComment.new(resp.body) else debug(resp) end end |
#create_review(subject_link = "", title = "", content = "", rating = 5) ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/douban/authorize.rb', line 359 def create_review(subject_link="",title="",content="",=5) subject_link = subject_link.id if subject_link.kind_of?(Subject) entry=%Q{<?xml version='1.0' encoding='UTF-8'?> <entry xmlns:ns0="http://www.w3.org/2005/Atom"> <db:subject xmlns:db="http://www.douban.com/xmlns/"> <id>#{h subject_link}</id> </db:subject> <content>#{h content}</content> <gd:rating xmlns:gd="http://schemas.google.com/g/2005" value="#{h }" ></gd:rating> <title>#{h title}</title> </entry> } resp=post("/reviews",entry,{"Content-Type" => "application/atom+xml"}) if resp.code=="201" Review.new(resp.body) else debug(resp) end end |
#delete_collection(collection) ⇒ Object
515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/douban/authorize.rb', line 515 def delete_collection(collection) collection_id = case collection when Collection then collection.collection_id else collection end resp=delete("/collection/#{u(collection_id.to_s)}") if resp.code=="200" true else false end end |
#delete_event(event_id = "") ⇒ Object
1101 1102 1103 1104 1105 1106 1107 1108 1109 |
# File 'lib/douban/authorize.rb', line 1101 def delete_event(event_id="") entry=%Q{<?xml version='1.0' encoding='UTF-8'?><entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/"><content>sorry!!!</content></entry>} resp=post("/event/#{u(event_id)}/delete",entry,{"Content-Type"=>"application/atom+xml"}) if resp.code=="200" true else debug(resp, false) end end |
#delete_mail(mail_id = "") ⇒ Object
1023 1024 1025 1026 1027 1028 1029 1030 |
# File 'lib/douban/authorize.rb', line 1023 def delete_mail(mail_id="") resp=delete("/doumail/#{mail_id.to_s}") if resp.code=="200" true else false end end |
#delete_mails(mail_ids = []) ⇒ Object
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 |
# File 'lib/douban/authorize.rb', line 1044 def delete_mails(mail_ids=[]) entrys="" mail_ids.each do |mail_id| entrys += %Q{<entry><id>http://api.douban.com/doumail/#{mail_id}</id></entry>} end feed=%Q{<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/">#{entrys}</feed>} resp=post("/doumail/delete",feed,{"Content-Type" => "application/atom+xml"}) if resp.code=="202" true else false end end |
#delete_miniblog(miniblog_id = "") ⇒ Object
573 574 575 576 577 578 579 580 |
# File 'lib/douban/authorize.rb', line 573 def delete_miniblog(miniblog_id="") resp=delete("/miniblog/#{u(miniblog_id.to_s)}") if resp.code=="200" true else false end end |
#delete_miniblog_comment(*args) ⇒ Object
:call-seq:
delete_miniblog_comment(aMiniblogComment) => true or false
delete_miniblog_comment(miniblog_id, comment_id) => true or false
删除我说
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/douban/authorize.rb', line 638 def delete_miniblog_comment(*args) if args.size == 1 and args[0].kind_of?(MiniblogComment) miniblog_id = args[0].miniblog_id comment_id = args[0].comment_id elsif args.size == 2 miniblog_id = args[0].to_s comment_id = args[1].to_s else raise "unsupported argument error" end resp = delete("/miniblog/#{u miniblog_id}/comment/#{u comment_id}") if resp.code == "200" true else debug(resp, false) end end |
#delete_note(note_id = "") ⇒ Object
703 704 705 706 707 708 709 710 711 712 |
# File 'lib/douban/authorize.rb', line 703 def delete_note(note_id="") note_id = note_id.note_id if note_id.kind_of?(Note) resp=delete("/note/#{u(note_id.to_s)}") if resp.code=="200" true else false end end |
#delete_recommendation(recommendation_id) ⇒ Object
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 |
# File 'lib/douban/authorize.rb', line 1253 def delete_recommendation(recommendation_id) if recommendation_id.kind_of?(Douban::Recommendation) recommendation_id = %r{/(\d+)$}.match(recommendation_id.id)[1] end resp = delete("/recommendation/#{u recommendation_id}") if resp.code == '200' true else debug(resp, false) end end |
#delete_recommendation_comment(recommendation, comment_id = nil) ⇒ Object
delete_recommendation_comment(comment:RecommendationComment) delete_recommendation_comment(recommendation:Recommendation, comment_id:Integer) delete_recommendation_comment(recommendation_id:Integer, comment_id:Integer)
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 |
# File 'lib/douban/authorize.rb', line 1284 def delete_recommendation_comment(recommendation, comment_id=nil) if comment_id.nil? recommendation_id = recommendation.recommendation_id comment_id = recommendation.comment_id else recommendation_id = recommendation.kind_of?(Douban::Recommendation) \ ? recommendation.recommendation_id : recommendation end resp = delete("/recommendation/#{u recommendation_id}/comment/#{u comment_id}") if resp.code == '200' true else debug(resp, false) end end |
#delete_review(review) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/douban/authorize.rb', line 345 def delete_review(review) review_id = case review when Review then review.review_id else review end resp=delete("/review/#{u(review_id.to_s)}") if resp.code=="200" true else false end end |
#delete_token ⇒ Object Also known as: logout
注销一个Access Token goo.gl/0JAB
1315 1316 1317 1318 1319 1320 1321 1322 |
# File 'lib/douban/authorize.rb', line 1315 def delete_token resp = delete("/access_token/#{@access_token.token}") if resp.code == "200" true else debug(resp, false) end end |
#get_authorize_url(oauth_callback = nil) {|@request_token| ... } ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/douban/authorize.rb', line 64 def (oauth_callback=nil) oauth_callback ||= @oauth_request_option[:realm] @consumer=new_request_consumer @request_token=@consumer.get_request_token @authorize_url="#{@request_token.}&oauth_callback=#{CGI.escape(oauth_callback)}" yield @request_token if block_given? @authorize_url end |
#get_book(id) ⇒ Object
获取书籍信息goo.gl/HaG5
get_book(:isbn => isbn) => Book get_book(:id => id) => Book get_book(id) => Book get_book(Book) => Book (refresh Book)
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/douban/authorize.rb', line 151 def get_book(id) resp = case id when Book get("/book/subject/#{u id.subject_id}") when Hash if id[:isbn] get("/book/subject/isbn/#{u id[:isbn]}") elsif id[:id] get("/book/subject/#{u id[:id]}") else raise "Hash only support :isbn or :id" end else get("/book/subject/#{u id}") end if resp.code=="200" atom=resp.body Book.new(atom) else nil end end |
#get_book_reviews(subject_id = "", option = {:start_index=>1,:max_results=>10,:orderby=>'score'}) ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/douban/authorize.rb', line 330 def get_book_reviews(subject_id="",option={:start_index=>1,:max_results=>10,:orderby=>'score'}) resp=get("/book/subject/#{u(subject_id.to_s)}/reviews?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}&orderby=#{option[:orderby]}") if resp.code=="200" atom=resp.body reviews=[] doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| reviews<< Review.new(entry) end reviews else nil end end |
#get_book_tags(subject_id = "", flag = :book) ⇒ Object
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 |
# File 'lib/douban/authorize.rb', line 1058 def (subject_id="",flag=:book) case flag when :book resp=get("/book/subject/#{subject_id}/tags") when :music resp=get("/music/subject/#{subject_id}/tags") when :movie resp=get("/movie/subject/#{subject_id}/tags") end if resp.code=="200" =[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| << Tag.new(entry) end else nil end end |
#get_city_events(location_id = nil, option = {:type=>"all",:start_index=>1,:max_results=>10}) ⇒ Object
843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
# File 'lib/douban/authorize.rb', line 843 def get_city_events(location_id=nil,option={:type=>"all",:start_index=>1,:max_results=>10}) resp=get("/event/location/#{u(location_id.to_s)}?type=#{option[:type]}&start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" events=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//feed/entry") do |entry| events<< Event.new(entry) end events else nil end end |
#get_collection(collection_id = "") ⇒ Object
406 407 408 409 410 411 412 413 414 |
# File 'lib/douban/authorize.rb', line 406 def get_collection(collection_id="") resp=get("/collection/#{u(collection_id.to_s)}") if resp.code=="200" atom=resp.body Collection.new(atom) else nil end end |
#get_contacts(uid = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/douban/authorize.rb', line 113 def get_contacts(uid="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u uid.to_s}/contacts?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" contacts=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| contacts << People.new(entry) end contacts else nil end end |
#get_event(event_id = "") ⇒ Object
735 736 737 738 739 740 741 742 743 |
# File 'lib/douban/authorize.rb', line 735 def get_event(event_id="") resp=get("/event/#{u(event_id.to_s)}") if resp.code=="200" atom=resp.body Event.new(atom) else nil end end |
#get_event_participant_people(event_id = nil, option = {:start_index=>1,:max_results=>10}) ⇒ Object
751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/douban/authorize.rb', line 751 def get_event_participant_people(event_id=nil,option={:start_index=>1,:max_results=>10}) resp=get("/event/#{u(event_id.to_s)}/participants?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" people=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//feed/entry") do |entry| people<< People.new(entry) end people else nil end end |
#get_event_wisher_people(event_id = nil, option = {:start_index=>1,:max_results=>10}) ⇒ Object
772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/douban/authorize.rb', line 772 def get_event_wisher_people(event_id=nil,option={:start_index=>1,:max_results=>10}) resp=get("/event/#{u(event_id.to_s)}/wishers?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" people=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//feed/entry") do |entry| people<< People.new(entry) end people else nil end end |
#get_friends(uid = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/douban/authorize.rb', line 98 def get_friends(uid="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u uid.to_s}/friends?start-index=#{u option[:start_index]}&max-results=#{u option[:max_results]}") if resp.code=="200" friends=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| friends << People.new(entry) end friends else debug(resp) end end |
#get_mail(mail_id = "", keep_unread = "false") ⇒ Object
966 967 968 969 970 971 972 973 974 |
# File 'lib/douban/authorize.rb', line 966 def get_mail(mail_id="",keep_unread="false") resp=get("/doumail/#{u(mail_id.to_s)}?keep-unread=#{keep_unread}") if resp.code=="200" atom=resp.body Mail.new(atom) else nil end end |
#get_mail_inbox(option = {:start_index=>1,:max_results=>10}) ⇒ Object
924 925 926 927 928 929 930 931 932 933 934 935 936 937 |
# File 'lib/douban/authorize.rb', line 924 def get_mail_inbox(option={:start_index=>1,:max_results=>10}) resp=get("/doumail/inbox?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" mails=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| mails << Mail.new(entry) end mails else nil end end |
#get_mail_outbox(option = {:start_index=>1,:max_results=>10}) ⇒ Object
952 953 954 955 956 957 958 959 960 961 962 963 964 965 |
# File 'lib/douban/authorize.rb', line 952 def get_mail_outbox(option={:start_index=>1,:max_results=>10}) resp=get("/doumail/outbox?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" mails=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| mails << Mail.new(entry) end mails else nil end end |
#get_miniblog_comments(miniblog, options = {}) ⇒ Object
:call-seq:
get_miniblog_comments(aMiniblog, options) => MiniblogComments or nil
get_miniblog_comments(miniblog_id, options) => MiniblogComments or nil
获取我说回复 (goo.gl/nTZK)
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/douban/authorize.rb', line 587 def get_miniblog_comments(miniblog, ={}) miniblog_id = case miniblog when Miniblog then miniblog.miniblog_id else miniblog end url = "/miniblog/#{u miniblog_id}/comments?" if [:start_index] url << "start-index=#{u [:start_index]}&" end if [:max_results] url << "max-results=#{u [:max_results]}&" end url = url[0..-2] resp = get(url) if resp.code == "200" MiniblogComments.new(resp.body) else debug(resp) end end |
#get_movie(id) ⇒ Object
获取电影信息goo.gl/2fZ4
get_movie(:imdb => imdb) => Movie get_movie(:id => id) => Movie get_movie(id) => Movie get_movie(Movie) => Movie (refresh Movie)
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/douban/authorize.rb', line 182 def get_movie(id) resp = case id when Movie get("/movie/subject/#{u id.subject_id}") when Hash if id[:imdb] get("/movie/subject/imdb/#{u id[:imdb]}") elsif id[:id] get("/movie/subject/#{u id[:id]}") else raise "Hash only support :imdb or :id" end else get("/movie/subject/#{u id}") end if resp.code=="200" atom=resp.body Movie.new(atom) else nil end end |
#get_movie_reviews(subject_id = "", option = {:start_index=>1,:max_results=>10,:orderby=>'score'}) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/douban/authorize.rb', line 301 def get_movie_reviews(subject_id="",option={:start_index=>1,:max_results=>10,:orderby=>'score'}) resp=get("/movie/subject/#{u(subject_id.to_s)}/reviews?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}&orderby=#{option[:orderby]}") if resp.code=="200" atom=resp.body reviews=[] doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| reviews<< Review.new(entry) end reviews else nil end end |
#get_music(id = nil) ⇒ Object
205 206 207 208 209 210 211 212 213 |
# File 'lib/douban/authorize.rb', line 205 def get_music(id=nil) resp=get("/music/subject/#{u(id.to_s)}") if resp.code=="200" atom=resp.body Music.new(atom) else nil end end |
#get_music_reviews(subject_id = "", option = {:start_index=>1,:max_results=>10,:orderby=>'score'}) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/douban/authorize.rb', line 316 def get_music_reviews(subject_id="",option={:start_index=>1,:max_results=>10,:orderby=>'score'}) resp=get("/music/subject/#{u(subject_id.to_s)}/reviews?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}&orderby=#{option[:orderby]}") if resp.code=="200" atom=resp.body reviews=[] doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| reviews<< Review.new(entry) end reviews else nil end end |
#get_note(note_id = "") ⇒ Object
657 658 659 660 661 662 663 664 665 |
# File 'lib/douban/authorize.rb', line 657 def get_note(note_id="") resp=get("/note/#{u(note_id.to_s)}") if resp.code=="200" atom=resp.body Note.new(atom) else nil end end |
#get_participant_people(*args) ⇒ Object
DEPRECATED: Please use get_event_participant_people instead.
746 747 748 749 |
# File 'lib/douban/authorize.rb', line 746 def get_participant_people(*args) warn "[DEPRECATION] `get_participant_people` is deprecated. Please use `get_event_participant_people` instead." get_event_participant_people(*args) end |
#get_people(uid = "@me") ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/douban/authorize.rb', line 88 def get_people(uid="@me") resp=get("/people/#{u uid}") if resp.code=="200" atom=resp.body People.new(atom) else debug(resp) end end |
#get_recommendation(id) ⇒ Object
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
# File 'lib/douban/authorize.rb', line 1195 def get_recommendation(id) resp=get("/recommendation/#{u(id.to_s)}") if resp.code=="200" Recommendation.new(resp.body) elsif resp.code == "404" nil else debug(resp) end end |
#get_recommendation_comments(recommendation_id) ⇒ Object
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 |
# File 'lib/douban/authorize.rb', line 1220 def get_recommendation_comments(recommendation_id) resp = get("/recommendation/#{u(recommendation_id)}/comments") if resp.code == "200" comments = [] doc=REXML::Document.new(resp.body) REXML::XPath.each(doc, "//entry") do |entry| comments << RecommendationComment.new(entry) end comments else debug(resp) end end |
#get_review(id = "") ⇒ Object
278 279 280 281 282 283 284 285 286 |
# File 'lib/douban/authorize.rb', line 278 def get_review(id="") resp=get("/review/#{u(id.to_s)}") if resp.code=="200" atom=resp.body Review.new(atom) else nil end end |
#get_unread_mail(option = {:start_index=>1,:max_results=>10}) ⇒ Object
938 939 940 941 942 943 944 945 946 947 948 949 950 951 |
# File 'lib/douban/authorize.rb', line 938 def get_unread_mail(option={:start_index=>1,:max_results=>10}) resp=get("/doumail/inbox/unread?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" mails=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| mails << Mail.new(entry) end mails else nil end end |
#get_user_collection(user_id = "@me", option = { :cat=>'', :tag=>'', :status=>'', :start_index=>1, :max_results=>10, :updated_max=>'', :updated_min=>'' }) ⇒ Object
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/douban/authorize.rb', line 415 def get_user_collection( user_id="@me", option={ :cat=>'', :tag=>'', :status=>'', :start_index=>1, :max_results=>10, :updated_max=>'', :updated_min=>'' } ) resp=get("/people/#{u(user_id.to_s)}/collection?cat=#{option[:cat]}&tag=#{option[:tag]}&status=#{option[:status]}&start-index=#{option[:start_index]}&max-results=#{option[:max_results]}&updated-max=#{option[:updated_max]}&updated-min=#{option[:updated_min]}") if resp.code=="200" atom=resp.body doc=REXML::Document.new(atom) =REXML::XPath.first(doc,"//feed/author") =Author.new(.to_s) if title=REXML::XPath.first(doc,"//feed/title") title=title.text if title collections=[] REXML::XPath.each(doc,"//entry") do |entry| collection=Collection.new(entry) collection.= collection.title=title collections<< collection end collections else nil end end |
#get_user_contact_miniblog(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'lib/douban/authorize.rb', line 546 def get_user_contact_miniblog(user_id="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u(user_id.to_s)}/miniblog/contacts?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" atom=resp.body doc=REXML::Document.new(atom) miniblogs=[] REXML::XPath.each(doc,"//feed/entry") do |entry| miniblog=Miniblog.new(entry) miniblogs<< miniblog end miniblogs else nil end end |
#get_user_events(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
786 787 788 789 790 791 792 793 794 795 796 797 798 799 |
# File 'lib/douban/authorize.rb', line 786 def get_user_events(user_id="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u(user_id.to_s)}/events?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" events=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//feed/entry") do |entry| events<< Event.new(entry) end events else nil end end |
#get_user_initiate_events(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/douban/authorize.rb', line 800 def get_user_initiate_events(user_id="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u(user_id.to_s)}/events/initiate?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" events=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//feed/entry") do |entry| events<< Event.new(entry) end events else nil end end |
#get_user_miniblog(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/douban/authorize.rb', line 528 def get_user_miniblog(user_id="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u(user_id.to_s)}/miniblog?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" atom=resp.body doc=REXML::Document.new(atom) =REXML::XPath.first(doc,"//feed/author") =Author.new(.to_s) if miniblogs=[] REXML::XPath.each(doc,"//feed/entry") do |entry| miniblog=Miniblog.new(entry) miniblog.= miniblogs<< miniblog end miniblogs else nil end end |
#get_user_notes(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'lib/douban/authorize.rb', line 667 def get_user_notes(user_id="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u(user_id.to_s)}/notes?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" atom=resp.body doc=REXML::Document.new(atom) =REXML::XPath.first(doc,"//feed/author") =Author.new(.to_s) if notes=[] REXML::XPath.each(doc,"//feed/entry") do |entry| note=Note.new(entry) note.= notes << note end notes else nil end end |
#get_user_participate_events(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
814 815 816 817 818 819 820 821 822 823 824 825 826 827 |
# File 'lib/douban/authorize.rb', line 814 def get_user_participate_events(user_id="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u(user_id.to_s)}/events/participate?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" events=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//feed/entry") do |entry| events<< Event.new(entry) end events else nil end end |
#get_user_recommendations(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 |
# File 'lib/douban/authorize.rb', line 1206 def get_user_recommendations(user_id="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u(user_id.to_s)}/recommendations?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code == "200" recommendations = [] doc=REXML::Document.new(resp.body) REXML::XPath.each(doc,"//entry") do |entry| recommendations << Recommendation.new(entry) end recommendations else debug(resp) end end |
#get_user_reviews(user_id = "@me", option = {:start_index=>1,:max_results=>10,:orderby=>'score'}) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/douban/authorize.rb', line 287 def get_user_reviews(user_id="@me",option={:start_index=>1,:max_results=>10,:orderby=>'score'}) resp=get("/people/#{u(user_id.to_s)}/reviews?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}&orderby=#{option[:orderby]}") if resp.code=="200" atom=resp.body reviews=[] doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| reviews<< Review.new(entry) end reviews else debug(resp) end end |
#get_user_tags(user_id = "@me", flag = :book, option = {:max_results=>10}) ⇒ Object
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
# File 'lib/douban/authorize.rb', line 1079 def (user_id="@me",flag=:book,option={:max_results=>10}) case flag when :book resp=get("/people/#{u user_id}/tags?cat=book&max-results=#{option[:max_results]}") when :music resp=get("/people/#{u user_id}/tags?cat=music&max-results=#{option[:max_results]}") when :movie resp=get("/people/#{u user_id}/tags?cat=movie&max-results=#{option[:max_results]}") end if resp.code=="200" =[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| << Tag.new(entry) end else debug(resp) end end |
#get_user_wish_events(user_id = "@me", option = {:start_index=>1,:max_results=>10}) ⇒ Object
828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/douban/authorize.rb', line 828 def get_user_wish_events(user_id="@me",option={:start_index=>1,:max_results=>10}) resp=get("/people/#{u(user_id.to_s)}/events/wish?start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" events=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//feed/entry") do |entry| events<< Event.new(entry) end events else nil end end |
#get_wisher_people(*args) ⇒ Object
DEPRECATED: Please use get_event_wisher_people instead.
767 768 769 770 |
# File 'lib/douban/authorize.rb', line 767 def get_wisher_people(*args) warn "[DEPRECATION] `get_wisher_people` is deprecated. Please use `get_event_wisher_people` instead." get_event_wisher_people(*args) end |
#modify_collection(collection, subject_id = "", content = "", rating = 5, status = "", tag = [], option = {:privacy=>"public"}) ⇒ Object
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/douban/authorize.rb', line 476 def modify_collection(collection, subject_id="",content="",=5,status="",tag=[],option={:privacy=>"public"}) collection_id = case collection when Collection then collection.collection_id else collection end subject_id = collection.subject.id if subject_id.nil? and collection.kind_of?(Collection) db_tag="" if tag.size==0 db_tag='<db:tag name="" />' else tag.each do |t| db_tag+=%Q{<db:tag name="#{h t}" />} end end entry=%Q{<?xml version='1.0' encoding='UTF-8'?> <entry xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/"> <id>http://api.douban.com/collection/#{h collection_id}</id> <db:status>#{h status}</db:status> #{db_tag} <gd:rating xmlns:gd="http://schemas.google.com/g/2005" value="#{h }" /> <content>#{h content}</content> <db:subject> <id>#{h subject_id}</id> </db:subject> <db:attribute name="privacy">#{h option[:privacy]}</db:attribute> </entry> } resp=put("/collection/#{u collection_id}",entry,{"Content-Type"=>"application/atom+xml"}) # resp.code should be 202, but currently it's 200 # http://www.douban.com/group/topic/12451628/ if resp.code=="200" or resp.code == "202" Collection.new(resp.body) else debug(resp) end end |
#modify_event(event, title = nil, content = nil, where = nil, option = nil) ⇒ Object
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 |
# File 'lib/douban/authorize.rb', line 891 def modify_event(event,title=nil,content=nil,where=nil,option=nil) event_id = case event when Event then event.event_id else event end option = {} if option.nil? option = {:kind=>"exhibit", :invite_only=>"no", :can_invite=>"yes", :when=>{"endTime"=>(Time.now+60*60*24*5).strftime("%Y-%m-%dT%H:%M:%S+08:00"), "startTime"=>Time.now.strftime("%Y-%m-%dT%H:%M:%S+08:00")}}.merge(option) entry=%Q{<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/"> <title>#{h title}</title> <category scheme="http://www.douban.com/2007#kind" term="http://www.douban.com/2007#event.#{option[:kind]}"/> <content>#{h content}</content> <db:attribute name="invite_only">#{h option[:invite_only]}</db:attribute> <db:attribute name="can_invite">#{h option[:can_invite]}</db:attribute> <gd:when endTime="#{h option[:when]["endTime"]}" startTime="#{h option[:when]["startTime"]}"/> <gd:where valueString="#{h where}" /> </entry> } resp=put("/event/#{u(event_id)}",entry,{"Content-Type"=>"application/atom+xml"}) if resp.code=="200" Event.new(resp.body) else debug(resp) end end |
#modify_note(note, title = "", content = "", option = {:privacy=>"public",:can_reply=>"yes"}) ⇒ Object
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
# File 'lib/douban/authorize.rb', line 714 def modify_note(note,title="",content="",option={:privacy=>"public",:can_reply=>"yes"}) note_id = case note when Note then note.note_id else note end entry=%Q{<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/"> <title>#{h title}</title> <content>#{h content}</content> <db:attribute name="privacy">#{h option[:privacy]}</db:attribute> <db:attribute name="can_reply">#{h option[:can_reply]}</db:attribute> </entry> } resp=put("/note/#{u(note_id.to_s)}",entry,{"Content-Type"=>"application/atom+xml"}) if resp.code=="202" Note.new(resp.body) else debug(resp) end end |
#modify_review(review, subject_link = nil, title = "", content = "", rating = 5) ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/douban/authorize.rb', line 380 def modify_review(review, subject_link=nil,title="",content="",=5) review_id = case review when Review then review.review_id else review end subject_link = review.subject.id if subject_link.nil? and review.kind_of?(Review) entry=%Q{<?xml version='1.0' encoding='UTF-8'?> <entry xmlns:ns0="http://www.w3.org/2005/Atom"> <id>http://api.douban.com/review/#{h review_id}</id> <db:subject xmlns:db="http://www.douban.com/xmlns/"> <id>#{h subject_link}</id> </db:subject> <content>#{h content}</content> <gd:rating xmlns:gd="http://schemas.google.com/g/2005" value="#{h }" ></gd:rating> <title>#{h title}</title> </entry> } resp=put("/review/#{u(review_id)}",entry,{"Content-Type" => "application/atom+xml"}) if resp.code=="202" Review.new(resp.body) else debug(resp) end end |
#read_mail(mail_id = "") ⇒ Object
1014 1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'lib/douban/authorize.rb', line 1014 def read_mail(mail_id="") entry=%Q{<?xml version="1.0" encoding="UTF-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/"><db:attribute name="unread">false</db:attribute></entry>} resp=put("/doumail/#{mail_id.to_s}",entry,{"Content-Type" => "application/atom+xml"}) if resp.code=="202" true else false end end |
#read_mails(mail_ids = []) ⇒ Object
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
# File 'lib/douban/authorize.rb', line 1031 def read_mails(mail_ids=[]) entrys="" mail_ids.each do |mail_id| entrys +=%Q{<entry><id>http://api.douban.com/doumail/#{mail_id}</id><db:attribute name="unread">false</db:attribute></entry>} end feed=%Q{<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/">#{entrys}</feed>} resp=put("/doumail/",feed,{"Content-Type" => "application/atom+xml"}) if resp.code=="202" true else false end end |
#request_token(arg = nil) ⇒ Object
:call-seq:
request_token => OAuth::RequestToken
request_token :as_token => OAuth::Token
request_token :as_hash => Hash
if you want to serialize request_token, use :as_token or :as_hash
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 |
# File 'lib/douban/authorize.rb', line 1140 def request_token(arg=nil) if arg.nil? @request_token elsif arg == :as_token @request_token.nil? ? nil : OAuth::Token.new(@request_token.token, @request_token.secret) elsif arg == :as_hash @request_token.nil? ? nil : {:token => @request_token.token, :secret => @request_token.secret} else raise ArgumentError end end |
#request_token=(token) ⇒ Object
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
# File 'lib/douban/authorize.rb', line 1114 def request_token=(token) case token when OAuth::RequestToken @request_token = token when OAuth::Token @request_token = OAuth::RequestToken.new( new_request_consumer, token.token, token.secret) when Hash @request_token = OAuth::RequestToken.new( new_request_consumer, token[:token], token[:secret]) else raise ArgumentError end end |
#search_book(*args) ⇒ Object
:call-seq:
search_book(:q => "search word") => [Book] or nil
search_book(:tag => "tag name") => [Book] or nil
search_book("search word") => [Book] or nil
搜索书籍
-
option
-
q: query string
-
tag:
-
start_index:
-
max_results:
-
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/douban/authorize.rb', line 229 def search_book(*args) url = _subject_search_args_to_url(:book, *args) resp=get(url) if resp.code=="200" atom=resp.body doc=REXML::Document.new(atom) books=[] REXML::XPath.each(doc,"//entry") do |entry| books << Book.new(entry) end books else nil end end |
#search_events(q = "", option = {:location=>"all",:start_index=>1,:max_results=>10}) ⇒ Object
857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/douban/authorize.rb', line 857 def search_events(q="",option={:location=>"all",:start_index=>1,:max_results=>10}) resp=get("/events?q=#{u(q.to_s)}&location=#{option[:location]}&start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" events=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//feed/entry") do |entry| events<< Event.new(entry) end events else nil end end |
#search_movie(*args) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/douban/authorize.rb', line 246 def search_movie(*args) url = _subject_search_args_to_url(:movie, *args) resp=get(url) if resp.code=="200" atom=resp.body doc=REXML::Document.new(atom) movies=[] REXML::XPath.each(doc,"//entry") do |entry| movies << Movie.new(entry) end movies else nil end end |
#search_music(tag = "", option = {:start_index=>1,:max_results=>10}) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/douban/authorize.rb', line 262 def search_music(tag="",option={:start_index=>1,:max_results=>10}) url = _subject_search_args_to_url(:music, *args) resp=get(url) if resp.code=="200" atom=resp.body doc=REXML::Document.new(atom) music=[] REXML::XPath.each(doc,"//entry") do |entry| music << Music.new(entry) end music else nil end end |
#search_people(q = "", option = {:start_index=>1,:max_results=>10}) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/douban/authorize.rb', line 129 def search_people(q="",option={:start_index=>1,:max_results=>10}) resp=get("/people?q=#{u(q.to_s)}&start-index=#{option[:start_index]}&max-results=#{option[:max_results]}") if resp.code=="200" results=[] atom=resp.body doc=REXML::Document.new(atom) REXML::XPath.each(doc,"//entry") do |entry| results << People.new(entry) end results else nil end end |
#send_mail(id = "", title = "", content = "", captcha_token = "", captcha_string = "") ⇒ Object
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
# File 'lib/douban/authorize.rb', line 982 def send_mail(id="",title="",content="",captcha_token="",captcha_string="") if !(captcha_token.empty?&&captcha_string.empty?) entry=%Q(<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/"> <db:entity name="receiver"><uri>http://api.douban.com/people/#{h id}</uri></db:entity> <content>#{h content}</content> <title>#{h title}</title> <db:attribute name="captcha_token">#{h captcha_token}</db:attribute> <db:attribute name="captcha_string">#{h captcha_string}</db:attribute> </entry>) else entry=%Q(<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:db="http://www.douban.com/xmlns/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/"> <db:entity name="receiver"> <uri>http://api.douban.com/people/#{h id}</uri></db:entity> <content>#{h content}</content> <title>#{h title}</title> </entry>) end resp=post("/doumails",entry,{"Content-Type"=>"application/atom+xml"}) if resp.code=="201" true elsif resp.code=="403" hash={} str=CGI.unescapeHTML(resp.body) hash[:token]=str.scan(/^captcha_token=(.*?)&/).flatten.to_s hash[:url]=str.scan(/captcha_url=(.*?)$/).flatten.to_s hash else debug(resp) end end |
#verify_token ⇒ Object
验证Access Token是否可用goo.gl/8v8d
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 |
# File 'lib/douban/authorize.rb', line 1302 def verify_token resp = get("/access_token/#{@access_token.token}") if resp.code == "200" true elsif resp.code == "401" false else debug(resp, false) end end |