summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rw-r--r--pikul.c14
-rw-r--r--pikul.h3
-rw-r--r--sicepat.c41
4 files changed, 58 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
diff --git a/pikul.c b/pikul.c
index df1662e..452a3e4 100644
--- a/pikul.c
+++ b/pikul.c
@@ -16,6 +16,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;
@@ -116,6 +119,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;
}
@@ -136,12 +142,17 @@ struct pikul_services *pikul_services(const char *origin, const char *destinatio
case PIKUL_ANTERAJA:
attributes = anteraja_services(origin, destination, weight);
break;
+ case PIKUL_SICEPAT:
+ attributes = sicepat_services(origin, destination, weight);
+ break;
default:
break;
}
curl_easy_setopt(curl, CURLOPT_URL, shipping.url);
if (shipping.post)
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, shipping.post);
+ else
+ curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
shipping.mode = SERVICES;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, attributes);
curl_easy_perform(curl);
@@ -214,7 +225,8 @@ char *pikul_order(const char *order_number, const char *service, const char *sen
#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)
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..9ea4af5
--- /dev/null
+++ b/sicepat.c
@@ -0,0 +1,41 @@
+#include <stdlib.h>
+#include <string.h>
+#include "private.h"
+
+#define BASE "http://api.sicepat.com/customer/"
+
+const char **sicepat_init(char *provisions[])
+{
+ 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)
+{
+ 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;
+}