From 65a334cf2fe2d7d524c129f0df765463a91f542c 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: Sun, 27 Jun 2021 23:41:31 +0800 Subject: Shipping API client framework with 1 module so far. --- anteraja.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 anteraja.c (limited to 'anteraja.c') diff --git a/anteraja.c b/anteraja.c new file mode 100644 index 0000000..cf9d685 --- /dev/null +++ b/anteraja.c @@ -0,0 +1,45 @@ +#include "shipping.h" +#include "handler.h" + +extern CURL *curl; + +void anteraja_init(char *provisions[], struct shipping *shipping) +{ + shipping->base = malloc(strlen(*provisions) + 1); + strcpy(shipping->base, *provisions); + headers(shipping, (const char *[]){ "access-key-id", "secret-access-key", NULL }, ++provisions); + shipping->headers = curl_slist_append(shipping->headers, "Content-Type:application/json"); +} + +void anteraja_services_request(const char *origin, const char *destination, double weight, + struct shipping *shipping, char **url, char **post) +{ + static const char *path = "serviceRates"; + *url = malloc(strlen(shipping->base) + strlen(path) + 1); + sprintf(*url, "%s%s", shipping->base, path); + static const char *format = "{" + "\"origin\": \"xx.xx.xx\"," + "\"destination\": \"xx.xx.xx\"," + "\"weight\": xxxxx" + "}"; + *post = malloc(strlen(format) + 1); + sprintf(*post, "{\"origin\": \"%s\",\"destination\": \"%s\",\"weight\": %d}", + origin, destination, (int)weight); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, *post); +} + +size_t anteraja_services_handle(const char *contents, size_t size, size_t nmemb, + struct pikul_services **services) +{ + size_t realsize = size * nmemb; + handle(contents, realsize, &(struct container){ services, (const char *[]){ + "product_code", + "product_name", + "etd", + "rates", + "content", + "services", + NULL + }}); + return realsize; +} -- cgit v1.2.3