Class: EvoleapLicensing::UserControlManager
- Inherits:
-
Object
- Object
- EvoleapLicensing::UserControlManager
- Defined in:
- lib/evoleap_licensing/user_control_manager.rb
Instance Attribute Summary collapse
-
#instance_id ⇒ Object
readonly
Returns the value of attribute instance_id.
-
#product_id ⇒ Object
readonly
Returns the value of attribute product_id.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
-
#session_state ⇒ Object
readonly
Returns the value of attribute session_state.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#user_state ⇒ Object
readonly
Returns the value of attribute user_state.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#check_in_components(*component_names) ⇒ Object
Check in named components.
-
#check_out_components(*component_names) ⇒ Object
Check out named components for the active session.
-
#components_status ⇒ Object
Get status of all components.
-
#end_session ⇒ Object
End the active session.
-
#initialize(product_id:, version:, instance_id:, public_key:, strategy: nil, user_state: nil, session_state: nil) ⇒ UserControlManager
constructor
A new instance of UserControlManager.
-
#license_info ⇒ Object
Get license info for the active session.
-
#register(user_info:, user_identity:) ⇒ Object
Register a user against the server instance.
-
#validate_session(user_identity:, requested_duration: nil) ⇒ Object
Begin or extend a user session.
-
#web_client=(client) ⇒ Object
For testing: allow injecting a custom web client.
Constructor Details
#initialize(product_id:, version:, instance_id:, public_key:, strategy: nil, user_state: nil, session_state: nil) ⇒ UserControlManager
Returns a new instance of UserControlManager.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 8 def initialize(product_id:, version:, instance_id:, public_key:, strategy: nil, user_state: nil, session_state: nil) @product_id = product_id @version = version @instance_id = instance_id @public_key = public_key @strategy = strategy || ControlStrategy.default @user_state = user_state || UserState.new @session_state = session_state || SessionState.new @client = WebClient.new end |
Instance Attribute Details
#instance_id ⇒ Object (readonly)
Returns the value of attribute instance_id.
5 6 7 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 5 def instance_id @instance_id end |
#product_id ⇒ Object (readonly)
Returns the value of attribute product_id.
5 6 7 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 5 def product_id @product_id end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
5 6 7 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 5 def public_key @public_key end |
#session_state ⇒ Object (readonly)
Returns the value of attribute session_state.
5 6 7 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 5 def session_state @session_state end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
5 6 7 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 5 def strategy @strategy end |
#user_state ⇒ Object (readonly)
Returns the value of attribute user_state.
5 6 7 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 5 def user_state @user_state end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 5 def version @version end |
Instance Method Details
#check_in_components(*component_names) ⇒ Object
Check in named components. Returns a ComponentCheckinResult.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 89 def check_in_components(*component_names) raise NoActiveSessionError, "No active session" unless @session_state.active? response = WebService.check_in_components( product_id: @product_id, auth_token: @session_state.auth_token, session_key: @session_state.session_key, component_names: component_names.flatten, public_key: @public_key, client: @client ) if response["status"] == ValidationStatus::SUCCESS @session_state.update_components_from_response(response) ComponentCheckinResult.new(success: true) else ComponentCheckinResult.new( success: false, failure_reason: InvalidReason.from_validation_status(response["status"]) ) end end |
#check_out_components(*component_names) ⇒ Object
Check out named components for the active session. Returns a ComponentCheckoutResult.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 60 def check_out_components(*component_names) raise NoActiveSessionError, "No active session" unless @session_state.active? response = WebService.check_out_components( product_id: @product_id, auth_token: @session_state.auth_token, session_key: @session_state.session_key, component_names: component_names.flatten, public_key: @public_key, client: @client ) if response["status"] == ValidationStatus::SUCCESS @session_state.update_components_from_response(response) ComponentCheckoutResult.new( success: true, components: response["components"] || [], component_entitlements: response["component_entitlements"] || [] ) else ComponentCheckoutResult.new( success: false, failure_reason: InvalidReason.from_validation_status(response["status"]) ) end end |
#components_status ⇒ Object
Get status of all components. Returns a ComponentsStatus.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 114 def components_status raise NoActiveSessionError, "No active session" unless @session_state.active? response = WebService.components_status( product_id: @product_id, auth_token: @session_state.auth_token, session_key: @session_state.session_key, public_key: @public_key, client: @client ) if response["status"] == ValidationStatus::SUCCESS ComponentsStatus.new( success: true, components: response["components"] || [], component_entitlements: response["component_entitlements"] || [] ) else ComponentsStatus.new( success: false, error_message: response["error"] ) end end |
#end_session ⇒ Object
End the active session.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 43 def end_session raise NoActiveSessionError, "No active session to end" unless @session_state.active? response = WebService.end_session( product_id: @product_id, auth_token: @session_state.auth_token, session_key: @session_state.session_key, public_key: @public_key, client: @client ) @session_state.clear! !response.key?("error") end |
#license_info ⇒ Object
Get license info for the active session. Returns a LicenseInfo.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 141 def license_info raise NoActiveSessionError, "No active session" unless @session_state.active? response = WebService.get_license_info( product_id: @product_id, auth_token: @session_state.auth_token, session_key: @session_state.session_key, public_key: @public_key, client: @client ) if response["status"] == ValidationStatus::SUCCESS LicenseInfo.new( success: true, owner_name: response["owner_name"], owner_logo_url: response["owner_logo_url"], expiry: response["expiry"] ) else LicenseInfo.new( success: false, error_message: response["error"] ) end end |
#register(user_info:, user_identity:) ⇒ Object
Register a user against the server instance. Returns a RegistrationResult.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 22 def register(user_info:, user_identity:) ControlManagerHelper.register(@user_state) do WebService.register_user( product_id: @product_id, instance_id: @instance_id, user_info: user_info, user_identity: user_identity.to_api_format, public_key: @public_key, client: @client ) end end |
#validate_session(user_identity:, requested_duration: nil) ⇒ Object
Begin or extend a user session. Returns a SessionValidity.
37 38 39 40 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 37 def validate_session(user_identity:, requested_duration: nil) ControlManagerHelper.validate_session(@strategy, @user_state, @session_state, -> { make_session_call(user_identity, requested_duration) }) end |
#web_client=(client) ⇒ Object
For testing: allow injecting a custom web client
168 169 170 |
# File 'lib/evoleap_licensing/user_control_manager.rb', line 168 def web_client=(client) @client = client end |