Skip to content

Commit

Permalink
Rename manifest fields, add example setting (#4)
Browse files Browse the repository at this point in the history
* 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 <clement@cbouvet.fr>
  • Loading branch information
alexcasalboni and CLEMENTINATOR authored Feb 14, 2025
1 parent df6c340 commit a858e08
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bin/
obj/
dc-component.wasm
43 changes: 23 additions & 20 deletions DataCollectionComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,55 @@ This is the main class that you will need to implement. It should inherit from
Page, Track, User
These functions are called by the Edgee runtime to get the HTTP request to make to the provider's API for each event type.
*/

public struct Settings {
public string Example { get; }

public Settings(List<(string, string)> settings) {
Example = string.Empty;
foreach (var setting in settings) {
if (setting.Item1 == "example") {
Example = setting.Item2;
}
}
}
}

public class DataCollectionImpl: IDataCollection {
public static IDataCollection.EdgeeRequest Page(IDataCollection.Event e, List<(string, string)> settings) {
/*
settings is a list of tuple, which contains each key and secret for the provider
for example, if your component is set to use
[[components.data_collection]]
name = "my_component"
component = "outpout.wasm"
settings.test_project_id = "123456789"
settings.test_write_key = "abcdefg"
then
foreach (var settings in settings)
{
Console.WriteLine($"{settings.Item1}: {cred.Item2}");
}
will print:
test_project_id: 123456789
test_write_key: abcdefg
*/
string url = "https://example.com/";
Settings s = new Settings(settings);
var headers = new List<(string, string)>
{
("Authorization", "Bearer exampleToken123"),
("Content-Type", "application/json")
("Content-Type", "application/json"),
("example", s.Example)
};
string body = "{\"event\": \"page\"}";
bool forward_client_headers = true;
return new IDataCollection.EdgeeRequest(IDataCollection.HttpMethod.POST, url, headers, forward_client_headers, body);
}
public static IDataCollection.EdgeeRequest Track(IDataCollection.Event e, List<(string, string)> settings) {
string url = "https://example.com/";
Settings s = new Settings(settings);
var headers = new List<(string, string)>
{
("Authorization", "Bearer exampleToken123"),
("Content-Type", "application/json")
("Content-Type", "application/json"),
("example", s.Example)
};
string body = "{\"event\": \"track\"}";
bool forward_client_headers = true;
return new IDataCollection.EdgeeRequest(IDataCollection.HttpMethod.POST, url, headers, forward_client_headers, body);
}
public static IDataCollection.EdgeeRequest User(IDataCollection.Event e, List<(string, string)> settings) {
string url = "https://example.com/";
Settings s = new Settings(settings);
var headers = new List<(string, string)>
{
("Authorization", "Bearer exampleToken123"),
("Content-Type", "application/json")
("Content-Type", "application/json"),
("example", s.Example)
};
string body = "{\"event\": \"user\"}";
bool forward_client_headers = true;
Expand Down
10 changes: 7 additions & 3 deletions edgee-component.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
manifest_version = 1
manifest-version = 1

[package]
[component]
name = "example-cs-component"
version = "1.0.0"
category = "data-collection"
Expand All @@ -10,6 +10,10 @@ documentation = "https://github.com/edgee-cloud/example-cs-component"
repository = "https://github.com/edgee-cloud/example-cs-component"
wit-world-version = "0.4.0"

[package.build]
[component.build]
command = "dotnet build && mv ./bin/Debug/net9.0/wasi-wasm/publish/example-cs-component.wasm ./dc-component.wasm"
output_path = "./dc-component.wasm"

[component.settings.example]
title = "Example Config Field"
type = "string"

0 comments on commit a858e08

Please sign in to comment.