diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-14 20:42:54 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-14 20:42:54 +0800 |
commit | 98b431f3b0b1f45b9f05edc43fff19c586658445 (patch) | |
tree | 451c25778d2c24b7d5cad7768c2b9b99146a0e27 | |
parent | 3aab16c1b17edf43c74832a2fdbdf49980aa1c75 (diff) | |
parent | 1c51604909c9953acd874e24abe90ba565c650d2 (diff) |
Merge branch 'master' into sicepat
-rw-r--r-- | anteraja.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -1,12 +1,14 @@ #include "shipping.h" #include "handler.h" -#define POST \ +#define SERVICES_PATH "serviceRates" +#define SERVICES_POST \ "{\ \"origin\":\"%s\",\ \"destination\":\"%s\",\ \"weight\":%d\ }" + extern CURL *curl; static const char *status_trail[] = { "status", NULL }; @@ -24,12 +26,11 @@ void anteraja_init(char *provisions[], struct shipping *shipping) void anteraja_services(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); - *post = malloc(strlen(POST) + strlen(origin) + strlen(destination) + strlen("50000") + *url = malloc(strlen(shipping->base) + strlen(SERVICES_PATH) + 1); + sprintf(*url, "%s%s", shipping->base, SERVICES_PATH); + *post = malloc(strlen(SERVICES_POST) + strlen(origin) + strlen(destination) + strlen("50000") - 2 * strlen("%s") - strlen("%d") + 1); - sprintf(*post, POST, origin, destination, weight < 1.0 ? 1000 : (int)weight * 1000); + sprintf(*post, SERVICES_POST, origin, destination, weight < 1.0 ? 1000 : (int)weight * 1000); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, *post); } |