diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d520857dd40..6597f49b94b 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-22.04 timeout-minutes: 10 env: - CACHE_VERSION: 1.11 # bump this to run all clients on the CI. + CACHE_VERSION: 1.12 # bump this to run all clients on the CI. steps: - name: debugging - dump GitHub context env: diff --git a/scripts/formatter.ts b/scripts/formatter.ts index b011baedb53..89cefa43e9a 100644 --- a/scripts/formatter.ts +++ b/scripts/formatter.ts @@ -15,13 +15,13 @@ export async function formatter(language: string, cwd: string): Promise { } break; case 'dart': - if (cwd.includes('tests') || cwd.includes('snippets')) { - await run('dart pub get && dart fix --apply && dart format .', { + if (cwd.includes('clients')) { + await run('dart pub get && melos bs && melos build --no-select && melos lint', { cwd, language, }); } else { - await run('dart pub get && melos bs && melos build --no-select && melos lint', { + await run('dart pub get && dart fix --apply && dart format .', { cwd, language, }); diff --git a/templates/dart/guides/search/saveObjectsMovies.mustache b/templates/dart/guides/search/saveObjectsMovies.mustache new file mode 100644 index 00000000000..4f647c43032 --- /dev/null +++ b/templates/dart/guides/search/saveObjectsMovies.mustache @@ -0,0 +1,37 @@ +import 'package:http/http.dart' as http; +import 'dart:convert'; +{{> snippets/import}} + +void main() async { + // initiate client + {{> snippets/init}} + + // read json file from url + final datasetRequest = await http.get( + Uri.parse('https://dashboard.algolia.com/sample_datasets/movie.json')); + + if (datasetRequest.statusCode == 200) { + final moviesData = jsonDecode(datasetRequest.body); + + final batchRequests = []; + + for (final movie in moviesData) { + batchRequests.add( + BatchRequest(action: Action.fromJson('addObject'), body: movie), + ); + } + + try { + // push data to algolia + await client.batch( + indexName: 'movies_index', + batchWriteParams: BatchWriteParams(requests: batchRequests), + ); + print("Successfully indexed records!"); + } catch (e) { + print("Error: ${e.toString()}"); + } + } else { + throw Exception('Failed to load data'); + } +} diff --git a/templates/dart/snippets/pubspec.mustache b/templates/dart/snippets/pubspec.mustache index b23129b2bec..7cad2f86675 100644 --- a/templates/dart/snippets/pubspec.mustache +++ b/templates/dart/snippets/pubspec.mustache @@ -10,6 +10,7 @@ dependencies: algolia_client_insights: ^1.0.0 algolia_client_recommend: ^1.0.0 dotenv: ^4.1.0 + http: ^1.2.2 dev_dependencies: - lints: ^5.0.0 + lints: ^5.0.0 \ No newline at end of file