Skip to content

Commit

Permalink
fix: use type-specific methods in public clients, Value in internal c…
Browse files Browse the repository at this point in the history
…lients (#90)

* fix: use dynamic in public clients, Value in internal clients

* dart format

* fix topics test

* provide String and Binary versions of methods that accept Values on public clients instead of using dynamic

* pass Strings directly to doc api examples

* add missing list collection docstrings

* Binary -> Bytes
  • Loading branch information
anitarua authored Jan 12, 2024
1 parent fbbd3d3 commit 50894b7
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 99 deletions.
19 changes: 12 additions & 7 deletions example/doc_example_apis/doc_example_apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Future<void> example_API_InstantiateCacheClient() async {
}
}

Future<void> example_API_CreateCache(CacheClient cacheClient, String cacheName) async {
Future<void> example_API_CreateCache(
CacheClient cacheClient, String cacheName) async {
final result = await cacheClient.createCache(cacheName);
switch (result) {
case CreateCacheAlreadyExists():
Expand All @@ -36,7 +37,8 @@ Future<void> example_API_ListCaches(CacheClient cacheClient) async {
}
}

Future<void> example_API_DeleteCache(CacheClient cacheClient, String cacheName) async {
Future<void> example_API_DeleteCache(
CacheClient cacheClient, String cacheName) async {
final result = await cacheClient.deleteCache(cacheName);
switch (result) {
case DeleteCacheError():
Expand All @@ -47,7 +49,8 @@ Future<void> example_API_DeleteCache(CacheClient cacheClient, String cacheName)
}
}

Future<void> example_API_Set(CacheClient cacheClient, String cacheName, Value key, Value value) async {
Future<void> example_API_Set(
CacheClient cacheClient, String cacheName, String key, String value) async {
final result = await cacheClient.set(cacheName, key, value);
switch (result) {
case SetError():
Expand All @@ -58,7 +61,8 @@ Future<void> example_API_Set(CacheClient cacheClient, String cacheName, Value ke
}
}

Future<void> example_API_Get(CacheClient cacheClient, String cacheName, Value key) async {
Future<void> example_API_Get(
CacheClient cacheClient, String cacheName, String key) async {
final result = await cacheClient.get(cacheName, key);
switch (result) {
case GetMiss():
Expand All @@ -70,7 +74,8 @@ Future<void> example_API_Get(CacheClient cacheClient, String cacheName, Value ke
}
}

Future<void> example_API_Delete(CacheClient cacheClient, String cacheName, Value key) async {
Future<void> example_API_Delete(
CacheClient cacheClient, String cacheName, String key) async {
final result = await cacheClient.delete(cacheName, key);
switch (result) {
case DeleteError():
Expand All @@ -88,8 +93,8 @@ Future<void> main() async {
Duration(seconds: 30));

final cacheName = "doc-example-apis-${Uuid().v4()}";
final key = StringValue("myKey");
final value = StringValue("myValue");
final key = "myKey";
final value = "myValue";

await example_API_InstantiateCacheClient();
await example_API_CreateCache(cacheClient, cacheName);
Expand Down
4 changes: 2 additions & 2 deletions example/flutter_chat_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> publishMessage() async {
final result = await _topicClient.publish(
"cache", "topic", StringValue(_textInputController.text));
final result =
await _topicClient.publish("cache", "topic", _textInputController.text);
switch (result) {
case TopicPublishSuccess():
print("Successful publish");
Expand Down
4 changes: 2 additions & 2 deletions example/quickstart/quickstart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Future<void> main() async {
Duration(seconds: 30));

final cacheName = "cache";
final key = StringValue("key");
final value = StringValue("value");
final key = "key";
final value = "value";

final setResp = await cacheClient.set(cacheName, key, value);
switch (setResp) {
Expand Down
3 changes: 1 addition & 2 deletions example/topics/advanced.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ void main() async {
Timer(const Duration(seconds: 2), () async {
// publish 10 messages spaced 1 second apart
for (final i in Iterable.generate(10)) {
var result =
await topicClient.publish("cache", "topic", StringValue("hi $i"));
var result = await topicClient.publish("cache", "topic", "hi $i");
switch (result) {
case TopicPublishSuccess():
print("Successful publish!");
Expand Down
3 changes: 1 addition & 2 deletions example/topics/basic_publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ void main() async {

// publish 10 messages spaced 1 second apart
for (final i in Iterable.generate(10)) {
var result =
await topicClient.publish("cache", "topic", StringValue("hi $i"));
var result = await topicClient.publish("cache", "topic", "hi $i");
switch (result) {
case TopicPublishSuccess():
print("Successful publish!");
Expand Down
Loading

0 comments on commit 50894b7

Please sign in to comment.