wechat 0.6.10 → 0.7.0

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: a46351d945927448378043c4d7ff5305d42a16dc
4
- data.tar.gz: b8f2ab96e6f7c04803a993cede138db3ac385b53
3
+ metadata.gz: b7f55b06f42f4f81535e3eac7cb4030d7850758e
4
+ data.tar.gz: 5b8992563a4e96c2e084a2f371601445678a3a8c
5
5
  SHA512:
6
- metadata.gz: 388f39cc6658760db382a9f0cb327716a1cacaa2673ed655c32d10d160169d290342c70d259c560ad894d204e6481c453a7d26cd35c934cbf2b15d134f9df3c6
7
- data.tar.gz: 93cd2d31a610c60ff6cb7962aea8f3e42813c55f35cd687ace7dd5091c1459549792ca8d76e244d79a5d68194705c6bd856ded5aad8c9730ee23449b0cfd6217
6
+ metadata.gz: 602388ebebfda0bba1b5bc2f7cf7601cb313255acdc658902bd3bab5785c52aa23139bdd9bb503d787175012691cccebf0aa17e0637e2aa84f6e251321c43cdb
7
+ data.tar.gz: 3700915a52962394b839d77d8b3d6478cdb1df903f5d026910f9bd330755353396c5ae572e199da9f5a8e31bbfe492a0aa4f022bcbc8b7dac50d6f6b268df62f
@@ -1,27 +1,8 @@
1
1
  # Changelog
2
2
 
3
- * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
4
- * Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
5
- * Warning not support on :scan with regular expression. by @kikyous #84
6
-
7
- ## v0.7.1 (released at 1/11/2016)
8
-
9
- * Fix after using http, upload file function break. #78
10
- * Add callback function after_wechat_response support. by @zfben #79
11
- * Should using department_id instead of departmentid at enterprise api: user_simplelist/user_list.
12
-
13
3
  ## v0.7.0 (released at 1/1/2016)
14
4
 
15
- * Using [http](https://github.com/httprb/http) instead of rest-client for performance reason. (not support upload file yet)
16
-
17
- ## v0.6.10 (released at 1/17/2016)
18
-
19
- * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
20
- * Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
21
- * Warning not support on :scan with regular expression. by @kikyous #84
22
-
23
- ## v0.6.9 (released at 1/6/2016)
24
-
5
+ * Using [http](https://github.com/httprb/http) instead of rest-client for performance reason.
25
6
  * Fix token refresh bug on multi worker. #76
26
7
  * Rewrite the token relative code to add more storage support in future.
27
8
 
data/README.md CHANGED
@@ -418,6 +418,7 @@ So the ActionController should defined like below:
418
418
  ```ruby
419
419
  class WechatsController < ActionController::Base
420
420
  wechat_responder
421
+ wechat_responder
421
422
 
422
423
  # default text responder when no other match
423
424
  on :text do |request, content|
@@ -1,7 +1,7 @@
1
1
  require 'wechat/api_base'
2
2
  require 'wechat/client'
3
3
  require 'wechat/token/public_access_token'
4
- require 'wechat/ticket/public_jsapi_ticket'
4
+ require 'wechat/ticket/jsapi_ticket'
5
5
 
6
6
  module Wechat
7
7
  class Api < ApiBase
@@ -11,7 +11,7 @@ module Wechat
11
11
  def initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file)
12
12
  @client = Client.new(API_BASE, timeout, skip_verify_ssl)
13
13
  @access_token = Token::PublicAccessToken.new(@client, appid, secret, token_file)
14
- @jsapi_ticket = Ticket::PublicJsapiTicket.new(@client, @access_token, jsapi_ticket_file)
14
+ @jsapi_ticket = Ticket::JsapiTicket.new(@client, @access_token, jsapi_ticket_file)
15
15
  end
16
16
 
17
17
  def groups
@@ -48,10 +48,9 @@ HELP
48
48
  rails_config_file = File.join(Dir.getwd, 'config/wechat.yml')
49
49
  home_config_file = File.join(Dir.home, '.wechat.yml')
50
50
  if File.exist?(rails_config_file)
51
- rails_env = ENV['RAILS_ENV'] || 'default'
52
- config = YAML.load(ERB.new(File.read(rails_config_file)).result)[rails_env]
51
+ config = YAML.load(ERB.new(File.read(rails_config_file)).result)['default']
53
52
  if config.present? && (config['appid'] || config['corpid'])
54
- puts "Using rails project config/wechat.yml #{rails_env} setting..."
53
+ puts 'Using rails project config/wechat.yml default setting...'
55
54
  return config
56
55
  end
57
56
  end
@@ -1,24 +1,27 @@
1
- require 'rest_client'
1
+ require 'http'
2
2
 
3
3
  module Wechat
4
4
  class Client
5
- attr_reader :base, :timeout, :verify_ssl
5
+ attr_reader :base, :ssl_context
6
6
 
7
7
  def initialize(base, timeout, skip_verify_ssl)
8
8
  @base = base
9
- @timeout = timeout
10
- @verify_ssl = skip_verify_ssl ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
9
+ HTTP.timeout(:global, write: timeout, connect: timeout, read: timeout)
10
+ @ssl_context = OpenSSL::SSL::SSLContext.new
11
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_verify_ssl
11
12
  end
12
13
 
13
- def get(path, header = {})
14
- request(path, header) do |url, header|
15
- RestClient::Request.execute(method: :get, url: url, headers: header, timeout: timeout, verify_ssl: verify_ssl)
14
+ def get(path, get_header = {})
15
+ request(path, get_header) do |url, header|
16
+ params = header.delete(:params)
17
+ HTTP.headers(header).get(url, params: params, ssl_context: ssl_context)
16
18
  end
17
19
  end
18
20
 
19
- def post(path, payload, header = {})
20
- request(path, header) do |url, header|
21
- RestClient::Request.execute(method: :post, url: url, payload: payload, headers: header, timeout: timeout, verify_ssl: verify_ssl)
21
+ def post(path, payload, post_header = {})
22
+ request(path, post_header) do |url, header|
23
+ params = header.delete(:params)
24
+ HTTP.headers(header).post(url, params: params, body: payload, ssl_context: ssl_context)
22
25
  end
23
26
  end
24
27
 
@@ -30,7 +33,7 @@ module Wechat
30
33
  header.merge!(accept: :json)
31
34
  response = yield(url, header)
32
35
 
33
- fail "Request not OK, response code #{response.code}" if response.code != 200
36
+ fail "Request not OK, response status #{response.status}" if response.status != 200
34
37
  parse_response(response, as || :json) do |parse_as, data|
35
38
  break data unless parse_as == :json && data['errcode'].present?
36
39
 
@@ -65,7 +68,7 @@ module Wechat
65
68
  data = file
66
69
 
67
70
  when :json
68
- data = JSON.parse(response.body.gsub /[\u0000-\u001f]+/, '')
71
+ data = JSON.parse response.body.to_s.gsub(/[\u0000-\u001f]+/, '')
69
72
  else
70
73
  data = response.body
71
74
  end
@@ -90,12 +90,12 @@ module Wechat
90
90
  get 'department/list', params: { id: departmentid }
91
91
  end
92
92
 
93
- def user_simplelist(department_id, fetch_child = 0, status = 0)
94
- get 'user/simplelist', params: { department_id: department_id, fetch_child: fetch_child, status: status }
93
+ def user_simplelist(departmentid, fetch_child = 0, status = 0)
94
+ get 'user/simplelist', params: { departmentid: departmentid, fetch_child: fetch_child, status: status }
95
95
  end
96
96
 
97
- def user_list(department_id, fetch_child = 0, status = 0)
98
- get 'user/list', params: { department_id: department_id, fetch_child: fetch_child, status: status }
97
+ def user_list(departmentid, fetch_child = 0, status = 0)
98
+ get 'user/list', params: { departmentid: departmentid, fetch_child: fetch_child, status: status }
99
99
  end
100
100
 
101
101
  def tag_create(tagname, tagid = nil)
@@ -8,7 +8,7 @@ module Wechat
8
8
 
9
9
  included do
10
10
  # Rails 5 remove before_filter and skip_before_filter
11
- if respond_to?(:skip_before_action)
11
+ if defined?(:skip_before_action)
12
12
  # Rails 5 API mode won't define verify_authenticity_token
13
13
  skip_before_action :verify_authenticity_token unless defined?(:verify_authenticity_token)
14
14
  before_action :verify_signature, only: [:show, :create]
@@ -29,13 +29,7 @@ module Wechat
29
29
  if with.present?
30
30
  fail 'Only text, event, click, view, scan and batch_job can having :with parameters' unless [:text, :event, :click, :view, :scan, :batch_job].include?(message_type)
31
31
  config.merge!(with: with)
32
- if message_type == :scan
33
- if with.is_a?(String)
34
- self.known_scan_key_lists = with
35
- else
36
- fail 'on :scan only support string in parameter with, detail see https://github.com/Eric-Guo/wechat/issues/84'
37
- end
38
- end
32
+ self.known_scan_key_lists = with if message_type == :scan
39
33
  else
40
34
  fail 'Message type click, view, scan and batch_job must specify :with parameters' if [:click, :view, :scan, :batch_job].include?(message_type)
41
35
  end
@@ -47,8 +41,6 @@ module Wechat
47
41
  user_defined_view_responders(with) << config
48
42
  when :batch_job
49
43
  user_defined_batch_job_responders(with) << config
50
- when :scan
51
- user_defined_scan_responders << config
52
44
  when :location
53
45
  user_defined_location_responders << config
54
46
  else
@@ -72,10 +64,6 @@ module Wechat
72
64
  @batch_job_responders[with] ||= []
73
65
  end
74
66
 
75
- def user_defined_scan_responders
76
- @scan_responders ||= []
77
- end
78
-
79
67
  def user_defined_location_responders
80
68
  @location_responders ||= []
81
69
  end
@@ -100,7 +88,7 @@ module Wechat
100
88
  elsif 'click' == message[:Event]
101
89
  yield(* match_responders(responders, message[:EventKey]))
102
90
  elsif known_scan_key_lists.include?(message[:EventKey])
103
- yield(* known_scan_with_match_responders(user_defined_scan_responders, message))
91
+ yield(* known_scan_with_match_responders(user_defined_responders(:scan), message))
104
92
  elsif 'batch_job_result' == message[:Event]
105
93
  yield(* user_defined_batch_job_responders(message[:BatchJob][:JobType]), message[:BatchJob])
106
94
  elsif 'location' == message[:Event]
@@ -2,7 +2,8 @@ require 'wechat/ticket/jsapi_base'
2
2
 
3
3
  module Wechat
4
4
  module Ticket
5
- class PublicJsapiTicket < JsapiBase
5
+ class JsapiTicket < JsapiBase
6
+ # refresh jsapi ticket
6
7
  def refresh
7
8
  data = client.get('ticket/getticket', params: { access_token: access_token.token, type: 'jsapi' })
8
9
  write_ticket_to_file(data)
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.6.10
4
+ version: 0.7.0
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: 2016-01-17 00:00:00.000000000 Z
12
+ date: 2016-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -60,19 +60,25 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: rest-client
63
+ name: http
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
66
69
  - - ">="
67
70
  - !ruby/object:Gem::Version
68
- version: '0'
71
+ version: 1.0.1
69
72
  type: :runtime
70
73
  prerelease: false
71
74
  version_requirements: !ruby/object:Gem::Requirement
72
75
  requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '1.0'
73
79
  - - ">="
74
80
  - !ruby/object:Gem::Version
75
- version: '0'
81
+ version: 1.0.1
76
82
  - !ruby/object:Gem::Dependency
77
83
  name: rspec-rails
78
84
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +136,7 @@ files:
130
136
  - lib/wechat/signature.rb
131
137
  - lib/wechat/ticket/corp_jsapi_ticket.rb
132
138
  - lib/wechat/ticket/jsapi_base.rb
133
- - lib/wechat/ticket/public_jsapi_ticket.rb
139
+ - lib/wechat/ticket/jsapi_ticket.rb
134
140
  - lib/wechat/token/access_token_base.rb
135
141
  - lib/wechat/token/corp_access_token.rb
136
142
  - lib/wechat/token/public_access_token.rb
@@ -139,14 +145,12 @@ licenses:
139
145
  - MIT
140
146
  metadata: {}
141
147
  post_install_message: |-
142
- ***************************** WeChat Notice *****************************
143
- Last version of v6 series, v7 relay on http gems and performance improved.
144
-
145
- 1. Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE'`
148
+ *****WECHAT BREAK CHANGE*****
149
+ 1. Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE' `
146
150
  instead of previous `on :event, with: 'BINDING_QR_CODE' `.
147
151
  2. Batch job using new syntax `on :batch_job, with: 'replace_user' `
148
152
  instead of previous `on :event, with: 'replace_user' `.
149
- ***************************************************************************
153
+ *****************************
150
154
  rdoc_options: []
151
155
  require_paths:
152
156
  - lib