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
|
#include "common.h"
#define BASE "http://api.sicepat.com/customer/"
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);
}
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;
}
|