wework 0.1.4 → 0.1.6

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: 2edfd8447ee2705141dc3e3b9f794ef762e0a52e
4
- data.tar.gz: d24518f8cd4da0e921b3b4c0ad73894872569845
3
+ metadata.gz: 714896d468c99ed325dfa1b8e94afd4ad6de85a8
4
+ data.tar.gz: ca5b3a044abd35673167c57033e8efbc554b8cb5
5
5
  SHA512:
6
- metadata.gz: ce2c7829cbdedd5aab33764a7285820e169ed9ba299a4b7710f2a3199e2e76c48536a12a635ac4e31a73f22a39c5a52c37c2c55f9401665af839a41dea78b8cf
7
- data.tar.gz: 29d325d1cd6aba6e2d9b2715f1b402e4e5c703a296db776d06f89327df17f57fc9c25844d8364a4f50e41f76ffe767eb51700e1e9c784a61a9f8859bc1892ca8
6
+ metadata.gz: efe9dabd28e852f5082311c9116cfef327d36f007a2c3bd17c47f03b5df57e0cd6c16e21245c81ee640293923a63c0ce3f47a5e57321f071bf0a01315ca85ea4
7
+ data.tar.gz: 02e82e258a1b8be84959777890007f5d29051093eadc5bb53bc108fffab60eb65503d1314e6233c3686885e81de33af7213a863a0b52d8721c961d3c6d1cf990
@@ -13,8 +13,8 @@ require 'wework/api/contact'
13
13
  module Wework
14
14
  API_ENDPOINT = 'https://qyapi.weixin.qq.com/cgi-bin/'.freeze
15
15
  AUTHORIZE_ENDPOINT = 'https://open.weixin.qq.com/connect/oauth2/authorize'.freeze
16
- ACCESS_TOKEN_PREFIX = 'TOKEN'.freeze
17
- JSAPI_TOKEN_PREFIX = 'JST'.freeze
16
+ ACCESS_TOKEN_PREFIX = 'WX_TOKEN'.freeze
17
+ JSAPI_TOKEN_PREFIX = 'WX_JST'.freeze
18
18
  CONTACT_AGENT_ID = 'CONTACT'.freeze
19
19
  HTTP_OK_STATUS = [200, 201].freeze
20
20
  SUCCESS_CODE = 0
@@ -26,6 +26,10 @@ module Wework
26
26
  @request ||= Wework::Request.new(API_ENDPOINT, false)
27
27
  end
28
28
 
29
+ def valid?
30
+ access_token.present?
31
+ end
32
+
29
33
  def get(path, headers = {})
30
34
  with_access_token(headers[:params]) do |params|
31
35
  request.get path, headers.merge(params: params)
@@ -9,7 +9,7 @@ module Wework
9
9
 
10
10
  def jsapi_ticket
11
11
  super
12
- redis.hget(key, "jsapi_ticket")
12
+ redis.hget(key, "ticket")
13
13
  end
14
14
 
15
15
  def expired?
@@ -18,14 +18,16 @@ module Wework
18
18
 
19
19
  def refresh_token
20
20
  result = super
21
- expires_at = Time.now.to_i + result['expires_in'].to_i - 100
22
- redis.hmset(
23
- key,
24
- "jsapi_ticket", result['ticket'],
25
- "expires_at", expires_at
26
- )
27
-
28
- redis.expireat(key, expires_at)
21
+ if result.success?
22
+ expires_at = Time.now.to_i + result.expires_in.to_i - 100
23
+ redis.hmset(
24
+ key,
25
+ "ticket", result.ticket,
26
+ "expires_at", expires_at
27
+ )
28
+
29
+ redis.expireat(key, expires_at)
30
+ end
29
31
  end
30
32
 
31
33
  private
@@ -18,15 +18,16 @@ module Wework
18
18
 
19
19
  def refresh_token
20
20
  result = super
21
-
22
- expires_at = Time.now.to_i + result['expires_in'].to_i - 100
23
- redis.hmset(
24
- key,
25
- "access_token", result['access_token'],
26
- "expires_at", expires_at
27
- )
28
-
29
- redis.expireat(key, expires_at)
21
+ if result.success?
22
+ expires_at = Time.now.to_i + result.expires_in.to_i - 100
23
+ redis.hmset(
24
+ key,
25
+ "access_token", result.access_token,
26
+ "expires_at", expires_at
27
+ )
28
+
29
+ redis.expireat(key, expires_at)
30
+ end
30
31
  end
31
32
 
32
33
  private
@@ -1,3 +1,3 @@
1
1
  module Wework
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.6'.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.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - seandong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http