Skip to content

Commit

Permalink
dart: add missing snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam committed Oct 12, 2023
1 parent b1a1398 commit 786f4d4
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 21 deletions.
16 changes: 15 additions & 1 deletion website/docs/clients/guides/retrieving-facets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,21 @@ client.search(
</TabItem>

<TabItem value="dart">
// TBD

```dart
await client.search(
searchMethodParams: SearchMethodParams(
requests: [
SearchForHits(
indexName: "<YOUR_INDEX_NAME>",
query: "<YOUR_QUERY>",
facets: ["author", "genre"],
),
],
),
);
```

</TabItem>

<TabItem value="go">
Expand Down
34 changes: 31 additions & 3 deletions website/docs/clients/guides/send-data-to-algolia.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ SearchClient client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
<TabItem value="kotlin">

```kotlin
val client = SearchClient(appId = "<YOUR_INDEX_NAME>",apiKey = "<YOUR_API_KEY>")
val client = SearchClient(appId = "<YOUR_APP_ID>", apiKey = "<YOUR_API_KEY>")
```

</TabItem>

<TabItem value="dart">
// TBD

```dart
var client = SearchClient(appId: '<YOUR_APP_ID>', apiKey: '<YOUR_API_KEY>');
```

</TabItem>

<TabItem value="go">
Expand Down Expand Up @@ -208,7 +212,31 @@ client.waitTask("<YOUR_INDEX_NAME>", response.taskID)
</TabItem>

<TabItem value="dart">
// TBD

```dart
class Actor {
final String name;
Actor(this.name);
Map<String, Object> toJson() => { "name": name };
}
// The records retrieved by any of your data sources
var records = [Actor('Tom Cruise'), Actor('Scarlett Johansson')];
// Here we construct the request to be sent to Algolia with the `batch` method
var response = await client.batch(
indexName : '<YOUR_INDEX_NAME>',
batchWriteParams : BatchWriteParams(
requests: records.map((record) => BatchRequest(action: Action.addObject, body: record)).toList(),
)
);
// Wait for indexing to be finished
await client.waitTask('<YOUR_INDEX_NAME>', response.taskID);
```

</TabItem>

<TabItem value="go">
Expand Down
21 changes: 20 additions & 1 deletion website/docs/clients/guides/wait-for-a-task-to-finish.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,26 @@ client.waitTask(
</TabItem>

<TabItem value="dart">
// TBD

```dart
var client = SearchClient(appId: '<YOUR_APP_ID>', apiKey: '<YOUR_API_KEY>');
var body = {'title', 'My Algolia Object'};
var response = await client.saveObject(indexName: '<YOUR_INDEX_NAME>', body: body);
// Poll the task status with defaults values
await client.waitTask('<YOUR_INDEX_NAME>', response.taskID);
// Poll the task status with your options
await client.waitTask(
indexName: '<YOUR_INDEX_NAME>',
taskID: response.taskID,
params: WaitParams(
maxRetries: 100,
timeout: Duration(minutes: 1),
),
);
```

</TabItem>

<TabItem value="go">
Expand Down
25 changes: 24 additions & 1 deletion website/docs/clients/guides/wait-for-api-key-to-be-valid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,30 @@ client.waitKeyDelete(key = keyResponse.key)
</TabItem>

<TabItem value="dart">
// TBD

```dart
var client = SearchClient(appId: '<YOUR_APP_ID>', apiKey: '<YOUR_API_KEY>');
var keyResponse = await client.addApiKey(apiKey : ApiKey(acl : [Acl.analytics, Acl.browse, Acl.editSettings]));
// Poll the task status with defaults values
await client.waitKeyCreation(keyResponse.key);
// The fields to update on your API key
var updatesToPerform = ApiKey(acl: [Acl.analytics, Acl.search], indexes: ['products']);
// Call for update
await client.updateApiKey(key: keyResponse.key, apiKey: updatesToPerform);
// Wait for update to be done
await client.waitKeyUpdate(
key: keyResponse.key,
apiKey: updatesToPerform, // We provide the updated fields to check if the changes have been applied
);
// Call for delete
await client.deleteApiKey(key: keyResponse.key);
// Wait for delete to be done
await client.waitKeyDelete(key: keyResponse.key);
```

</TabItem>

<TabItem value="go">
Expand Down
36 changes: 35 additions & 1 deletion website/docs/clients/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,41 @@ println(response)
</TabItem>

<TabItem value="dart">
// TBD

```dart
import 'package:algolia_client_search/algolia_client_search.dart';
void main() async {
// Instantiate the client
var client = SearchClient(appId: '<YOUR_APP_ID>', apiKey: '<YOUR_API_KEY>');
// Add a new record to your Algolia index.
// Can also be an instance of a class with a `toJson()` method.
var record = {
'objectID': 'id1',
'title': 'My Algolia Object',
};
await client.saveObject(indexName: '<YOUR_INDEX_NAME>', body: record);
// Fetch search results
var response = await client.search(
searchMethodParams: SearchMethodParams(
requests: [
SearchForHits(
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>', // Typo tolerant search
hitsPerPage: 50,
),
],
),
);
print(response);
// Close the client and dispose of all underlying resources.
client.dispose();
}
```

</TabItem>

<TabItem value="go">
Expand Down
13 changes: 0 additions & 13 deletions website/docs/clients/migration-guides/dart.md

This file was deleted.

1 change: 0 additions & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const sidebars = {
'clients/migration-guides/php',
'clients/migration-guides/kotlin',
'clients/migration-guides/go',
'clients/migration-guides/dart',
],
},
],
Expand Down

0 comments on commit 786f4d4

Please sign in to comment.