wework 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0fbabd57cb7bd9087631129ecbba3fcd26cb507
4
- data.tar.gz: c398798ee29911574473e39862849a5b87cfa44c
3
+ metadata.gz: 717cb7ed89b19797fdac7c6a077cf73ed7ced467
4
+ data.tar.gz: 2958df54c9332520cdc5dec16f7405864c8ebf7d
5
5
  SHA512:
6
- metadata.gz: 69b73d6d95cb9cab62a436c984183cfabac591c6c6762dab48b29f9c0012c7d1906db55ad76058cfed7cfcd35a88d519b4d5510675913ba12d16896d94f7d427
7
- data.tar.gz: 718901cccc7dd9a7b837173c22e80a847336822823ec111ec016735a576919f38c03e19d97f893937baa2ee36e9dc9d1e1fffd7ae144c964417a5c4eabcb8620
6
+ metadata.gz: 4baa61653bc4804a29d773b961da60fdde11370dfc7326086284f50e03306cfea3bcd06247e0d6319b6f7fa5ec93cc129c5c80a8c67701214ef887de68a1ee5c
7
+ data.tar.gz: 4a59d08dc5eb7f48837b27abda0b5b81bf3ec9eccb1543d215ac7e89b1d032a2e9402e37b6935717cf7e1cc0b347ded062a74766b107afdabc6908f1d9dc2796
data/lib/wework/config.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module Wework
2
2
 
3
3
  class << self
4
- attr_accessor :config
5
4
  def configure
6
5
  yield config
7
6
  end
@@ -0,0 +1,39 @@
1
+ module Wework
2
+ class Provider
3
+ include Wework::Cipher
4
+
5
+ attr_accessor :corp_id, :provider_secret, :encoding_aes_key, :token
6
+
7
+ def initialize(options={})
8
+ @corp_id = options[:corp_id]
9
+ @provider_secret = options[:provider_secret]
10
+ @encoding_aes_key = options[:encoding_aes_key]
11
+ @token = options[:token]
12
+ end
13
+
14
+ def msg_decrypt msg
15
+ unpack(decrypt(Base64.decode64(msg), self.encoding_aes_key))[0]
16
+ end
17
+
18
+ def msg_encrypt msg
19
+ Base64.strict_encode64(encrypt(pack(msg, self.corp_id), self.encoding_aes_key))
20
+ end
21
+
22
+ def signature(timestamp, nonce, encrypt)
23
+ array = [self.token, timestamp, nonce]
24
+ array << encrypt unless encrypt.nil?
25
+ dev_msg_signature = array.compact.collect(&:to_s).sort.join
26
+ Digest::SHA1.hexdigest(dev_msg_signature)
27
+ end
28
+
29
+ def generate_xml(msg, timestamp, nonce)
30
+ encrypt = msg_encrypt(msg)
31
+ {
32
+ Encrypt: encrypt,
33
+ MsgSignature: signature(timestamp, nonce, encrypt),
34
+ TimeStamp: timestamp,
35
+ Nonce: nonce
36
+ }.to_xml(root: 'xml', children: 'item', skip_instruct: true, skip_types: true)
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Wework
2
- VERSION = '0.2.9'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - seandong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -126,6 +126,7 @@ files:
126
126
  - lib/wework/global_code.rb
127
127
  - lib/wework/js_ticket/redis_store.rb
128
128
  - lib/wework/js_ticket/store.rb
129
+ - lib/wework/provider.rb
129
130
  - lib/wework/request.rb
130
131
  - lib/wework/token/redis_store.rb
131
132
  - lib/wework/token/store.rb