diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | pikul.c | 11 | ||||
-rw-r--r-- | pikul.h | 3 | ||||
-rw-r--r-- | sicepat.c | 46 |
4 files changed, 61 insertions, 2 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 @@ -17,6 +17,10 @@ void anteraja_order(const char *, const char *, const char *, const char *, cons size_t anteraja_order_handle(const char *, size_t size, size_t nmemb, char **); void anteraja_cleanup(); +extern void sicepat_init(char *[], struct shipping *); +extern void sicepat_services(const char *, const char *, double, struct shipping *, char **); +extern size_t sicepat_services_handle(const char *, size_t, size_t, struct pikul_services **); + void pikul_init(enum pikul_company company, char *provisions[]) { curl_global_init(CURL_GLOBAL_SSL); @@ -29,6 +33,9 @@ void pikul_init(enum pikul_company company, char *provisions[]) case PIKUL_ANTERAJA: anteraja_init(provisions); break; + case PIKUL_SICEPAT: + sicepat_init(provisions, &shipping); + break; default: break; } @@ -58,6 +65,10 @@ struct pikul_services *pikul_services(const char *origin, const char *destinatio anteraja_services(origin, destination, weight, &url, &post); handler = anteraja_services_handle; break; + case PIKUL_SICEPAT: + sicepat_services(origin, destination, weight, &shipping, &url); + handler = sicepat_services_handle; + break; default: break; } @@ -2,7 +2,8 @@ #define PIKUL_H enum pikul_company { - PIKUL_ANTERAJA + PIKUL_ANTERAJA, + PIKUL_SICEPAT }; struct pikul_service { 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; +} |