Class: Huanxin::Base
- Inherits:
-
Object
- Object
- Huanxin::Base
- Defined in:
- lib/huanxin/base.rb
Direct Known Subclasses
Constant Summary collapse
- RAND_WORDS =
[('a'..'z'), (0..9), ['_','-']].map { |i| i.to_a }.flatten
Instance Method Summary collapse
-
#initialize(cache_client, org_name, app_name) ⇒ Base
constructor
RAND_WORDS = [(‘a’..‘z’), (‘A’..‘Z’), (0..9), [‘_’]].map { |i| i.to_a }.flatten 由于环信聊天接口会强制转换用户名成小写,所以最好不要包括大写字符,已经和他们沟通,他们不会修改.
Constructor Details
#initialize(cache_client, org_name, app_name) ⇒ Base
RAND_WORDS = [(‘a’..‘z’), (‘A’..‘Z’), (0..9), [‘_’]].map { |i| i.to_a }.flatten 由于环信聊天接口会强制转换用户名成小写,所以最好不要包括大写字符,已经和他们沟通,他们不会修改. cache_client 所有实现了 ActiveSupport::Cache::Store 的对象实例 如果是在rails里面使用,可以直接传递 Rails.cache
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/huanxin/base.rb', line 20 def initialize(cache_client, org_name, app_name) raise 'invalid cache client' if cache_client.nil? @client_id = Huanxin.config[:client_id] @client_secret = Huanxin.config[:client_secret] @base_url = Huanxin.config[:host] || 'https://a1.easemob.com' @username_len = Huanxin.config[:username_len] || 10 @password_len = Huanxin.config[:password_len] || 12 @org_name = org_name @app_name = app_name @cache = cache_client @head_url = "#{@base_url}/#{org_name}/#{app_name}" @token_cache_key = "_huanxin_auth_#{org_name}_#{app_name}_" end |