Module: Douban::Client::Doumail

Included in:
Douban::Client
Defined in:
lib/douban_api/client/doumail.rb

Overview

Instance Method Summary collapse

Instance Method Details

#delete_doumail(id) ⇒ Hashie::Mash

删除豆邮

Examples:

删除id为281740901的删除

client.delete_doumail("281740901")

删除多个豆邮

client.delete_doumail(["281740901", "281745597"])

Parameters:

  • id (Array<String>, String)

    豆邮id的列表或豆邮的id

Returns:

  • (Hashie::Mash)

    豆邮信息

See Also:

是否需要认证:

  • true

需要的scope:

  • community_advanced_doumail_w



90
91
92
93
94
95
96
# File 'lib/douban_api/client/doumail.rb', line 90

def delete_doumail(id)
  if id.kind_of?(Array)
    post "v2/doumail/delete", :ids => id.join(',')
  else
    post "v2/doumail/#{id}"
  end
end

#doumail(id, keep_unread = false) ⇒ Hashie::Mash

获取一封邮件

Examples:

获取 id为281922967 的豆邮

client.doumail('281922967')

Parameters:

  • id (String)

    豆邮的id

Returns:

  • (Hashie::Mash)

    豆邮信息

See Also:

是否需要认证:

  • true

需要的scope:

  • community_advanced_doumail_r



16
17
18
# File 'lib/douban_api/client/doumail.rb', line 16

def doumail(id, keep_unread=false)
  response = get("v2/doumail/#{id}", :"keep-unread" => keep_unread)
end

#inbox(options = {}) ⇒ Array<Hashie::Mash>

获取用户收件箱

Examples:

获取当前用户的收件箱

client.inbox

Returns:

  • (Array<Hashie::Mash>)

    豆邮列表

See Also:

是否需要认证:

  • true

需要的scope:

  • community_advanced_doumail_r



28
29
30
31
# File 'lib/douban_api/client/doumail.rb', line 28

def inbox(options={})
  response = get "v2/doumail/inbox"
  response["mails"]
end

#outbox(options = {}) ⇒ Array<Hashie::Mash>

获取用户发件箱

Examples:

获取当前用户的发件箱

client.outbox

Returns:

  • (Array<Hashie::Mash>)

    豆邮列表

See Also:

是否需要认证:

  • true

需要的scope:

  • community_advanced_doumail_r



41
42
43
44
# File 'lib/douban_api/client/doumail.rb', line 41

def outbox(options={})
  response = get "v2/doumail/outbox"
  response["mails"]
end

#read(id) ⇒ Array<Hashie::Mash>, Hashie::Mash

标记已读邮件

Examples:

标记id为281740901的

client.read("281740901")

标记多个豆邮为已读

client.read(["281740901", "281745597"])

Parameters:

  • id (Array<String>, String)

    豆邮id的列表或豆邮的id

Returns:

  • (Array<Hashie::Mash>, Hashie::Mash)

    豆邮信息或者豆邮列表

See Also:

是否需要认证:

  • true

需要的scope:

  • community_advanced_doumail_w



70
71
72
73
74
75
76
77
# File 'lib/douban_api/client/doumail.rb', line 70

def read(id)
  if id.is_a?(Array)
    response = put("v2/doumail/read", :ids => id.join(','))
    response["doumails"]
  else 
    put "v2/doumail/#{id}"
  end
end

#send_doumail(receiver_id, options = {}) ⇒ Hashie::Mash

发送一封豆邮

Examples:

发送一封豆邮

client.send_doumail('48576635', {
  :title => "test",
  :content => "只是test"
})

Parameters:

  • receiver_id (String)

    收件人的id

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :title (String)

    豆邮标题: 必填字段

  • :content (String)

    豆邮正文: 必填字段

  • :captcha_token (String)

    系统验证码 token: 选填字段

  • :captcha_string (String)

    用户输入验证码: 选填字段

Returns:

  • (Hashie::Mash)

    豆邮信息

See Also:

是否需要认证:

  • true

需要的scope:

  • community_advanced_doumail_w



114
115
116
117
# File 'lib/douban_api/client/doumail.rb', line 114

def send_doumail(receiver_id, options={})
  options["receiver_id"] = receiver_id
  post("v2/doumails", options) == {}
end

#unread(options = {}) ⇒ Array<Hashie::Mash>

获取用户未读邮件

Examples:

获取当前用户未读邮件

client.unread

Returns:

  • (Array<Hashie::Mash>)

    豆邮列表

See Also:

是否需要认证:

  • true

需要的scope:

  • community_advanced_doumail_r



54
55
56
57
# File 'lib/douban_api/client/doumail.rb', line 54

def unread(options={})
  response = get "v2/doumail/inbox/unread"
  response["mails"]
end