summaryrefslogtreecommitdiff
path: root/client.c
blob: d69399699f03b218cd49716df2cf46ec280b9d35 (plain)
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
#include <stdbool.h>
#include <string.h>
#include "request.h"
#include "icclient/product.h"
#include "icclient/catalog.h"
#include "icclient/client.h"

#ifdef __EMSCRIPTEN__
extern void icclient_catalog_results(emscripten_fetch_t *);
#else
extern size_t icclient_catalog_results(void *, size_t, size_t, void *);
#endif

bool icclient_init(const char *url, const char *certificate)
{
	return icclient_request_init(url, certificate);
}

void icclient_results(const char *prod_group, void (*callback)(struct icclient_catalog *), icclient_handler handler)
{
	char nonspaced[strlen(prod_group) + 1];
	strcpy(nonspaced, prod_group);
	char *space = NULL;
	while ((space = strchr(nonspaced, ' ')))
		*space = '-';
	request(handler ? handler : icclient_catalog_results, (void *)callback, 0, "%s", nonspaced);
}

void icclient_flypage(const char *sku, icclient_handler handler, struct icclient_product **productptr)
{
	request(handler, (void *)productptr, 0, "%s", sku);
}

void icclient_page(const char *path, icclient_handler handler, void **dataptr)
{
	request(handler, (void *)dataptr, 0, "%s", path);
}

void icclient_cleanup()
{
	icclient_request_cleanup();
}