Module: Wechat::Api::Public::User

Included in:
Wechat::Api::Public
Defined in:
app/apis/wechat/api/public/user.rb

Constant Summary collapse

BASE =
'https://api.weixin.qq.com/cgi-bin/'

Instance Method Summary collapse

Instance Method Details

#tag(tagid, next_openid = '') ⇒ Object



41
42
43
# File 'app/apis/wechat/api/public/user.rb', line 41

def tag(tagid, next_openid = '')
  post 'user/tag/get', tagid: tagid, next_openid: next_openid, base: BASE
end

#tag_add_user(tagid, *openids) ⇒ Object



33
34
35
# File 'app/apis/wechat/api/public/user.rb', line 33

def tag_add_user(tagid, *openids)
  post 'tags/members/batchtagging', openid_list: openids, tagid: tagid, base: BASE
end

#tag_create(tag_name, tag_id = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/apis/wechat/api/public/user.rb', line 13

def tag_create(tag_name, tag_id = nil)
  if tag_id.present?
    r = post 'tags/update', tag: { id: tag_id, name: tag_name }, base: BASE
  else
    r = post 'tags/create', tag: { name: tag_name }, base: BASE
  end

  if r['errcode'] == 0
    { 'tag' => { 'id' => tag_id, 'name' => tag_name } }
  elsif r['errcode'] == 45157
    { 'tag' => tags['tags'].find { |i| i['name'] == tag_name } }
  else
    r
  end
end

#tag_del_user(tagid, *openids) ⇒ Object



37
38
39
# File 'app/apis/wechat/api/public/user.rb', line 37

def tag_del_user(tagid, *openids)
  post 'tags/members/batchuntagging', openid_list: openids, tagid: tagid, base: BASE
end

#tag_delete(tagid) ⇒ Object



29
30
31
# File 'app/apis/wechat/api/public/user.rb', line 29

def tag_delete(tagid)
  post 'tags/delete', tag: { id: tagid }, base: BASE
end

#tagsObject



9
10
11
# File 'app/apis/wechat/api/public/user.rb', line 9

def tags
  get 'tags/get', base: BASE
end

#user(openid) ⇒ Object



52
53
54
# File 'app/apis/wechat/api/public/user.rb', line 52

def user(openid)
  get 'user/info', params: { openid: openid }, base: BASE
end

#user_batchget(openids, lang = 'zh-CN') ⇒ Object



56
57
58
# File 'app/apis/wechat/api/public/user.rb', line 56

def user_batchget(openids, lang = 'zh-CN')
  post 'user/info/batchget', user_list: openids.collect { |v| { openid: v, lang: lang } }, base: BASE
end

#user_change_group(openid, to_groupid) ⇒ Object



64
65
66
# File 'app/apis/wechat/api/public/user.rb', line 64

def user_change_group(openid, to_groupid)
  post 'groups/members/update', openid: openid, to_groupid: to_groupid, base: BASE
end

#user_group(openid) ⇒ Object



60
61
62
# File 'app/apis/wechat/api/public/user.rb', line 60

def user_group(openid)
  post 'groups/getid', openid: openid, base: BASE
end

#user_update_remark(openid, remark) ⇒ Object



68
69
70
# File 'app/apis/wechat/api/public/user.rb', line 68

def user_update_remark(openid, remark)
  post 'user/info/updateremark', openid: openid, remark: remark, base: BASE
end

#users(nextid = nil) ⇒ Object



45
46
47
48
49
50
# File 'app/apis/wechat/api/public/user.rb', line 45

def users(nextid = nil)
  params = {}
  params.merge! next_openid: nextid if nextid.present?

  get 'user/get', params: params, base: BASE
end