Class: WeChat::Bot::ContactList
- Inherits:
-
CachedList
- Object
- CachedList
- WeChat::Bot::ContactList
- Defined in:
- lib/wechat/bot/contact_list.rb
Overview
微信联系人列表
Instance Method Summary collapse
-
#batch_sync(list) ⇒ ContactList
批量同步联系人数据.
-
#find(**args) ⇒ Contact
查找用户.
- #size ⇒ Object
-
#sync(data) ⇒ Contact
创建用户或更新用户数据.
Methods inherited from CachedList
Constructor Details
This class inherits a constructor from WeChat::Bot::CachedList
Instance Method Details
#batch_sync(list) ⇒ ContactList
批量同步联系人数据
更多查看 #sync 接口
11 12 13 14 15 16 17 |
# File 'lib/wechat/bot/contact_list.rb', line 11 def batch_sync(list) list.each do |item| sync(item) end self end |
#find(**args) ⇒ Contact
查找用户
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/wechat/bot/contact_list.rb', line 61 def find(**args) @mutex.synchronize do return @cache[args[:username]] if args[:username] if args[:nickname] @cache.each do |_, contact| return contact if contact.nickname == args[:nickname] end end end end |
#size ⇒ Object
19 20 21 |
# File 'lib/wechat/bot/contact_list.rb', line 19 def size @cache.size end |
#sync(data) ⇒ Contact
创建用户或更新用户数据
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wechat/bot/contact_list.rb', line 27 def sync(data) @mutex.synchronize do contact = Contact.parse(data, @bot) if @cache[contact.username] @cache[contact.username].update(data) else @cache[contact.username] = contact end contact end end |