Skip to content

Commit 151bd36

Browse files
levimichaelmillotpFluf22
authored
guides: add onboarding snippets (#3844)
Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: Thomas Raffray <[email protected]>
1 parent 3f5e35d commit 151bd36

File tree

17 files changed

+293
-370
lines changed

17 files changed

+293
-370
lines changed

generators/src/main/java/com/algolia/codegen/cts/guides/GuidesGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public void addSupportingFiles(List<SupportingFile> supportingFiles, String outp
5050

5151
@Override
5252
public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation> operations, Map<String, Object> bundle) throws Exception {
53+
if (this.client.equals("search")) {
54+
bundle.put("isSearchClient", true);
55+
}
56+
bundle.put("isSyncClient", true);
5357
// nothing to do here, the mustache uses dynamicSnippets lambda
5458
}
5559
}

generators/src/main/java/com/algolia/codegen/cts/manager/SwiftCTSManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ public void addDataToBundle(Map<String, Object> bundle) throws GeneratorExceptio
4242

4343
@Override
4444
public void addSnippetsSupportingFiles(List<SupportingFile> supportingFiles, String output) {
45-
supportingFiles.add(new SupportingFile("snippets/Package.mustache", output + "/swift", "Package.swift"));
4645
supportingFiles.add(new SupportingFile("snippets/.swiftformat.mustache", output + "/swift", ".swiftformat"));
4746
supportingFiles.add(new SupportingFile("snippets/.gitignore.mustache", output + "/swift", ".gitignore"));
47+
48+
if (output.equals("snippets")) {
49+
supportingFiles.add(new SupportingFile("snippets/Package.mustache", output + "/swift", "Package.swift"));
50+
} else if (output.equals("guides")) {
51+
supportingFiles.add(new SupportingFile("guides/Package.mustache", output + "/swift", "Package.swift"));
52+
}
4853
}
4954
}

guides/swift/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc
9+
Package.resolved

scripts/buildLanguages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function buildLanguage(language: Language, gens: Generator[], buildType: B
6565
break;
6666
case 'swift':
6767
// make this work in the playground
68-
if (buildType === 'client') {
68+
if (buildType !== 'playground') {
6969
await run('swift build -Xswiftc -suppress-warnings', { cwd, language });
7070
}
7171
break;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Net.Http;
4+
using System.Collections.Generic;
5+
6+
{{> snippets/import}}
7+
8+
class Program
9+
{
10+
public static async Task Main(string[] args)
11+
{
12+
// read json file from url
13+
var url = "https://dashboard.algolia.com/sample_datasets/movie.json";
14+
var httpClient = new HttpClient();
15+
var response = await httpClient.GetAsync(url);
16+
var content = await response.Content.ReadAsStringAsync();
17+
18+
// parse json
19+
var movies = JsonSerializer.Deserialize<List<dynamic>>(content);
20+
21+
// initiate client and index
22+
{{> snippets/init}}
23+
24+
// push data to algolia
25+
try
26+
{
27+
var result = {{#dynamicSnippet}}saveObjectsMovies{{/dynamicSnippet}};
28+
}
29+
catch (Exception e)
30+
{
31+
Console.WriteLine(e.Message);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)