From 67a7728f02701c1f0b8f9f7a71554ff222e46de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Tue, 13 Jul 2021 19:53:38 +0800 Subject: Sicepat handler So far only to retrieve services tariffs information. --- sicepat.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sicepat.c (limited to 'sicepat.c') diff --git a/sicepat.c b/sicepat.c new file mode 100644 index 0000000..e03be36 --- /dev/null +++ b/sicepat.c @@ -0,0 +1,46 @@ +#include "shipping.h" +#include "handler.h" + +extern CURL *curl; + +static const char *status_trail[] = { + "sicepat", + "status", + "code", + NULL +}; + +void sicepat_init(char *provisions[], struct shipping *shipping) +{ + static const char *url = "http://api.sicepat.com/customer/"; + shipping->base = malloc(strlen(url) + 1); + strcpy(shipping->base, url); + headers((const char *[]){ "api-key", NULL }, provisions, shipping); +} + +void sicepat_services(const char *origin, const char *destination, double weight, + struct shipping *shipping, char **url) +{ + *url = malloc(strlen(shipping->base) + strlen("tariff?origin=") + strlen(origin) + + strlen("&destination=") + strlen(destination) + strlen("&weight=") + 9); + sprintf(*url, "%stariff?origin=%s&destination=%s&weight=%f", shipping->base, + origin, destination, weight); + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); +} + +size_t sicepat_services_handle(const char *contents, size_t size, size_t nmemb, + struct pikul_services **services) +{ + size_t realsize = size * nmemb; + handle_services(contents, realsize, status_trail, (const char *[]){ + "sicepat", + "results", + NULL + }, (const char *[]){ + "service", + "description", + "etd", + "tariff" + }, services); + return realsize; +} -- cgit v1.2.3