Class: WeChat::Bot::Contact
- Inherits:
-
Object
- Object
- WeChat::Bot::Contact
- Defined in:
- lib/wechat/bot/contact.rb
Overview
微信联系人
可以是用户、公众号、群组等
Defined Under Namespace
Modules: Kind
Class Method Summary collapse
Instance Method Summary collapse
-
#city ⇒ Object
城市.
-
#displayname ⇒ Object
群聊显示名.
- #find_member(args) ⇒ Object
-
#group? ⇒ Boolean
是否群聊.
-
#initialize(bot) ⇒ Contact
constructor
A new instance of Contact.
-
#kind ⇒ Object
用户类型.
-
#members ⇒ Hash
群组成员列表.
-
#mp? ⇒ Boolean
是否公众号.
-
#nickname ⇒ Object
用户昵称.
-
#parse(raw, update = false) ⇒ Contact
联系人解析.
-
#province ⇒ Object
省份.
-
#remarkname ⇒ Object
备注名.
-
#sex ⇒ Object
性别.
-
#signature ⇒ Object
个人签名.
-
#special? ⇒ Boolean
是否特殊账户.
- #to_s ⇒ Object (also: #inspect)
- #update(raw) ⇒ Object
-
#username ⇒ Object
用户唯一 ID.
Constructor Details
#initialize(bot) ⇒ Contact
Returns a new instance of Contact.
18 19 20 21 |
# File 'lib/wechat/bot/contact.rb', line 18 def initialize(bot) @bot = bot @data = {} end |
Class Method Details
.parse(obj, bot) ⇒ Object
14 15 16 |
# File 'lib/wechat/bot/contact.rb', line 14 def self.parse(obj, bot) self.new(bot).parse(obj) end |
Instance Method Details
#city ⇒ Object
城市
64 65 66 |
# File 'lib/wechat/bot/contact.rb', line 64 def city attr(:city) end |
#displayname ⇒ Object
群聊显示名
39 40 41 |
# File 'lib/wechat/bot/contact.rb', line 39 def displayname attr(:displayname) end |
#find_member(args) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/wechat/bot/contact.rb', line 93 def find_member(args) if args[:username] members.find{|contact| args[:username] == contact.username } elsif args[:nickname] members.find{|contact| args[:nickname] == contact.nickname } end end |
#group? ⇒ Boolean
是否群聊
74 75 76 |
# File 'lib/wechat/bot/contact.rb', line 74 def group? kind == Kind::Group end |
#kind ⇒ Object
用户类型
54 55 56 |
# File 'lib/wechat/bot/contact.rb', line 54 def kind attr(:kind) end |
#members ⇒ Hash
89 90 91 |
# File 'lib/wechat/bot/contact.rb', line 89 def members attr(:members) end |
#mp? ⇒ Boolean
是否公众号
79 80 81 |
# File 'lib/wechat/bot/contact.rb', line 79 def mp? kind == Kind::MP end |
#nickname ⇒ Object
用户昵称
29 30 31 |
# File 'lib/wechat/bot/contact.rb', line 29 def nickname attr(:nickname) end |
#parse(raw, update = false) ⇒ Contact
联系人解析
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/wechat/bot/contact.rb', line 105 def parse(raw, update = false) @raw = raw parse_kind parse_members @raw.each do |key, value| if attribute = mapping[key] next if value.to_s.empty? && update sync(attribute, value) end end self end |
#province ⇒ Object
省份
59 60 61 |
# File 'lib/wechat/bot/contact.rb', line 59 def province attr(:province) end |
#remarkname ⇒ Object
备注名
34 35 36 |
# File 'lib/wechat/bot/contact.rb', line 34 def remarkname attr(:remarkname) end |
#sex ⇒ Object
性别
44 45 46 |
# File 'lib/wechat/bot/contact.rb', line 44 def sex attr(:sex) end |
#signature ⇒ Object
个人签名
49 50 51 |
# File 'lib/wechat/bot/contact.rb', line 49 def signature attr(:signature) end |
#special? ⇒ Boolean
是否特殊账户
69 70 71 |
# File 'lib/wechat/bot/contact.rb', line 69 def special? kind == Kind::Special end |
#to_s ⇒ Object Also known as: inspect
127 128 129 |
# File 'lib/wechat/bot/contact.rb', line 127 def to_s "#<#{self.class}:#{object_id.to_s(16)} username='#{username}' nickname='#{nickname}' kind='#{kind}' members=#{members.size}>" end |
#update(raw) ⇒ Object
122 123 124 125 |
# File 'lib/wechat/bot/contact.rb', line 122 def update(raw) @raw = raw parse(@raw, true) end |
#username ⇒ Object
用户唯一 ID
24 25 26 |
# File 'lib/wechat/bot/contact.rb', line 24 def username attr(:username) end |