diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | pikul.c | 15 | ||||
-rw-r--r-- | pikul.h | 1 | ||||
-rw-r--r-- | sicepat.c | 43 |
4 files changed, 59 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am index ff1a123..c00b280 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ lib_LTLIBRARIES = libpikul.la libpikul_la_SOURCES = pikul.c \ - anteraja.c + anteraja.c \ + sicepat.c libpikul_la_CPPFLAGS = $(DEPS_CFLAGS) libpikul_la_LDFLAGS = $(DEPS_LIBS) include_HEADERS = pikul.h @@ -23,6 +23,9 @@ void anteraja_order(const char *, const char *, const char *, const char *, cons char **[], double); void anteraja_cleanup(); +const char **sicepat_init(char *[]); +const char **sicepat_services(const char *, const char *, double); + static void recurse(struct json_object *outer, const char *trail[], struct json_object **last) { struct json_object *inner = NULL; @@ -128,6 +131,9 @@ void pikul_init(enum pikul_company company, char *provisions[]) case PIKUL_ANTERAJA: fields = anteraja_init(provisions); break; + case PIKUL_SICEPAT: + fields = sicepat_init(provisions); + break; default: break; } @@ -150,6 +156,9 @@ struct pikul_service **pikul_services(enum pikul_company company, case PIKUL_ANTERAJA: shipping->data = anteraja_services(origin, destination, weight); break; + case PIKUL_SICEPAT: + shipping->data = sicepat_services(origin, destination, weight); + break; default: break; } @@ -160,7 +169,8 @@ struct pikul_service **pikul_services(enum pikul_company company, #ifdef DEBUG fprintf(stderr, "POST: %s\n", shipping->post); #endif - } + } else + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); shipping->mode = SERVICES; curl_easy_perform(curl); if (shipping->post) @@ -308,7 +318,8 @@ char *pikul_order(enum pikul_company company, const char *order_number, const ch #ifdef DEBUG fprintf(stderr, "POST: %s\n", shipping->post); #endif - } + } else + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); shipping->mode = ORDER; curl_easy_perform(curl); if (shipping->post) @@ -4,6 +4,7 @@ enum pikul_company { PIKUL, PIKUL_ANTERAJA, + PIKUL_SICEPAT, PIKUL_END }; diff --git a/sicepat.c b/sicepat.c new file mode 100644 index 0000000..9dd3d19 --- /dev/null +++ b/sicepat.c @@ -0,0 +1,43 @@ +#include <stdlib.h> +#include <string.h> +#include "private.h" + +#define BASE "http://api.sicepat.com/customer/" + +const char **sicepat_init(char *provisions[]) +{ + struct shipping *shipping = shipping_list[PIKUL_SICEPAT]; + shipping->base = malloc(strlen(BASE) + 1); + strcpy(shipping->base, BASE); + static const char *status_trail[] = { + "sicepat", + "status", + "code", + NULL + }; + shipping->status_trail = status_trail; + static const char *fields[] = { "api-key", NULL }; + return fields; +} + +const char **sicepat_services(const char *origin, const char *destination, double weight) +{ + struct shipping *shipping = shipping_list[PIKUL_SICEPAT]; + shipping->url = malloc(strlen(shipping->base) + strlen("tariff?origin=") + strlen(origin) + + strlen("&destination=") + strlen(destination) + strlen("&weight=") + 9); + sprintf(shipping->url, "%stariff?origin=%s&destination=%s&weight=%f", shipping->base, origin, + destination, weight); + static const char *trail[] = { + "sicepat", + "results", + NULL + }; + shipping->trail = trail; + static const char *attributes[] = { + "service", + "description", + "etd", + "tariff" + }; + return attributes; +} |