put method
- AtKey atKey,
- dynamic value,
- {bool isDedicated = false,
- PutRequestOptions? putRequestOptions}
Updates value of AtKey.key is if it is already present. Otherwise creates a new key. Set AtKey.sharedWith if the key
has to be shared with another atSign. Set AtKey.metadata.isBinary
if you are updating binary value e.g image,file.
By default namespace that is used to create the AtClient instance will be appended to the key. phone@alice will be saved as
phone.persona@alice where 'persona' is the namespace. If you want to save by ignoring the namespace set AtKey.metadata.namespaceAware
to false.
Additional metadata can be set using AtKey.metadata
isDedicated
is currently ignored and will be removed in next major version
putRequestOptions
allows additional options to be provided. See PutRequestOptions
From at_client v3.0.55 lowercase will be enforced on all AtKey types AtKeys will now be actively converted to lowercase in at_client The values(AtValue) will however continue to be case-sensitive
update:phone@alice +1 999 9999
var key = AtKey()..key='phone'
put(key,'+1 999 9999');
update:public:phone@alice +1 999 9999
var metaData = Metadata()..isPublic=true;
var key = AtKey()..key='phone'
..metadata=metaData
put(key,'+1 999 9999');
update:@bob:phone@alice +1 999 9999
var metaData = Metadata()..sharedWith='@bob';
var key = AtKey()..key='phone'
..metadata=metaData
put(key,'+1 999 9999');
update:@alice:phone.persona@alice +1 999 9999
var key = AtKey()..key='phone'
..sharedWith='@alice'
put(key, '+1 999 9999');
update:@alice:phone@alice +1 999 9999
var metaData = Metadata()..namespaceAware=false
var key = AtKey()..key='phone'
sharedWith='@alice'
put(key, '+1 999 9999');
update:@bob:phone.persona@alice +1 999 9999
var key = AtKey()..key='phone'
sharedWith='@bob'
put(key, '+1 999 9999');
Starting version 3.0.0 isDedicated
is deprecated
Throws AtValueException if invalid value type is found
Throws AtKeyException if invalid key or metadata is found
Throws AtEncryptionException if encryption process fails
Throws SelfKeyNotFoundException if self encryption key is not found
Throws AtPrivateKeyNotFoundException if encryption private key is not found
Throws AtPublicKeyNotFoundException if encryption public key is not found
Implementation
@override
Future<bool> put(AtKey atKey, dynamic value,
{bool isDedicated = false, PutRequestOptions? putRequestOptions}) async {
_telemetry?.controller.sink
.add(AtTelemetryEvent('AtClient.put called', {"key": atKey}));
// If the value is neither String nor List<int> throw exception
if (value is! String && value is! List<int>) {
throw AtValueException(
'Invalid value type found ${value.runtimeType}. Expected String or List<int>');
}
AtResponse atResponse = AtResponse();
if (value is String) {
atResponse =
await putText(atKey, value, putRequestOptions: putRequestOptions);
}
if (value is List<int>) {
atResponse =
await putBinary(atKey, value, putRequestOptions: putRequestOptions);
}
_telemetry?.controller.sink
.add(AtTelemetryEvent('AtClient.put complete', {"atKey": atKey}));
return atResponse.response.isNotEmpty;
}