summaryrefslogtreecommitdiff
path: root/sicepat.c
blob: 8e194120c3cfd2d745f9a720aeb8758378415d62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdlib.h>
#include <string.h>
#include "private.h"

#define BASE "https://api.sicepat.com/customer/"
#define ORIGINS "origin"
#define DESTINATIONS "destination"

const char **sicepat_init(char *provisions[])
{
	struct shipping *shipping = shipping_list[PIKUL_SICEPAT];
	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_origins()
{
	struct shipping *shipping = shipping_list[PIKUL_SICEPAT];
	shipping->url = malloc(strlen(BASE) + strlen(ORIGINS) + 1);
	sprintf(shipping->url, "%s%s", BASE, ORIGINS);
	static const char *trail[] = {
		"sicepat",
		"results",
		NULL
	};
	shipping->trail = trail;
       	static const char *attributes[] = {
		"origin_code",
		NULL,
		"origin_name",
		NULL
	};
	return attributes;
}

const char **sicepat_destinations()
{
	struct shipping *shipping = shipping_list[PIKUL_SICEPAT];
	shipping->url = malloc(strlen(BASE) + strlen(DESTINATIONS) + 1);
	sprintf(shipping->url, "%s%s", BASE, DESTINATIONS);
	static const char *trail[] = {
		"sicepat",
		"results",
		NULL
	};
	shipping->trail = trail;
       	static const char *attributes[] = {
		"destination_code",
		"subdistrict",
		"city",
		"province"
	};
	return attributes;
}

const char **sicepat_services(const char *origin, const char *destination, double weight)
{
	struct shipping *shipping = shipping_list[PIKUL_SICEPAT];
	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;
}