xi_wechat_corp 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/xi_wechat_corp/callback.rb +4 -1
- data/lib/xi_wechat_corp/callback/grape.rb +28 -0
- data/lib/xi_wechat_corp/version.rb +1 -1
- metadata +2 -2
- data/lib/xi_wechat_corp/callback/grape_xml_parser.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea696c0f425a8c09f218831490f7066e0b1a8be6
|
4
|
+
data.tar.gz: cd8160b093ab9e98023d9a518bd98e6e0dbb1a5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f279c4577eefb16d2e8810a29001e7b9d9868ca4e19568ebdc49ba5fce29cdbbae889be8488e28a0c3cb41cdc08a44a91aff9bf6d4a389df268edd2902d0e7f
|
7
|
+
data.tar.gz: ac876379962b1bd3195be9bf17a9df6c0803c7f27aec20af5be6ce994f5e57b9f67b1eef3c58fe1931dff3602e7562302a024266e1dfa93abb2588e56d40619f
|
data/README.md
CHANGED
@@ -39,6 +39,20 @@ logic for `POST` requests. All post params can be get through rack env
|
|
39
39
|
`xi_wechat_corp.params`, including decrypted params. The handler just return
|
40
40
|
the plain XML, The middleware will encrypt response and sign it.
|
41
41
|
|
42
|
+
### Used in Grape
|
43
|
+
|
44
|
+
require 'xi_wechat_corp'
|
45
|
+
class MyAPI < Grape::API
|
46
|
+
use XiWechatCorp::Callback::Rack do |req|
|
47
|
+
corp_id 'wx1234'
|
48
|
+
token 'secret'
|
49
|
+
aes_key 'secret'
|
50
|
+
end
|
51
|
+
|
52
|
+
parser :xml, XiWechatCorp::Callback::Grape::Parser
|
53
|
+
formatter :xml, XiWechatCorp::Callback::Grape::Formatter
|
54
|
+
end
|
55
|
+
|
42
56
|
### Handle Callback Manually
|
43
57
|
|
44
58
|
Verify and decrypt Request
|
@@ -3,6 +3,9 @@ module XiWechatCorp
|
|
3
3
|
autoload :Request, 'xi_wechat_corp/callback/request'
|
4
4
|
autoload :Response, 'xi_wechat_corp/callback/response'
|
5
5
|
autoload :Rack, 'xi_wechat_corp/callback/rack'
|
6
|
-
|
6
|
+
module Grape
|
7
|
+
autoload :Parser, 'xi_wechat_corp/callback/grape'
|
8
|
+
autoload :Formatter, 'xi_wechat_corp/callback/grape'
|
9
|
+
end
|
7
10
|
end
|
8
11
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module XiWechatCorp
|
2
|
+
module Callback
|
3
|
+
module Grape
|
4
|
+
# Ensure that XiWechatCorp::Callback::Rack middleware has bee added.
|
5
|
+
#
|
6
|
+
# parser :xml, XiWechatCorp::Callback::Grape::Parser
|
7
|
+
module Parser
|
8
|
+
def self.call(object, env)
|
9
|
+
if env['xi_wechat_corp.params']
|
10
|
+
env['xi_wechat_corp.params']
|
11
|
+
else
|
12
|
+
Grape::Parser::Xml.call(object, env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Set this as the default XML formater in Grape
|
18
|
+
#
|
19
|
+
# formatter :xml, XiWechatCorp::Callback::Grape::Formatter
|
20
|
+
module Formatter
|
21
|
+
def self.call(object, env)
|
22
|
+
return object.to_xml(root: 'xml', skip_instruct: true, indent: 0) if object.respond_to?(:to_xml)
|
23
|
+
fail Grape::Exceptions::InvalidFormatter.new(object.class, 'xml')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xi_wechat_corp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Yang
|
@@ -186,7 +186,7 @@ files:
|
|
186
186
|
- lib/xi_wechat_corp/api/connection.rb
|
187
187
|
- lib/xi_wechat_corp/callback.rb
|
188
188
|
- lib/xi_wechat_corp/callback/config.rb
|
189
|
-
- lib/xi_wechat_corp/callback/
|
189
|
+
- lib/xi_wechat_corp/callback/grape.rb
|
190
190
|
- lib/xi_wechat_corp/callback/rack.rb
|
191
191
|
- lib/xi_wechat_corp/callback/request.rb
|
192
192
|
- lib/xi_wechat_corp/callback/response.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module XiWechatCorp
|
2
|
-
module Callback
|
3
|
-
# Ensure that XiWechatCorp::Callback::Rack middleware has bee added.
|
4
|
-
#
|
5
|
-
# parser :xml, XiWechatCorp::Callback::GrapeXmlParser
|
6
|
-
module GrapeXmlParser
|
7
|
-
class << self
|
8
|
-
def call(object, env)
|
9
|
-
if env['xi_wechat_corp.params']
|
10
|
-
env['xi_wechat_corp.params']
|
11
|
-
else
|
12
|
-
Grape::Parser::Xml.call(object, env)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|