Class: Lark::Api

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/lark/api.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Api

Returns a new instance of Api.



27
28
29
30
31
32
33
34
35
# File 'lib/lark/api.rb', line 27

def initialize(options = {})
  @app_id = options.delete(:app_id) || Lark.config.default_app_id
  @app_secret = options.delete(:app_secret) || Lark.config.default_app_secret
  raise AppNotConfigException if @app_id.nil? || @app_id.empty?

  @tenant_key = options.delete(:tenant_key)
  @isv = options.delete(:isv) || Lark.config.default_isv
  @options = options
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



25
26
27
# File 'lib/lark/api.rb', line 25

def app_id
  @app_id
end

#app_secretObject (readonly)

Returns the value of attribute app_secret.



25
26
27
# File 'lib/lark/api.rb', line 25

def app_secret
  @app_secret
end

#isvObject (readonly)

Returns the value of attribute isv.



25
26
27
# File 'lib/lark/api.rb', line 25

def isv
  @isv
end

#optionsObject (readonly)

Returns the value of attribute options.



25
26
27
# File 'lib/lark/api.rb', line 25

def options
  @options
end

#tenant_keyObject (readonly)

Returns the value of attribute tenant_key.



25
26
27
# File 'lib/lark/api.rb', line 25

def tenant_key
  @tenant_key
end

Class Method Details

.defaultObject



108
109
110
111
112
113
114
# File 'lib/lark/api.rb', line 108

def default
  @default ||= new(
    app_id: Lark.config.default_app_id,
    app_secret: Lark.config.default_app_secret,
    isv: Lark.config.default_isv
  )
end

Instance Method Details

#app_access_tokenObject



71
72
73
# File 'lib/lark/api.rb', line 71

def app_access_token
  app_token_store.token
end

#app_ticketObject



67
68
69
# File 'lib/lark/api.rb', line 67

def app_ticket
  Lark.redis.get "APP_TICKET_#{app_id}"
end

#app_ticket=(new_ticket) ⇒ Object



63
64
65
# File 'lib/lark/api.rb', line 63

def app_ticket=(new_ticket)
  Lark.redis.set "APP_TICKET_#{app_id}", new_ticket
end

#get(path, headers = {}) ⇒ Object



45
46
47
48
49
# File 'lib/lark/api.rb', line 45

def get(path, headers = {})
  with_token(headers) do |headers_with_token|
    request.get path, headers_with_token
  end
end

#post(path, payload, headers = {}) ⇒ Object



51
52
53
54
55
# File 'lib/lark/api.rb', line 51

def post(path, payload, headers = {})
  with_token(headers) do |headers_with_token|
    request.post path, payload, headers_with_token
  end
end

#post_file(path, file, headers = {}) ⇒ Object



57
58
59
60
61
# File 'lib/lark/api.rb', line 57

def post_file(path, file, headers = {})
  with_token(headers) do |headers_with_token|
    request.post_file path, file, headers_with_token
  end
end

#requestObject



41
42
43
# File 'lib/lark/api.rb', line 41

def request
  @request ||= Lark::Request.new
end

#tenant_access_tokenObject



75
76
77
# File 'lib/lark/api.rb', line 75

def tenant_access_token
  tenant_token_store.token
end

#valid?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/lark/api.rb', line 37

def valid?
  app_token_store.valid? && tenant_token_store.valid?
end