diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-14 20:41:14 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-14 20:41:14 +0800 |
commit | 1c51604909c9953acd874e24abe90ba565c650d2 (patch) | |
tree | b84690f3d3b5d93fe586098ddc78bca580b394db | |
parent | 98e006f67c205a2674a1b35c3a215ba41ae1881b (diff) |
Macros for Anteraja services
-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); } |