Class: Dingtalk::Client
- Inherits:
-
Object
- Object
- Dingtalk::Client
- Includes:
- Api::Department, Api::Message, Api::Microapp, Api::User, EcoApi::Role, MonitorMixin
- Defined in:
- lib/dingtalk/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#app_id ⇒ Object
Time.now + expires_in.
-
#app_secret ⇒ Object
Time.now + expires_in.
-
#expired_at ⇒ Object
Time.now + expires_in.
-
#redis_key ⇒ Object
Returns the value of attribute redis_key.
Instance Method Summary collapse
- #get_access_token ⇒ Object
- #http_get(url, url_params = {}, endpoint = "plain") ⇒ Object
- #http_post(url, post_body = {}, url_params = {}, endpoint = "plain") ⇒ Object
-
#initialize(app_id, app_secret, options = {}) ⇒ Client
constructor
A new instance of Client.
- #is_valid? ⇒ Boolean
- #token_store ⇒ Object
Methods included from EcoApi::Role
Methods included from Api::Message
#send_link, #send_oa, #send_text
Methods included from Api::Microapp
Methods included from Api::User
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, ={}) @app_id = app_id @app_secret = app_secret @expired_at = Time.now.to_i @redis_key = security_redis_key([:redis_key] || "dingtalk_#{app_id}") super() end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
15 16 17 |
# File 'lib/dingtalk/client.rb', line 15 def access_token @access_token end |
#app_id ⇒ Object
Time.now + expires_in
14 15 16 |
# File 'lib/dingtalk/client.rb', line 14 def app_id @app_id end |
#app_secret ⇒ Object
Time.now + expires_in
14 15 16 |
# File 'lib/dingtalk/client.rb', line 14 def app_secret @app_secret end |
#expired_at ⇒ Object
Time.now + expires_in
14 15 16 |
# File 'lib/dingtalk/client.rb', line 14 def expired_at @expired_at end |
#redis_key ⇒ Object
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_token ⇒ Object
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
29 30 31 |
# File 'lib/dingtalk/client.rb', line 29 def is_valid? token_store.valid? end |