Class: Virgil::SDK::HighLevel::VirgilApi

Inherits:
Object
  • Object
show all
Defined in:
lib/virgil/sdk/high_level/virgil_api.rb

Overview

The VirgilApi class is a high-level API that provides easy access to Virgil Security services and allows to perform cryptographic operations by using two domain entities VirgilKey and VirgilCard. Where the VirgilKey is an entity that represents a user's Private key, and the VirgilCard is the entity that represents user's identity and a Public key.

Defined Under Namespace

Classes: VirgilApiAccessTokenException, VirgilApiException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token: nil, context: nil) ⇒ VirgilApi

Note:

The both of the arguments(access_token and context) are not required for actions with Global cards.

Initializes a new instance of the Virgil::SDK::HighLevel::VirgilApi class.

Examples:

Initializes a new instance for actions: get card, find card.

virgil = VirgilApi.new(access_token: "[YOUR_ACCESS_TOKEN_HERE]")

Initializes a new instance for actions: publish card, revoke card.

virgil = VirgilApi.new(context: VirgilContext.new(
    credentials: VirgilAppCredentials.new(
        access_token: "[YOUR_ACCESS_TOKEN_HERE]",
        app_id: "[YOUR_APP_ID_HERE]",
        app_key_data: VirgilBuffer.from_file("[YOUR_APP_KEY_PATH_HERE]"),
        app_key_password: "[YOUR_APP_KEY_PASSWORD_HERE]"))
)

Initializes a new instance for actions with global cards.

virgil = VirgilApi.new()

Parameters:

  • access_token: (String) (defaults to: nil)

    Retrieved string value from development deshboard that provides an authenticated secure access to the Virgil Security services. The access token also allows the API to associate your app requests with your Virgil Security developer’s account. It's not required if context with own access token has been set. It's required(only if context with own access token hasn't been set)

    for the following actions: get card, find card.
  • context: (VirgilContext) (defaults to: nil)

    Virgil Context that manages the VirgilApi dependencies during run time. It's required with defined Application credentials and own access_token for publishing and revoking card.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/virgil/sdk/high_level/virgil_api.rb', line 94

def initialize(access_token: nil, context: nil)

  if (access_token && context)
    raise VirgilApiAccessTokenException.new unless access_token == context.access_token
  end


  if context
    self.context = context
  else
    self.context = Virgil::SDK::HighLevel::VirgilContext.new(access_token: access_token)
  end

  self.keys = VirgilKeyManager.new(self.context)
  self.cards = VirgilCardManager.new(self.context)
end

Instance Attribute Details

#cardsVirgilCardManager

Virgil Card Manager that provides a work with VirgilCard entities.

Returns:



55
56
57
# File 'lib/virgil/sdk/high_level/virgil_api.rb', line 55

def cards
  @cards
end

#contextVirgilContext

Virgil Context that manages the VirgilApi dependencies during run time.

Returns:



47
48
49
# File 'lib/virgil/sdk/high_level/virgil_api.rb', line 47

def context
  @context
end

#keysVirgilKeyManager

Virgil Key Manager that provides a work with VirgilKey entities.

Returns:



51
52
53
# File 'lib/virgil/sdk/high_level/virgil_api.rb', line 51

def keys
  @keys
end