Class: Dingtalk::Api::Base

Inherits:
Object
  • Object
show all
Defined in:
app/apis/dingtalk/api/base.rb

Direct Known Subclasses

New, Normal

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#appObject (readonly)

Returns the value of attribute app.



4
5
6
# File 'app/apis/dingtalk/api/base.rb', line 4

def app
  @app
end

#clientObject (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_hostObject



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_ticketObject



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

#tokenObject



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