Class: Virgil::SDK::HighLevel::VirgilCardManager
- Inherits:
-
Object
- Object
- Virgil::SDK::HighLevel::VirgilCardManager
- Defined in:
- lib/virgil/sdk/high_level/virgil_card_manager.rb
Overview
This class provides a list of methods to manage the VirgilCard entities.
Defined Under Namespace
Classes: AccessTokenException, AppCredentialsException, CardArray
Instance Method Summary collapse
-
#create(identity, owner_key, custom_data = {}) ⇒ VirgilCard
Creates a new Virgil Card that is representing user's Public key and information.
-
#create_global(identity:, identity_type:, owner_key:, custom_data: {}) ⇒ VirgilCard
Creates a new Global Virgil Card that is representing user's Public key and information.
-
#find(*identities) ⇒ Array<VirgilCard>
Find Virgil cards by specified identities in application scope.
-
#find_global(identity_type, *identities) ⇒ Array<VirgilCard>
Find Global Virgil cards by specified identity type and identities.
-
#get(card_id) ⇒ VirgilCard
Get a card from Virgil Security services by specified Card ID.
-
#import(exported_card) ⇒ VirgilCard
Create new Card from base64-encoded json representation of card's content_snapshot and meta.
-
#initialize(context) ⇒ VirgilCardManager
constructor
Initializes a new instance of the VirgilCardManager class.
-
#publish(card) ⇒ Object
Publish synchronously a card into application Virgil Services scope.
-
#publish_global(card, validation_token) ⇒ Object
Publish a global card into application Virgil Services scope.
-
#revoke(card) ⇒ Object
Revoke a card from Virgil Services.
-
#revoke_global(global_card, key_pair, validation_token) ⇒ Object
Revoke a Global card from Virgil Services.
Constructor Details
#initialize(context) ⇒ VirgilCardManager
Initializes a new instance of the Virgil::SDK::HighLevel::VirgilCardManager class.
48 49 50 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 48 def initialize(context) @context = context end |
Instance Method Details
#create(identity, owner_key, custom_data = {}) ⇒ VirgilCard
Creates a new Virgil Card that is representing user's Public key and information.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 133 def create(identity, owner_key, custom_data={}) card = context.client.new_card( identity, VirgilIdentity::UNKNOWN, owner_key.private_key, custom_data ) VirgilCard.new(context: context, card: card) end |
#create_global(identity:, identity_type:, owner_key:, custom_data: {}) ⇒ VirgilCard
Creates a new Global Virgil Card that is representing user's Public key and information.
165 166 167 168 169 170 171 172 173 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 165 def create_global(identity:, identity_type:, owner_key:, custom_data: {}) card = context.client.new_global_card( identity, identity_type, owner_key.private_key, custom_data ) VirgilCard.new(context: context, card: card) end |
#find(*identities) ⇒ Array<VirgilCard>
Find Virgil cards by specified identities in application scope.
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 242 def find(*identities) raise AccessTokenException unless (context && context.access_token) validate_identities_param(identities) cards = context.client.search_cards_by_identities(*identities) virgil_cards = cards.map { |v| VirgilCard.new(context: context, card: v) } CardArray.new(virgil_cards) end |
#find_global(identity_type, *identities) ⇒ Array<VirgilCard>
Find Global Virgil cards by specified identity type and identities.
268 269 270 271 272 273 274 275 276 277 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 268 def find_global(identity_type, *identities) validate_identities_param(identities) cards = context.client.search_cards_by_criteria( Client::SearchCriteria.new(identities, identity_type, Client::Card::GLOBAL) ) virgil_global_cards = cards.map { |v| VirgilCard.new(context: context, card: v) } CardArray.new(virgil_global_cards) end |
#get(card_id) ⇒ VirgilCard
Get a card from Virgil Security services by specified Card ID.
228 229 230 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 228 def get(card_id) VirgilCard.new(context: context, card: context.client.get_card(card_id)) end |
#import(exported_card) ⇒ VirgilCard
Create new Card from base64-encoded json representation of card's content_snapshot and meta.
354 355 356 357 358 359 360 361 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 354 def import(exported_card) request = Client::Requests::CreateCardRequest.import(exported_card) VirgilCard.new( context: self.context, card: Client::Card.from_request_model(request.request_model) ) end |
#publish(card) ⇒ Object
Publish synchronously a card into application Virgil Services scope.
191 192 193 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 191 def publish(card) card.publish end |
#publish_global(card, validation_token) ⇒ Object
Publish a global card into application Virgil Services scope.
215 216 217 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 215 def publish_global(card, validation_token) card.publish_as_global(validation_token) end |
#revoke(card) ⇒ Object
Revoke a card from Virgil Services.
298 299 300 301 302 303 304 305 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 298 def revoke(card) validate_app_credentials context.client.revoke_card( card.id, context.credentials.app_id, context.credentials.app_key(context.crypto)) end |
#revoke_global(global_card, key_pair, validation_token) ⇒ Object
Revoke a Global card from Virgil Services.
335 336 337 338 |
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 335 def revoke_global(global_card, key_pair, validation_token) context.client.revoke_global_card(global_card.id, key_pair, validation_token) end |