Class: Dingtalk::Client

Inherits:
Object
  • Object
show all
Includes:
Api::Department, Api::Message, Api::Microapp, Api::User, EcoApi::Role, MonitorMixin
Defined in:
lib/dingtalk/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EcoApi::Role

#role_list, #role_simplelist

Methods included from Api::Message

#send_link, #send_oa, #send_text

Methods included from Api::Microapp

#microapp_visible_scopes

Methods included from Api::User

#user_simplelist

Methods included from Api::Department

#get_department, #list_department

Constructor Details

#initialize(app_id, app_secret, options = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
# File 'lib/dingtalk/client.rb', line 17

def initialize(app_id, app_secret, options={})
  @app_id = app_id
  @app_secret = app_secret
  @expired_at = Time.now.to_i
  @redis_key = security_redis_key(options[:redis_key] || "dingtalk_#{app_id}")
  super()
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



15
16
17
# File 'lib/dingtalk/client.rb', line 15

def access_token
  @access_token
end

#app_idObject

Time.now + expires_in



14
15
16
# File 'lib/dingtalk/client.rb', line 14

def app_id
  @app_id
end

#app_secretObject

Time.now + expires_in



14
15
16
# File 'lib/dingtalk/client.rb', line 14

def app_secret
  @app_secret
end

#expired_atObject

Time.now + expires_in



14
15
16
# File 'lib/dingtalk/client.rb', line 14

def expired_at
  @expired_at
end

#redis_keyObject

Returns the value of attribute redis_key.



15
16
17
# File 'lib/dingtalk/client.rb', line 15

def redis_key
  @redis_key
end

Instance Method Details

#get_access_tokenObject



25
26
27
# File 'lib/dingtalk/client.rb', line 25

def get_access_token
  synchronize{ token_store.access_token }
end

#http_get(url, url_params = {}, endpoint = "plain") ⇒ Object



37
38
39
40
# File 'lib/dingtalk/client.rb', line 37

def http_get(url, url_params={}, endpoint="plain")
  url_params = endpoint == Dingtalk::ECO_ENDPOINT ? url_params.merge(eco_access_token_param) : url_params.merge(access_token_param)
  Dingtalk.http_get_without_token(url, url_params, endpoint)
end

#http_post(url, post_body = {}, url_params = {}, endpoint = "plain") ⇒ Object



42
43
44
45
# File 'lib/dingtalk/client.rb', line 42

def http_post(url, post_body={}, url_params={}, endpoint="plain")
  url_params = endpoint == Dingtalk::ECO_ENDPOINT ? eco_access_token_param.merge(url_params) : access_token_param.merge(url_params)
  Dingtalk.http_post_without_token(url, post_body, url_params, endpoint)
end

#is_valid?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/dingtalk/client.rb', line 29

def is_valid?
  token_store.valid?
end

#token_storeObject



33
34
35
# File 'lib/dingtalk/client.rb', line 33

def token_store
  Token::Store.init_with(self)
end