Updating Metadata on the atPlatform

Updating Metadata on the atPlatform

atProtocol exposes various attributes that can be set as the metadata for a key.

Please refer to the AtMetadata class for the complete list of metadata attributes.

The focus of this article is on how to update the metadata of a key.

Description:

The update:meta verb is used for updating the metadata of a key. If a key is already present, the metadata is updated. If a key is not present, a new key is created with the given metadata with a ‘null’ value. Users can add the value using the update verb.

Please refer to update_meta_verb_handler for implementation.

SDK offers the ‘ putMeta’ method to update the metadata of a key.

Updating metadata of a key using the SDK.

var currentAtSign = '@alice';

//Creating AtClient SDK instance.
await AtClientImpl.createClient(
   currentAtSign, 'me', TestUtil.getAlicePreference());

// Getting atClient Instance
var atClient = await AtClientImpl.getClient(currentAtSign);

var metadata = Metadata()..ttl = 600000
                         ..ttb = 600000;
var atKey = AtKey()..phone
                   ..sharedWith = ‘@bob’
                   ..sharedBy=’@alice’
                   ..metadata=metadata;
var result  = await atClient.putMeta(atKey);

The AtClient exposes the ‘getMeta’ which can be used to get the metadata of the key. The ‘getMeta’ method returns metadata in a JSON String.

var currentAtSign = '@alice';

//Creating AtClient SDK instance.
await AtClientImpl.createClient(
   currentAtSign, 'me', TestUtil.getAlicePreference());

// Getting atClient Instance
var atClient = await AtClientImpl.getClient(currentAtSign);

var atKey = AtKey()
 ..key = 'phone'
 ..sharedWith = '@bob
 ..sharedBy = '@alice';
var metadata = await atClient.getMeta(atKey);

Response :

Metadata{ttl: 600000, ttb: 600000, ttr: null,ccd: null, isPublic: false, isHidden: false, availableAt : 2021-02-18 02:40:03.207Z, expiresAt : 2021-02-18 02:50:03.207Z, refreshAt : null, createdAt : 2021-02-18 02:30:03.207Z,updatedAt : 2021-02-18 02:45:03.207Z,isBinary : null, isEncrypted : null, isCached : false, dataSignature: null}

For more samples, please refer to update_meta_verb_test.

We are working to make the internet better. Please come code with us!!!