summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rw-r--r--pikul.c11
-rw-r--r--pikul.h3
-rw-r--r--sicepat.c46
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
diff --git a/pikul.c b/pikul.c
index 1ccf717..d0ef912 100644
--- a/pikul.c
+++ b/pikul.c
@@ -13,6 +13,10 @@ extern void anteraja_init(char *[], struct shipping *);
extern void anteraja_services(const char *, const char *, double, struct shipping *, char **, char **);
extern size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **);
+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);
@@ -25,6 +29,9 @@ void pikul_init(enum pikul_company company, char *provisions[])
case PIKUL_ANTERAJA:
anteraja_init(provisions, &shipping);
break;
+ case PIKUL_SICEPAT:
+ sicepat_init(provisions, &shipping);
+ break;
default:
break;
}
@@ -54,6 +61,10 @@ struct pikul_services *pikul_services(const char *origin, const char *destinatio
anteraja_services(origin, destination, weight, &shipping, &url, &post);
handler = anteraja_services_handle;
break;
+ case PIKUL_SICEPAT:
+ sicepat_services(origin, destination, weight, &shipping, &url);
+ handler = sicepat_services_handle;
+ break;
default:
break;
}
diff --git a/pikul.h b/pikul.h
index 4cd11f7..4eb790b 100644
--- a/pikul.h
+++ b/pikul.h
@@ -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;
+}