Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename manifest fields, add example setting #4

Merged
merged 5 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"