Commit 795147d0eb65cfd9c7a3cd0705c23a4d8c7f217d

Authored by lanrion
1 parent 809810ac
Exists in master

add synchronize for get_access_token

Showing 3 changed files with 7 additions and 3 deletions   Show diff stats
.rspec
1 1 --format documentation --color spec --drb
  2 +--require spec_helper
... ...
Gemfile
1   -source 'https://rubygems.org'
  1 +source 'https://ruby.taobao.org'
2 2  
3 3 group :test, :development do
4 4 gem 'rspec', '~> 3.1.0'
... ...
lib/qy_wechat_api/client.rb
1 1 # encoding: utf-8
2   -
  2 +require "monitor"
3 3 module QyWechatApi
4 4 class Client
  5 + include MonitorMixin
  6 +
5 7 attr_accessor :corp_id, :group_secret, :expired_at # Time.now + expires_in
6 8 attr_accessor :access_token, :redis_key, :storage, :custom_access_token
7 9  
... ... @@ -12,12 +14,13 @@ module QyWechatApi
12 14 @corp_id = corp_id
13 15 @redis_key = security_redis_key((redis_key || "qy_#{group_secret}"))
14 16 @storage = Storage.init_with(self)
  17 + super() # Monitor#initialize
15 18 end
16 19  
17 20 # return token
18 21 def get_access_token
19 22 return custom_access_token if custom_access_token.present?
20   - @storage.access_token
  23 + synchronize{ @storage.access_token }
21 24 end
22 25  
23 26 # 检查appid和app_secret是否有效。
... ...