-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdc_component.c
83 lines (65 loc) · 3.79 KB
/
dc_component.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "internal/data_collection.h"
#include <stdlib.h>
#include <string.h>
/*
These are the functions that you will need to implement in order to create your component.
These functions are called by the Edgee runtime to get the HTTP request to make to the provider's API for each event type.
You should set your request parameters in the `ret` struct and return true if the request was successful.
*/
struct component_settings {
data_collection_string_t example;
};
struct component_settings parse_settings(exports_edgee_protocols_data_collection_dict_t *settings) {
struct component_settings ret;
for (int i = 0; i < settings->len; i++) {
if (settings->ptr[i].f0.len == 0) {
continue;
}
if (strncmp((const char*)settings->ptr[i].f0.ptr, "example", settings->ptr[i].f0.len) == 0) {
ret.example = settings->ptr[i].f1;
}
}
return ret;
}
bool exports_edgee_protocols_data_collection_page(exports_edgee_protocols_data_collection_event_t *e, exports_edgee_protocols_data_collection_dict_t *settings, exports_edgee_protocols_data_collection_edgee_request_t *ret, data_collection_string_t *err) {
struct component_settings parsed_settings = parse_settings(settings);
data_collection_string_dup(&ret->url, "https://example.com");
data_collection_string_dup(&ret->body, "{\"key\":\"value\"}");
ret->method = EXPORTS_EDGEE_PROTOCOLS_DATA_COLLECTION_HTTP_METHOD_POST;
ret->headers.ptr = malloc(2 * sizeof(data_collection_tuple2_string_string_t));
ret->headers.len = 2;
data_collection_string_dup(&ret->headers.ptr[0].f0, "Content-Type");
data_collection_string_dup(&ret->headers.ptr[0].f1, "application/json");
data_collection_string_dup(&ret->headers.ptr[1].f0, "Example");
ret->headers.ptr[1].f1 = parsed_settings.example;
ret->forward_client_headers = true;
return true;
}
bool exports_edgee_protocols_data_collection_track(exports_edgee_protocols_data_collection_event_t *e, exports_edgee_protocols_data_collection_dict_t *settings, exports_edgee_protocols_data_collection_edgee_request_t *ret, data_collection_string_t *err) {
struct component_settings parsed_settings = parse_settings(settings);
data_collection_string_dup(&ret->url, "https://example.com");
data_collection_string_dup(&ret->body, "{\"key\":\"value\"}");
ret->method = EXPORTS_EDGEE_PROTOCOLS_DATA_COLLECTION_HTTP_METHOD_POST;
ret->headers.ptr = malloc(2 * sizeof(data_collection_tuple2_string_string_t));
ret->headers.len = 2;
data_collection_string_dup(&ret->headers.ptr[0].f0, "Content-Type");
data_collection_string_dup(&ret->headers.ptr[0].f1, "application/json");
data_collection_string_dup(&ret->headers.ptr[1].f0, "Example");
ret->headers.ptr[1].f1 = parsed_settings.example;
ret->forward_client_headers = true;
return true;
}
bool exports_edgee_protocols_data_collection_user(exports_edgee_protocols_data_collection_event_t *e, exports_edgee_protocols_data_collection_dict_t *settings, exports_edgee_protocols_data_collection_edgee_request_t *ret, data_collection_string_t *err) {
struct component_settings parsed_settings = parse_settings(settings);
data_collection_string_dup(&ret->url, "https://example.com");
data_collection_string_dup(&ret->body, "{\"key\":\"value\"}");
ret->method = EXPORTS_EDGEE_PROTOCOLS_DATA_COLLECTION_HTTP_METHOD_POST;
ret->headers.ptr = malloc(2 * sizeof(data_collection_tuple2_string_string_t));
ret->headers.len = 2;
data_collection_string_dup(&ret->headers.ptr[0].f0, "Content-Type");
data_collection_string_dup(&ret->headers.ptr[0].f1, "application/json");
data_collection_string_dup(&ret->headers.ptr[1].f0, "Example");
ret->headers.ptr[1].f1 = parsed_settings.example;
ret->forward_client_headers = true;
return true;
}