Class: Gitlab::ChatNameToken

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/chat_name_token.rb

Constant Summary collapse

TOKEN_LENGTH =
50
EXPIRY_TIME =
10.minutes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = new_token) ⇒ ChatNameToken

Returns a new instance of ChatNameToken.


12
13
14
# File 'lib/gitlab/chat_name_token.rb', line 12

def initialize(token = new_token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token


7
8
9
# File 'lib/gitlab/chat_name_token.rb', line 7

def token
  @token
end

Instance Method Details

#deleteObject


31
32
33
34
35
# File 'lib/gitlab/chat_name_token.rb', line 31

def delete
  Gitlab::Redis::SharedState.with do |redis|
    redis.del(redis_shared_state_key)
  end
end

#getObject


16
17
18
19
20
21
# File 'lib/gitlab/chat_name_token.rb', line 16

def get
  Gitlab::Redis::SharedState.with do |redis|
    data = redis.get(redis_shared_state_key)
    Gitlab::Json.parse(data, symbolize_names: true) if data
  end
end

#store!(params) ⇒ Object


23
24
25
26
27
28
29
# File 'lib/gitlab/chat_name_token.rb', line 23

def store!(params)
  Gitlab::Redis::SharedState.with do |redis|
    params = params.to_json
    redis.set(redis_shared_state_key, params, ex: EXPIRY_TIME)
    token
  end
end