Class: Dingtalk::Api::New

Inherits:
Base
  • Object
show all
Includes:
Inner::New
Defined in:
app/apis/dingtalk/api/new.rb

Constant Summary collapse

BASE =
'https://api.dingtalk.com/'

Instance Attribute Summary

Attributes inherited from Base

#app, #client

Instance Method Summary collapse

Methods inherited from Base

#initialize, #jsapi_ticket

Constructor Details

This class inherits a constructor from Dingtalk::Api::Base

Instance Method Details

#base_hostObject



18
19
20
# File 'app/apis/dingtalk/api/new.rb', line 18

def base_host
  BASE
end

#get(path, params: {}, headers: {}, base: base_host, as: nil) ⇒ Object



22
23
24
25
26
# File 'app/apis/dingtalk/api/new.rb', line 22

def get(path, params: {}, headers: {}, base: base_host, as: nil)
  with_access_token(headers) do |with_token_headers|
    @client.get path, headers: with_token_headers, params: params, base: base, as: as
  end
end

#post(path, params: {}, headers: {}, base: base_host, **payload) ⇒ Object



28
29
30
31
32
# File 'app/apis/dingtalk/api/new.rb', line 28

def post(path, params: {}, headers: {}, base: base_host, **payload)
  with_access_token(headers) do |with_token_headers|
    @client.post path, payload.to_json, headers: with_token_headers, params: params, base: base
  end
end

#post_file(path, file, params: {}, headers: {}, base: base_host) ⇒ Object



34
35
36
37
38
# File 'app/apis/dingtalk/api/new.rb', line 34

def post_file(path, file, params: {}, headers: {}, base: base_host)
  with_access_token(headers) do |with_token_headers|
    @client.post_file path, file, headers: with_token_headers, params: params, base: base
  end
end

#tokenObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/apis/dingtalk/api/new.rb', line 6

def token
  payload = {
    appKey: app.app_key,
    appSecret: app.app_secret,
  }
  r = @client.post 'v1.0/oauth2/accessToken', payload.to_json, base: BASE
  {
    'access_token' => r['accessToken'],
    'expires_in' => r['expireIn']
  }
end