Skip to content

Commit 0e4ffdb

Browse files
authored
Merge branch 'main' into fix/search-save-rules
2 parents 413371e + 804d49d commit 0e4ffdb

File tree

9 files changed

+135
-5
lines changed

9 files changed

+135
-5
lines changed

docs/guides/dart/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Files and directories created by pub
2+
.dart_tool/
3+
.buildlog
4+
.packages
5+
.project
6+
.pub/
7+
build/
8+
9+
# Files created by dart2js
10+
*.dart.js
11+
*.part.js
12+
*.js.deps
13+
*.js.map
14+
*.info.json
15+
16+
# Directory created by dartdoc
17+
doc/api/
18+
19+
# Don't commit pubspec lock file
20+
pubspec.lock
21+
22+
# IntelliJ
23+
*.iml
24+
*.ipr
25+
*.iws
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'package:http/http.dart' as http;
2+
import 'dart:convert';
3+
import 'package:algolia_client_search/algolia_client_search.dart';
4+
5+
void main() async {
6+
// initiate client
7+
final client =
8+
SearchClient(appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');
9+
10+
// read json file from url
11+
final datasetRequest = await http.get(
12+
Uri.parse('https://dashboard.algolia.com/sample_datasets/movie.json'));
13+
14+
if (datasetRequest.statusCode == 200) {
15+
final moviesData = jsonDecode(datasetRequest.body);
16+
17+
final batchRequests = <BatchRequest>[];
18+
19+
for (final movie in moviesData) {
20+
batchRequests.add(
21+
BatchRequest(action: Action.fromJson('addObject'), body: movie),
22+
);
23+
}
24+
25+
try {
26+
// push data to algolia
27+
await client.batch(
28+
indexName: 'movies_index',
29+
batchWriteParams: BatchWriteParams(requests: batchRequests),
30+
);
31+
print("Successfully indexed records!");
32+
} catch (e) {
33+
print("Error: ${e.toString()}");
34+
}
35+
} else {
36+
throw Exception('Failed to load data');
37+
}
38+
}

docs/guides/dart/pubspec.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: algolia_snippets
2+
version: 1.0.0
3+
4+
environment:
5+
sdk: ^3.0.0
6+
7+
dependencies:
8+
algoliasearch: ^1.0.0
9+
algolia_client_search: ^1.0.0
10+
algolia_client_insights: ^1.0.0
11+
algolia_client_recommend: ^1.0.0
12+
dotenv: ^4.1.0
13+
http: ^1.2.2
14+
15+
dev_dependencies:
16+
lints: ^5.0.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dependency_overrides:
2+
algoliasearch:
3+
path: ../../../clients/algoliasearch-client-dart/packages/algoliasearch
4+
algolia_client_core:
5+
path: ../../../clients/algoliasearch-client-dart/packages/client_core
6+
algolia_client_search:
7+
path: ../../../clients/algoliasearch-client-dart/packages/client_search
8+
algolia_client_insights:
9+
path: ../../../clients/algoliasearch-client-dart/packages/client_insights
10+
algolia_client_recommend:
11+
path: ../../../clients/algoliasearch-client-dart/packages/client_recommend

docs/snippets/dart/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
algolia_client_insights: ^1.0.0
1111
algolia_client_recommend: ^1.0.0
1212
dotenv: ^4.1.0
13+
http: ^1.2.2
1314

1415
dev_dependencies:
15-
lints: ^5.0.0
16+
lints: ^5.0.0

scripts/formatter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export async function formatter(language: string, cwd: string): Promise<void> {
1515
}
1616
break;
1717
case 'dart':
18-
if (cwd.includes('tests') || cwd.includes('snippets')) {
19-
await run('dart pub get && dart fix --apply && dart format .', {
18+
if (cwd.includes('clients')) {
19+
await run('dart pub get && melos bs && melos build --no-select && melos lint', {
2020
cwd,
2121
language,
2222
});
2323
} else {
24-
await run('dart pub get && melos bs && melos build --no-select && melos lint', {
24+
await run('dart pub get && dart fix --apply && dart format .', {
2525
cwd,
2626
language,
2727
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:http/http.dart' as http;
2+
import 'dart:convert';
3+
{{> snippets/import}}
4+
5+
void main() async {
6+
// initiate client
7+
{{> snippets/init}}
8+
9+
// read json file from url
10+
final datasetRequest = await http.get(
11+
Uri.parse('https://dashboard.algolia.com/sample_datasets/movie.json'));
12+
13+
if (datasetRequest.statusCode == 200) {
14+
final moviesData = jsonDecode(datasetRequest.body);
15+
16+
final batchRequests = <BatchRequest>[];
17+
18+
for (final movie in moviesData) {
19+
batchRequests.add(
20+
BatchRequest(action: Action.fromJson('addObject'), body: movie),
21+
);
22+
}
23+
24+
try {
25+
// push data to algolia
26+
await client.batch(
27+
indexName: 'movies_index',
28+
batchWriteParams: BatchWriteParams(requests: batchRequests),
29+
);
30+
print("Successfully indexed records!");
31+
} catch (e) {
32+
print("Error: ${e.toString()}");
33+
}
34+
} else {
35+
throw Exception('Failed to load data');
36+
}
37+
}

templates/dart/snippets/pubspec.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
algolia_client_insights: ^1.0.0
1111
algolia_client_recommend: ^1.0.0
1212
dotenv: ^4.1.0
13+
http: ^1.2.2
1314

1415
dev_dependencies:
15-
lints: ^5.0.0
16+
lints: ^5.0.0

0 commit comments

Comments
 (0)