summaryrefslogtreecommitdiff
path: root/anteraja.c
diff options
context:
space:
mode:
Diffstat (limited to 'anteraja.c')
-rw-r--r--anteraja.c86
1 files changed, 41 insertions, 45 deletions
diff --git a/anteraja.c b/anteraja.c
index 057b22e..87438dd 100644
--- a/anteraja.c
+++ b/anteraja.c
@@ -1,4 +1,6 @@
-#include "common.h"
+#include <stdlib.h>
+#include <string.h>
+#include "private.h"
#define SERVICES_PATH "serviceRates"
#define SERVICES_POST \
@@ -50,56 +52,55 @@
#define ORDER_ITEM_PRICE 9
#define ORDER_ITEM_WEIGHT 5
-static const char *status_trail[] = { "status", NULL };
static char *prefix = NULL;
-void anteraja_init(char *provisions[])
+const char **anteraja_init(char *provisions[])
{
- enum { BASE_PATH, ACCESS_KEY_ID, SECRET_ACCESS_KEY, PREFIX };
+ enum { ACCESS_KEY_ID, SECRET_ACCESS_KEY, BASE_PATH, PREFIX };
shipping.base = malloc(strlen(provisions[BASE_PATH]) + 1);
strcpy(shipping.base, provisions[BASE_PATH]);
- headers((const char *[]){ "access-key-id", "secret-access-key", NULL }, &provisions[ACCESS_KEY_ID]);
- shipping.headers = curl_slist_append(shipping.headers, "Content-Type:application/json");
if (provisions[PREFIX]) {
prefix = malloc(strlen(provisions[PREFIX]) + 1);
strcpy(prefix, provisions[PREFIX]);
}
+ shipping.headers = curl_slist_append(shipping.headers, "Content-Type:application/json");
+ static const char *status_trail[] = { "status", NULL };
+ shipping.status_trail = status_trail;
+ static const char *fields[] = { "access-key-id", "secret-access-key", NULL };
+ return fields;
}
-void anteraja_services(const char *origin, const char *destination, double weight, char **url, char **post)
-{
- *url = malloc(strlen(shipping.base) + strlen(SERVICES_PATH) + 1);
- sprintf(*url, "%s%s", shipping.base, SERVICES_PATH);
- *post = malloc(strlen(SERVICES_POST) + strlen(origin) + strlen(destination) + SERVICES_WEIGHT
- - 2 * strlen("%s") - strlen("%d") + 1);
- sprintf(*post, SERVICES_POST, origin, destination, weight < 1.0 ? 1000 : (int)weight * 1000);
-}
-
-size_t anteraja_services_handle(const char *contents, size_t size, size_t nmemb,
- struct pikul_services **services)
+const char **anteraja_services(const char *origin, const char *destination, double weight)
{
- size_t realsize = size * nmemb;
- handle(SERVICES, contents, realsize, status_trail, (const char *[]){
- "content",
- "services",
- NULL
- }, (const char *[]){
- "product_code",
- "product_name",
- "etd",
- "rates"
- }, services);
- return realsize;
+ shipping.url = malloc(strlen(shipping.base) + strlen(SERVICES_PATH) + 1);
+ sprintf(shipping.url, "%s%s", shipping.base, SERVICES_PATH);
+ shipping.post = malloc(strlen(SERVICES_POST) + strlen(origin) + strlen(destination)
+ + SERVICES_WEIGHT - 2 * strlen("%s") - strlen("%d") + 1);
+ sprintf(shipping.post, SERVICES_POST, origin, destination,
+ weight < 1.0 ? 1000 : (int)weight * 1000);
+ static const char *trail[] = {
+ "content",
+ "services",
+ NULL
+ };
+ shipping.trail = trail;
+ static const char *attributes[] = {
+ "product_code",
+ "product_name",
+ "etd",
+ "rates"
+ };
+ return attributes;
}
void anteraja_order(const char *order_number, const char *service, const char *sender_name,
const char *sender_phone, const char *origin, const char *sender_address,
const char *sender_postal, const char *receiver_name, const char *receiver_phone,
const char *destination, const char *receiver_address, const char *receiver_postal,
- int nitems, char **items[], double subtotal, char **url, char **post)
+ int nitems, char **items[], double subtotal)
{
- *url = malloc(strlen(shipping.base) + strlen(ORDER_PATH) + 1);
- sprintf(*url, "%s%s", shipping.base, ORDER_PATH);
+ shipping.url = malloc(strlen(shipping.base) + strlen(ORDER_PATH) + 1);
+ sprintf(shipping.url, "%s%s", shipping.base, ORDER_PATH);
enum { SKU, QUANTITY, DESCRIPTION, PRICE, WEIGHT };
char *json = NULL;
double total_weight = .0;
@@ -131,27 +132,22 @@ void anteraja_order(const char *order_number, const char *service, const char *s
else
json[strlen(json)] = '\0';
}
- *post = malloc(strlen(ORDER_POST) + strlen(prefix) + strlen(order_number) + strlen(service)
+ shipping.post = malloc(strlen(ORDER_POST) + strlen(prefix) + strlen(order_number) + strlen(service)
+ ORDER_WEIGHT + strlen(sender_name) + strlen(sender_phone) + strlen(origin)
+ strlen(sender_address) + strlen(sender_postal) + strlen(receiver_name)
+ strlen(receiver_phone) + strlen(destination) + strlen(receiver_address)
+ strlen(receiver_postal) + strlen(json) + ORDER_INSURANCE + ORDER_SUBTOTAL
- 15 * strlen("%s") - 2 * strlen("%d") + 1);
- sprintf(*post, ORDER_POST, prefix, order_number, service, (int)total_weight, sender_name,
+ sprintf(shipping.post, ORDER_POST, prefix, order_number, service, (int)total_weight, sender_name,
sender_phone, origin, sender_address, sender_postal, receiver_name, receiver_phone,
destination, receiver_address, receiver_postal, json,
total_weight < 1000.0 ? "true" : "false", subtotal < 1000.0 ? 1000 : (int)subtotal);
-}
-
-size_t anteraja_order_handle(const char *contents, size_t size, size_t nmemb, char **tracking_number)
-{
- size_t realsize = size * nmemb;
- handle(ORDER, contents, realsize, status_trail, (const char *[]){
- "content",
- "waybill_no",
- NULL
- }, NULL, tracking_number);
- return realsize;
+ static const char *trail[] = {
+ "content",
+ "waybill_no",
+ NULL
+ };
+ shipping.trail = trail;
}
void anteraja_cleanup()