wechat 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15c91eb2d65ed9645ca79ace9245f8b37951dd04
4
- data.tar.gz: ce52424a06ecbd344c18f4a2113dbf7af9507a9f
3
+ metadata.gz: 0ff11a10da8e6a405f646702fc63e4b72e778ace
4
+ data.tar.gz: 5269fd75b8a4044d6b140fdb197f3dd8381fc868
5
5
  SHA512:
6
- metadata.gz: 7d7c44d220b7467482271b757dddc50e71f19df8a2d2bde28d6e2d3a3c8f9eaf2cebb70adaa6df73ad9b86c34314f013c0803d3def5cd47dd933e82d1d86408b
7
- data.tar.gz: 988540c451e81e64e44c2959d46197e420bfe1ed32756e4a15b33b68ad523abf9a32afb50fd9ddeb3e117c98fd6bf16c83eb77b750161976fec40b0dec0f309a
6
+ metadata.gz: 03775bee616b1c070efefaff727330ea8ce3411232ea3dffb3f8da2cd21d309b1aa8e86a07831711f198da5dbb5460bc71fa831900eba27c29ac291badad7548
7
+ data.tar.gz: 6e1001ea2b328e4c69fd6960bb8c7b50a0b178950c2c922ed482b37eacabdcc5c0b4cf7ec213490a80de6530695d79b428becf61d72c33f462dfc22586145433
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.4.2 (released at 9/7/2015)
4
+
5
+ * Fix wrong number of arguments at Wechat::Responder.on by using arity #47
6
+ * Fix can not access wechat method after using instance level context.
7
+ * Fix skip_verify_ssl parameter error.
8
+
3
9
  ## v0.4.1 (released at 9/6/2015)
4
10
 
5
11
  * Limit news articles collection to 10, close #5
data/README.md CHANGED
@@ -147,6 +147,7 @@ Wechat commands:
147
147
  wechat custom_video [OPENID, VIDEO_PATH] # 发送视频客服消息
148
148
  wechat custom_voice [OPENID, VOICE_PATH] # 发送语音客服消息
149
149
  wechat department [DEPARTMENT_ID] # 获取部门列表
150
+ wechat department_create [NAME, PARENT_ID] # 创建部门
150
151
  wechat group_create [GROUP_NAME] # 创建分组
151
152
  wechat group_delete [GROUP_ID] # 删除分组
152
153
  wechat group_update [GROUP_ID, NEW_GROUP_NAME] # 修改分组名
@@ -352,14 +353,16 @@ class WechatsController < ApplicationController
352
353
  end
353
354
  end
354
355
 
355
- # 当收到 EventKey 为 mykey 的事件时
356
- on :event, with: "mykey" do |request, key|
357
- request.reply.text "收到来自#{request[:FromUserName]} 的EventKey #{key} 的事件"
356
+ # 当收到EventKey 为二维码扫描结果事件时
357
+ on :event, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type|
358
+ request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}"
358
359
  end
359
360
 
360
- # 当收到EventKey 为二维码扫描结果事件时
361
- on :event, with: 'BINDING_QR_CODE' do |request, scan_type, scan_result|
362
- request.reply.text "User #{request[:FromUserName]} ScanType #{scan_type} ScanResult #{scan_result}"
361
+ # 当收到EventKey 为CODE 39码扫描结果事件时
362
+ on :event, with: 'BINDING_BARCODE' do |message, scan_result|
363
+ if scan_result.start_with? 'CODE_39,'
364
+ message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}"
365
+ end
363
366
  end
364
367
 
365
368
  # 处理图片信息
@@ -384,12 +387,12 @@ class WechatsController < ApplicationController
384
387
  end
385
388
 
386
389
  # 当用户加关注
387
- on :event, with: 'subscribe' do |request, key|
388
- request.reply.text "#{request[:FromUserName]} #{key} now"
390
+ on :event, with: 'subscribe' do |request|
391
+ request.reply.text "#{request[:FromUserName]} subscribe now"
389
392
  end
390
393
 
391
394
  # 当用户取消关注订阅
392
- on :event, with: 'unsubscribe' do |request, key|
395
+ on :event, with: 'unsubscribe' do |request|
393
396
  request.reply.text "#{request[:FromUserName]}无法收到这条消息。"
394
397
  end
395
398
 
data/bin/wechat CHANGED
@@ -88,6 +88,13 @@ HELP
88
88
  puts Helper.with(options).group_delete(groupid)
89
89
  end
90
90
 
91
+ desc 'department_create [NAME, PARENT_ID]', '创建部门'
92
+ method_option :parentid, aliases: '-p', desc: '父亲部门id。根部门id为1'
93
+ def department_create(name)
94
+ api_opts = options.slice(:parentid)
95
+ puts Helper.with(options).department_create(name, api_opts[:parentid] || '1')
96
+ end
97
+
91
98
  desc 'department [DEPARTMENT_ID]', '获取部门列表'
92
99
  def department(departmentid)
93
100
  puts Helper.with(options).department(departmentid)
data/lib/wechat.rb CHANGED
@@ -25,16 +25,7 @@ module Wechat
25
25
  config = YAML.load(ERB.new(File.new(config_file).read).result)[Rails.env] if File.exist?(config_file)
26
26
  end
27
27
 
28
- config ||= { appid: ENV['WECHAT_APPID'],
29
- secret: ENV['WECHAT_SECRET'],
30
- corpid: ENV['WECHAT_CORPID'],
31
- corpsecret: ENV['WECHAT_CORPSECRET'],
32
- agentid: ENV['WECHAT_AGENTID'],
33
- token: ENV['WECHAT_TOKEN'],
34
- access_token: ENV['WECHAT_ACCESS_TOKEN'],
35
- encrypt_mode: ENV['WECHAT_ENCRYPT_MODE'],
36
- skip_verify_ssl: ENV['WECHAT_SKIP_VERIFY_SSL'],
37
- encoding_aes_key: ENV['WECHAT_ENCODING_AES_KEY'] }
28
+ config ||= config_from_environment
38
29
  config.symbolize_keys!
39
30
  config[:access_token] ||= Rails.root.join('tmp/access_token').to_s
40
31
  config[:jsapi_ticket] ||= Rails.root.join('tmp/jsapi_ticket').to_s
@@ -46,7 +37,22 @@ module Wechat
46
37
  if config.corpid.present?
47
38
  @api ||= CorpApi.new(config.corpid, config.corpsecret, config.access_token, config.agentid, config.skip_verify_ssl)
48
39
  else
49
- @api ||= Api.new(config.appid, config.secret, config.access_token, config.jsapi_ticket, config.skip_verify_ssl)
40
+ @api ||= Api.new(config.appid, config.secret, config.access_token, config.skip_verify_ssl, config.jsapi_ticket)
50
41
  end
51
42
  end
43
+
44
+ private
45
+
46
+ def self.config_from_environment
47
+ { appid: ENV['WECHAT_APPID'],
48
+ secret: ENV['WECHAT_SECRET'],
49
+ corpid: ENV['WECHAT_CORPID'],
50
+ corpsecret: ENV['WECHAT_CORPSECRET'],
51
+ agentid: ENV['WECHAT_AGENTID'],
52
+ token: ENV['WECHAT_TOKEN'],
53
+ access_token: ENV['WECHAT_ACCESS_TOKEN'],
54
+ encrypt_mode: ENV['WECHAT_ENCRYPT_MODE'],
55
+ skip_verify_ssl: ENV['WECHAT_SKIP_VERIFY_SSL'],
56
+ encoding_aes_key: ENV['WECHAT_ENCODING_AES_KEY'] }
57
+ end
52
58
  end
@@ -39,6 +39,10 @@ module Wechat
39
39
  get('user/delete', params: { userid: userid })
40
40
  end
41
41
 
42
+ def department_create(name, parentid)
43
+ post('department/create', JSON.generate(name: name, parentid: parentid))
44
+ end
45
+
42
46
  def department(departmentid = 1)
43
47
  get('department/list', params: { id: departmentid })
44
48
  end
@@ -71,7 +71,7 @@ module Wechat
71
71
  if condition.is_a? Regexp
72
72
  memo[:scoped] ||= [responder] + $LAST_MATCH_INFO.captures if value =~ condition
73
73
  elsif value.is_a? Hash
74
- memo[:scoped] ||= [responder, value[:scan_type], value[:scan_result]] if value[:event_key] == condition
74
+ memo[:scoped] ||= [responder, value[:scan_result], value[:scan_type]] if value[:event_key] == condition
75
75
  else
76
76
  memo[:scoped] ||= [responder, value] if value == condition
77
77
  end
@@ -80,6 +80,10 @@ module Wechat
80
80
  end
81
81
  end
82
82
 
83
+ def wechat
84
+ self.class.wechat # Make sure user can continue access wechat at instance level similar to class level
85
+ end
86
+
83
87
  def show
84
88
  if self.class.corpid.present?
85
89
  echostr, _corp_id = unpack(decrypt(Base64.decode64(params[:echostr]), self.class.encoding_aes_key))
@@ -106,7 +110,6 @@ module Wechat
106
110
  signature = params[:signature] || params[:msg_signature]
107
111
 
108
112
  msg_encrypt = params[:echostr] if self.class.corpid.present?
109
-
110
113
  msg_encrypt ||= request_encrypt_content if self.class.encrypt_mode
111
114
 
112
115
  render text: 'Forbidden', status: 403 if signature != Signature.hexdigest(self.class.token,
@@ -138,7 +141,8 @@ module Wechat
138
141
  request.reply.text responder[:respond]
139
142
  when responder[:proc]
140
143
  define_singleton_method :process, responder[:proc]
141
- send(:process, *args.unshift(request))
144
+ number_of_block_parameter = responder[:proc].arity
145
+ send(:process, *args.unshift(request).take(number_of_block_parameter))
142
146
  else
143
147
  next
144
148
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skinnyworm
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-06 00:00:00.000000000 Z
12
+ date: 2015-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails