Class: Dingtalk::Api::Base
- Inherits:
-
Object
- Object
- Dingtalk::Api::Base
- Defined in:
- app/apis/dingtalk/api/base.rb
Constant Summary collapse
- BASE =
'https://oapi.dingtalk.com/'
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #base_host ⇒ Object
- #get(path, params: {}, headers: {}, base: base_host, as: nil) ⇒ Object
-
#initialize(app) ⇒ Base
constructor
A new instance of Base.
- #jsapi_ticket ⇒ Object
- #post(path, params: {}, headers: {}, base: base_host, **payload) ⇒ Object
- #post_file(path, file, params: {}, headers: {}, base: base_host) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(app) ⇒ Base
Returns a new instance of Base.
6 7 8 9 |
# File 'app/apis/dingtalk/api/base.rb', line 6 def initialize(app) @app = app @client = Dingtalk::HttpClient.new end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
4 5 6 |
# File 'app/apis/dingtalk/api/base.rb', line 4 def app @app end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'app/apis/dingtalk/api/base.rb', line 4 def client @client end |
Instance Method Details
#base_host ⇒ Object
19 20 21 |
# File 'app/apis/dingtalk/api/base.rb', line 19 def base_host BASE end |
#get(path, params: {}, headers: {}, base: base_host, as: nil) ⇒ Object
23 24 25 26 27 |
# File 'app/apis/dingtalk/api/base.rb', line 23 def get(path, params: {}, headers: {}, base: base_host, as: nil) with_access_token(params) do |with_token_params| @client.get path, headers: headers, params: with_token_params, base: base, as: as end end |
#jsapi_ticket ⇒ Object
15 16 17 |
# File 'app/apis/dingtalk/api/base.rb', line 15 def jsapi_ticket get 'get_jsapi_ticket', base: BASE end |
#post(path, params: {}, headers: {}, base: base_host, **payload) ⇒ Object
29 30 31 32 33 |
# File 'app/apis/dingtalk/api/base.rb', line 29 def post(path, params: {}, headers: {}, base: base_host, **payload) with_access_token(params) do |with_token_params| @client.post path, payload.to_json, headers: headers, params: with_token_params, base: base end end |
#post_file(path, file, params: {}, headers: {}, base: base_host) ⇒ Object
35 36 37 38 39 |
# File 'app/apis/dingtalk/api/base.rb', line 35 def post_file(path, file, params: {}, headers: {}, base: base_host) with_access_token(params) do |with_token_params| @client.post_file path, file, headers: headers, params: with_token_params, base: base end end |
#token ⇒ Object
11 12 13 |
# File 'app/apis/dingtalk/api/base.rb', line 11 def token @client.get 'gettoken', params: { appkey: app.app_key, appsecret: app.app_secret }, base: BASE end |