Class: Wework::Api::Agent
- Inherits:
-
Base
- Object
- Base
- Wework::Api::Agent
show all
- Defined in:
- lib/wework/api/agent.rb
Constant Summary
Constants included
from Cipher
Cipher::BLOCK_SIZE, Cipher::CIPHER
Instance Attribute Summary
Attributes inherited from Base
#app_id, #app_secret, #corp_id, #options
Instance Method Summary
collapse
-
#authorize_url(redirect_uri, scope = "snsapi_base", state = "wxwork") ⇒ Object
user agent: UA is mozilla/5.0 (iphone; cpu iphone os 10_2 like mac os x) applewebkit/602.3.12 (khtml, like gecko) mobile/14c92 wxwork/1.3.2 micromessenger/6.2.
-
#file_message_send(user_ids, department_ids, media_id) ⇒ Object
-
#get_info ⇒ Object
-
#get_jssign_package(url) ⇒ Object
-
#get_oauth_userinfo(code) ⇒ Object
-
#image_message_send(user_ids, department_ids, media_id) ⇒ Object
-
#menu_create(menu) ⇒ Object
-
#menu_delete ⇒ Object
-
#menu_get ⇒ Object
-
#message_send(user_ids, department_ids, payload = {}) ⇒ Object
-
#news_message_send(user_ids, department_ids, news = []) ⇒ Object
-
#set_info(data = {}) ⇒ Object
-
#text_message_send(user_ids, department_ids, content) ⇒ Object
-
#textcard_message_send(user_ids, department_ids, textcard = {}) ⇒ Object
-
#video_message_send(user_ids, department_ids, video = {}) ⇒ Object
-
#voice_message_send(user_ids, department_ids, media_id) ⇒ Object
Methods inherited from Base
#get, #initialize, #media_get, #media_upload, #post, #post_file, #request, #valid?
Methods included from Cipher
#decrypt, #encrypt, #pack, #unpack
Instance Method Details
#authorize_url(redirect_uri, scope = "snsapi_base", state = "wxwork") ⇒ Object
user agent: UA is mozilla/5.0 (iphone; cpu iphone os 10_2 like mac os x) applewebkit/602.3.12 (khtml, like gecko) mobile/14c92 wxwork/1.3.2 micromessenger/6.2
8
9
10
11
|
# File 'lib/wework/api/agent.rb', line 8
def authorize_url(redirect_uri, scope="snsapi_base", state="wxwork")
uri = ERB::Util.url_encode(redirect_uri)
"#{AUTHORIZE_ENDPOINT}?appid=#{corp_id}&redirect_uri=#{uri}&response_type=code&scope=#{scope}&agentid=#{app_id}&state=#{state}#wechat_redirect"
end
|
#file_message_send(user_ids, department_ids, media_id) ⇒ Object
70
71
72
|
# File 'lib/wework/api/agent.rb', line 70
def file_message_send user_ids, department_ids, media_id
message_send user_ids, department_ids, {file: {media_id: media_id}, msgtype: 'file'}
end
|
#get_info ⇒ Object
31
32
33
|
# File 'lib/wework/api/agent.rb', line 31
def get_info
get 'agent/get', params: {agentid: agent_id}
end
|
#get_jssign_package(url) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/wework/api/agent.rb', line 17
def get_jssign_package url
timestamp = Time.now.to_i
noncestr = SecureRandom.hex(8)
str = "jsapi_ticket=#{jsapi_ticket}&noncestr=#{noncestr}×tamp=#{timestamp}&url=#{url}"
{
"appId" => corp_id,
"nonceStr" => noncestr,
"timestamp" => timestamp,
"url" => url,
"signature" => Digest::SHA1.hexdigest(str),
"rawString" => str
}
end
|
#get_oauth_userinfo(code) ⇒ Object
13
14
15
|
# File 'lib/wework/api/agent.rb', line 13
def get_oauth_userinfo code
get 'user/getuserinfo', params: {code: code}
end
|
#image_message_send(user_ids, department_ids, media_id) ⇒ Object
62
63
64
|
# File 'lib/wework/api/agent.rb', line 62
def image_message_send user_ids, department_ids, media_id
message_send user_ids, department_ids, {image: {media_id: media_id}, msgtype: 'image'}
end
|
39
40
41
|
# File 'lib/wework/api/agent.rb', line 39
def
post 'menu/create', , params: {agentid: agent_id}
end
|
47
48
49
|
# File 'lib/wework/api/agent.rb', line 47
def
get 'menu/delete', params: {agentid: agent_id}
end
|
43
44
45
|
# File 'lib/wework/api/agent.rb', line 43
def
get 'menu/get', params: {agentid: agent_id}
end
|
#message_send(user_ids, department_ids, payload = {}) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/wework/api/agent.rb', line 51
def message_send user_ids, department_ids, payload={}
payload[:agentid] = agent_id
payload[:touser] = Array.wrap(user_ids).join('|') if user_ids.present?
payload[:toparty] = Array.wrap(department_ids).join('|') if department_ids.present?
post 'message/send', payload
end
|
#news_message_send(user_ids, department_ids, news = []) ⇒ Object
82
83
84
|
# File 'lib/wework/api/agent.rb', line 82
def news_message_send user_ids, department_ids, news=[]
message_send user_ids, department_ids, {news: {articles: news}, msgtype: 'news'}
end
|
#set_info(data = {}) ⇒ Object
35
36
37
|
# File 'lib/wework/api/agent.rb', line 35
def set_info data={}
post 'agent/set', data.merge(agentid: agent_id)
end
|
#text_message_send(user_ids, department_ids, content) ⇒ Object
58
59
60
|
# File 'lib/wework/api/agent.rb', line 58
def text_message_send user_ids, department_ids, content
message_send user_ids, department_ids, {text: {content: content}, msgtype: 'text'}
end
|
#textcard_message_send(user_ids, department_ids, textcard = {}) ⇒ Object
78
79
80
|
# File 'lib/wework/api/agent.rb', line 78
def textcard_message_send user_ids, department_ids, textcard={}
message_send user_ids, department_ids, {textcard: textcard, msgtype: 'textcard'}
end
|
#video_message_send(user_ids, department_ids, video = {}) ⇒ Object
74
75
76
|
# File 'lib/wework/api/agent.rb', line 74
def video_message_send user_ids, department_ids, video={}
message_send user_ids, department_ids, {video: video, msgtype: 'video'}
end
|
#voice_message_send(user_ids, department_ids, media_id) ⇒ Object
66
67
68
|
# File 'lib/wework/api/agent.rb', line 66
def voice_message_send user_ids, department_ids, media_id
message_send user_ids, department_ids, {voice: {media_id: media_id}, msgtype: 'voice'}
end
|