Skip to content

Commit a858e08

Browse files
Rename manifest fields, add example setting (#4)
* rename manifest fields, add example setting * fix manifest version * parse settings into struct * gitignore: add output artefact * c#ify settings --------- Co-authored-by: Clement Bouvet <[email protected]>
1 parent df6c340 commit a858e08

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin/
22
obj/
3+
dc-component.wasm

DataCollectionComponent.cs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,55 @@ This is the main class that you will need to implement. It should inherit from
66
Page, Track, User
77
These functions are called by the Edgee runtime to get the HTTP request to make to the provider's API for each event type.
88
*/
9+
10+
public struct Settings {
11+
public string Example { get; }
12+
13+
public Settings(List<(string, string)> settings) {
14+
Example = string.Empty;
15+
foreach (var setting in settings) {
16+
if (setting.Item1 == "example") {
17+
Example = setting.Item2;
18+
}
19+
}
20+
}
21+
}
22+
923
public class DataCollectionImpl: IDataCollection {
1024
public static IDataCollection.EdgeeRequest Page(IDataCollection.Event e, List<(string, string)> settings) {
11-
/*
12-
settings is a list of tuple, which contains each key and secret for the provider
13-
for example, if your component is set to use
14-
[[components.data_collection]]
15-
name = "my_component"
16-
component = "outpout.wasm"
17-
settings.test_project_id = "123456789"
18-
settings.test_write_key = "abcdefg"
19-
then
20-
foreach (var settings in settings)
21-
{
22-
Console.WriteLine($"{settings.Item1}: {cred.Item2}");
23-
}
24-
will print:
25-
test_project_id: 123456789
26-
test_write_key: abcdefg
27-
*/
2825
string url = "https://example.com/";
26+
Settings s = new Settings(settings);
2927
var headers = new List<(string, string)>
3028
{
3129
("Authorization", "Bearer exampleToken123"),
32-
("Content-Type", "application/json")
30+
("Content-Type", "application/json"),
31+
("example", s.Example)
3332
};
3433
string body = "{\"event\": \"page\"}";
3534
bool forward_client_headers = true;
3635
return new IDataCollection.EdgeeRequest(IDataCollection.HttpMethod.POST, url, headers, forward_client_headers, body);
3736
}
3837
public static IDataCollection.EdgeeRequest Track(IDataCollection.Event e, List<(string, string)> settings) {
3938
string url = "https://example.com/";
39+
Settings s = new Settings(settings);
4040
var headers = new List<(string, string)>
4141
{
4242
("Authorization", "Bearer exampleToken123"),
43-
("Content-Type", "application/json")
43+
("Content-Type", "application/json"),
44+
("example", s.Example)
4445
};
4546
string body = "{\"event\": \"track\"}";
4647
bool forward_client_headers = true;
4748
return new IDataCollection.EdgeeRequest(IDataCollection.HttpMethod.POST, url, headers, forward_client_headers, body);
4849
}
4950
public static IDataCollection.EdgeeRequest User(IDataCollection.Event e, List<(string, string)> settings) {
5051
string url = "https://example.com/";
52+
Settings s = new Settings(settings);
5153
var headers = new List<(string, string)>
5254
{
5355
("Authorization", "Bearer exampleToken123"),
54-
("Content-Type", "application/json")
56+
("Content-Type", "application/json"),
57+
("example", s.Example)
5558
};
5659
string body = "{\"event\": \"user\"}";
5760
bool forward_client_headers = true;

edgee-component.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
manifest_version = 1
1+
manifest-version = 1
22

3-
[package]
3+
[component]
44
name = "example-cs-component"
55
version = "1.0.0"
66
category = "data-collection"
@@ -10,6 +10,10 @@ documentation = "https://github.com/edgee-cloud/example-cs-component"
1010
repository = "https://github.com/edgee-cloud/example-cs-component"
1111
wit-world-version = "0.4.0"
1212

13-
[package.build]
13+
[component.build]
1414
command = "dotnet build && mv ./bin/Debug/net9.0/wasi-wasm/publish/example-cs-component.wasm ./dc-component.wasm"
1515
output_path = "./dc-component.wasm"
16+
17+
[component.settings.example]
18+
title = "Example Config Field"
19+
type = "string"

0 commit comments

Comments
 (0)