diff options
| author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-13 19:53:38 +0800 |
|---|---|---|
| committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-13 19:53:38 +0800 |
| commit | 67a7728f02701c1f0b8f9f7a71554ff222e46de6 (patch) | |
| tree | 953c2e14456752c438eba7c99a0df8eb6cdc154a /sicepat.c | |
| parent | 55aa9be96a1561e07f36da03e28eb6d1dd051274 (diff) | |
Sicepat handler
So far only to retrieve services tariffs information.
Diffstat (limited to 'sicepat.c')
| -rw-r--r-- | sicepat.c | 46 |
1 files changed, 46 insertions, 0 deletions
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; +} |