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 bd3a147..fe43976 100644
--- a/pikul.c
+++ b/pikul.c
@@ -16,6 +16,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();
+void sicepat_init(char *[]);
+void sicepat_services(const char *, const char *, double, char **);
+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);
@@ -28,6 +32,9 @@ void pikul_init(enum pikul_company company, char *provisions[])
case PIKUL_ANTERAJA:
anteraja_init(provisions);
break;
+ case PIKUL_SICEPAT:
+ sicepat_init(provisions);
+ break;
default:
break;
}
@@ -57,6 +64,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, &url);
+ handler = sicepat_services_handle;
+ break;
default:
break;
}
diff --git a/pikul.h b/pikul.h
index fde0483..aa54cca 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..ffa83c3
--- /dev/null
+++ b/sicepat.c
@@ -0,0 +1,46 @@
+#include "shipping.h"
+#include "handler.h"
+
+#define BASE "http://api.sicepat.com/customer/"
+
+extern CURL *curl;
+
+static const char *status_trail[] = {
+ "sicepat",
+ "status",
+ "code",
+ NULL
+};
+
+void sicepat_init(char *provisions[])
+{
+ shipping.base = malloc(strlen(BASE) + 1);
+ strcpy(shipping.base, BASE);
+ headers((const char *[]){ "api-key", NULL }, provisions);
+}
+
+void sicepat_services(const char *origin, const char *destination, double weight, 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;
+}