Class: EvoleapLicensing::SessionState

Inherits:
Object
  • Object
show all
Defined in:
lib/evoleap_licensing/state/session_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ SessionState

Returns a new instance of SessionState.



9
10
11
12
13
14
15
16
17
18
# File 'lib/evoleap_licensing/state/session_state.rb', line 9

def initialize(hash = nil)
  hash = (hash || {}).transform_keys(&:to_s)
  @auth_token = hash["auth_token"]
  @session_key = hash["session_key"]
  @session_duration = hash["session_duration"]
  @features = hash["features"] || []
  @feature_groups = hash["feature_groups"] || []
  @components = hash["components"] || []
  @component_entitlements = hash["component_entitlements"] || []
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



5
6
7
# File 'lib/evoleap_licensing/state/session_state.rb', line 5

def auth_token
  @auth_token
end

#component_entitlementsObject

Returns the value of attribute component_entitlements.



5
6
7
# File 'lib/evoleap_licensing/state/session_state.rb', line 5

def component_entitlements
  @component_entitlements
end

#componentsObject

Returns the value of attribute components.



5
6
7
# File 'lib/evoleap_licensing/state/session_state.rb', line 5

def components
  @components
end

#feature_groupsObject

Returns the value of attribute feature_groups.



5
6
7
# File 'lib/evoleap_licensing/state/session_state.rb', line 5

def feature_groups
  @feature_groups
end

#featuresObject

Returns the value of attribute features.



5
6
7
# File 'lib/evoleap_licensing/state/session_state.rb', line 5

def features
  @features
end

#session_durationObject

Returns the value of attribute session_duration.



5
6
7
# File 'lib/evoleap_licensing/state/session_state.rb', line 5

def session_duration
  @session_duration
end

#session_keyObject

Returns the value of attribute session_key.



5
6
7
# File 'lib/evoleap_licensing/state/session_state.rb', line 5

def session_key
  @session_key
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/evoleap_licensing/state/session_state.rb', line 20

def active?
  !@auth_token.nil? && !@session_key.nil?
end

#clear!Object



24
25
26
27
28
29
30
31
32
# File 'lib/evoleap_licensing/state/session_state.rb', line 24

def clear!
  @auth_token = nil
  @session_key = nil
  @session_duration = nil
  @features = []
  @feature_groups = []
  @components = []
  @component_entitlements = []
end

#to_hObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/evoleap_licensing/state/session_state.rb', line 56

def to_h
  {
    "auth_token" => @auth_token,
    "session_key" => @session_key,
    "session_duration" => @session_duration,
    "features" => @features,
    "feature_groups" => @feature_groups,
    "components" => @components,
    "component_entitlements" => @component_entitlements
  }
end

#update_components_from_response(response) ⇒ Object



51
52
53
54
# File 'lib/evoleap_licensing/state/session_state.rb', line 51

def update_components_from_response(response)
  @components = response["components"] if response["components"]
  @component_entitlements = response["component_entitlements"] if response["component_entitlements"]
end

#update_from_extend_response(response) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/evoleap_licensing/state/session_state.rb', line 43

def update_from_extend_response(response)
  @auth_token = response["token"] if response["token"]
  @session_duration = response["session_duration"] if response["session_duration"]
  @features = response["features"] if response["features"]
  @feature_groups = response["feature_groups"] if response["feature_groups"]
  update_components_from_response(response)
end

#update_from_session_response(response) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/evoleap_licensing/state/session_state.rb', line 34

def update_from_session_response(response)
  @auth_token = response["token"] if response["token"]
  @session_key = response["session_key"] if response["session_key"]
  @session_duration = response["session_duration"] if response["session_duration"]
  @features = response["features"] if response["features"]
  @feature_groups = response["feature_groups"] if response["feature_groups"]
  update_components_from_response(response)
end