Module: Douban::Client::Event

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

Overview

Instance Method Summary collapse

Instance Method Details

#created_events(user_id = nil, options = {}) ⇒ Array<Hashie::Mash>

获取用户创建的活动

Examples:

获取 id为2217855 的用户创建的活动

Douban.created_events('2217855')

获取已认证的用户创建的活动

client.created_events()

Parameters:

  • user_id (String) (defaults to: nil)

    用户的数字id

Returns:

  • (Array<Hashie::Mash>)

    活动列表

See Also:

是否需要认证:

  • false



59
60
61
62
63
64
65
66
67
# File 'lib/douban_api/client/event.rb', line 59

def created_events(user_id=nil, options={})
  if user_id.nil?
    response = get("v2/event/user_created/#{get_user_id}", options)
  else
    response = get("v2/event/user_created/#{user_id}", options)
  end
  
  response["events"]
end

#event(id) ⇒ Hashie::Mash

获取活动

Examples:

获取 id为17790089 的活动信息

Douban.event('17790089')

Parameters:

  • id (String)

    活动的id

Returns:

  • (Hashie::Mash)

    活动信息

See Also:

是否需要认证:

  • false



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

def event(id)
  response = get "v2/event/#{id}"
end

#event_participants(id, options = {}) ⇒ Array<Hashie::Mash>

获取参加活动的用户

Examples:

获取参与 id为17790089 活动的用户

Douban.event_participants('17790089')

Parameters:

  • id (String)

    活动的id

Returns:

  • (Array<Hashie::Mash>)

    用户列表

See Also:

是否需要认证:

  • false



29
30
31
32
# File 'lib/douban_api/client/event.rb', line 29

def event_participants(id, options={})
  response = get("v2/event/#{id}/participants", options)
  response["users"]
end

#event_wishers(id, options = {}) ⇒ Array<Hashie::Mash>

获取活动感兴趣的用户

Examples:

获取对 id为17790089 活动感兴趣的用户

Douban.event_wishers('17790089')

Parameters:

  • id (String)

    活动的id

Returns:

  • (Array<Hashie::Mash>)

    用户列表

See Also:

是否需要认证:

  • false



43
44
45
46
# File 'lib/douban_api/client/event.rb', line 43

def event_wishers(id, options={})
  response = get("v2/event/#{id}/wishers", options)
  response["users"]
end

#events(loc_id, options = {}) ⇒ Array<Hashie::Mash>

获取活动列表

Examples:

查看北京地区的音乐活动

Douban.events('108288', :type => "music")

Parameters:

  • loc_id (String)

    城市id

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

    a customizable set of options

Options Hash (options):

  • :day_type (String)

    时间类型: future, week, weekend, today, tomorrow

  • :type (String)

    活动类型: all,music, film, drama, commonweal, salon, exhibition, party, sports, travel, others

Returns:

  • (Array<Hashie::Mash>)

    活动列表

See Also:

是否需要认证:

  • false



124
125
126
127
# File 'lib/douban_api/client/event.rb', line 124

def events(loc_id, options={})
  response = get("v2/event/list", options.merge(:loc => loc_id))
  response["events"]
end

#loc(id) ⇒ Hashie::Mash

获取城市

Examples:

查看北京的信息

Douban.loc('108288')

Parameters:

  • id (String)

    城市id

Returns:

  • (Hashie::Mash)

    活动列表

See Also:

是否需要认证:

  • false



138
139
140
# File 'lib/douban_api/client/event.rb', line 138

def loc(id)
  response = get "v2/loc/#{id}"
end

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

获取城市列表

Examples:

城市列表

Douban.loc_list

Returns:

  • (Array<Hashie::Mash>)

    城市列表

See Also:

是否需要认证:

  • false



150
151
152
153
# File 'lib/douban_api/client/event.rb', line 150

def loc_list(options={})
  response = get("v2/loc/list", options)
  response["locs"]
end

#participants_event(id, options = {}) ⇒ Hashie::Mash

参加活动

Examples:

参加 id为17717231 的活动

client.participants_event('17717231')

Parameters:

  • id (String)

    活动的id

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

    a customizable set of options

Options Hash (options):

  • :participate_date (String)

    参加时间: 时间格式:“%Y-%m-%d”,无此参数则时间待定

Returns:

  • (Hashie::Mash)

    活动信息

See Also:

是否需要认证:

  • true



166
167
168
# File 'lib/douban_api/client/event.rb', line 166

def participants_event(id, options={})
  post "v2/event/#{id}/participants", options
end

#participated_events(user_id = nil) ⇒ Array<Hashie::Mash>

获取用户参加的活动

Examples:

获取 id为2217855 的用户参加的活动

Douban.participated_events('2217855')

获取已认证的用户参加的活动

client.participated_events()

Parameters:

  • user_id (String) (defaults to: nil)

    用户的数字id

Returns:

  • (Array<Hashie::Mash>)

    活动列表

See Also:

是否需要认证:

  • false



80
81
82
83
84
85
86
87
88
# File 'lib/douban_api/client/event.rb', line 80

def participated_events(user_id=nil)
  if user_id.nil?
    response = get "v2/event/user_participated/#{get_user_id}"
  else
    response = get "v2/event/user_participated/#{user_id}"
  end
  
  response["events"]
end

#unparticipants_event(id) ⇒ Hashie::Mash

不参加活动

Examples:

取消参加 id为17717231 的活动

client.unparticipants_event('17717231')

Parameters:

  • id (String)

    活动的id

Returns:

  • (Hashie::Mash)

    活动信息

See Also:

是否需要认证:

  • true



179
180
181
# File 'lib/douban_api/client/event.rb', line 179

def unparticipants_event(id)
  delete "v2/event/#{id}/participants"
end

#unwish_event(id) ⇒ Hashie::Mash

对活动不感兴趣

Examples:

对 id为17717231 的活动不感兴趣

client.wish_event('17717231')

Parameters:

  • id (String)

    活动的id

Returns:

  • (Hashie::Mash)

    活动信息

See Also:

是否需要认证:

  • true



205
206
207
# File 'lib/douban_api/client/event.rb', line 205

def unwish_event(id)
  delete "v2/event/#{id}/wishers"
end

#wish_event(id) ⇒ Hashie::Mash

对活动感兴趣

Examples:

对 id为17717231 的活动感兴趣

client.wish_event('17717231')

Parameters:

  • id (String)

    活动的id

Returns:

  • (Hashie::Mash)

    活动信息

See Also:

是否需要认证:

  • true



192
193
194
# File 'lib/douban_api/client/event.rb', line 192

def wish_event(id)
  post "v2/event/#{id}/wishers"
end

#wished_events(user_id = nil) ⇒ Array<Hashie::Mash>

获取用户参加的活动

Examples:

获取 id为2217855 的用户感兴趣的活动

Douban.wished_events('2217855')

获取已认证的用户感兴趣的活动

client.wished_events()

Parameters:

  • user_id (String) (defaults to: nil)

    用户的数字id

Returns:

  • (Array<Hashie::Mash>)

    活动列表

See Also:

是否需要认证:

  • false



101
102
103
104
105
106
107
108
109
# File 'lib/douban_api/client/event.rb', line 101

def wished_events(user_id=nil)
  if user_id.nil?
    response = get "v2/event/user_wished/#{get_user_id}"
  else
    response = get "v2/event/user_wished/#{user_id}"
  end
  
  response["events"]
end