summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c82
1 files changed, 13 insertions, 69 deletions
diff --git a/main.c b/main.c
index 45ec093..b3e4f4f 100644
--- a/main.c
+++ b/main.c
@@ -2,7 +2,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
-#include <json.h>
#include "icclient.h"
#include "icclient/member.h"
@@ -10,86 +9,31 @@ static void print_catalog(struct icclient_catalog *catalog)
{
for (size_t i = 0; i < catalog->length; i++) {
struct icclient_product *product = catalog->products[i];
- printf("SKU: %s\n"
- "Description: %s\n"
- "Thumb: %s\n"
- "Image: %s\n"
- "Price: %f\n"
- "Product Group: %s\n",
+ printf("sku: %s | "
+ "desc: %s | "
+ "img: %s | "
+ "prc: %f | "
+ "cat: %s\n",
product->sku,
product->description,
- product->thumb,
product->image,
product->price,
- product->prod_group
+ product->category
);
}
icclient_free_catalog(catalog);
}
-
-static void handle_results(icclient_fetch_t *fetch)
-{
- json_tokener *tokener = json_tokener_new();
- json_object *products = json_tokener_parse_ex(tokener, fetch->data, fetch->numBytes);
- json_tokener_free(tokener);
- size_t length = json_object_array_length(products);
- struct icclient_catalog *catalog = malloc(sizeof(struct icclient_catalog) + sizeof(struct icclient_product *[length]));
- catalog->length = length;
- for (size_t i = 0; i < length; i++) {
- catalog->products[i] = malloc(sizeof(struct icclient_product));
- struct icclient_product *product = catalog->products[i];
- memset(product, '\0', sizeof(struct icclient_product));
- json_object *object = json_object_array_get_idx(products, i);
- struct json_object_iterator iterator = json_object_iter_begin(object);
- struct json_object_iterator iterator_end = json_object_iter_end(object);
- while (!json_object_iter_equal(&iterator, &iterator_end)) {
- const char *key = json_object_iter_peek_name(&iterator);
- json_object *val = json_object_iter_peek_value(&iterator);
- if (!strcmp(key, "price"))
- product->price = json_object_get_double(val);
- else {
- int len = json_object_get_string_len(val);
- if (len) {
- char *value = malloc(len + 1);
- strcpy(value, json_object_get_string(val));
- if (!strcmp(key, "sku"))
- product->sku = value;
- else if (!strcmp(key, "thumb"))
- product->thumb = value;
- else if (!strcmp(key, "image"))
- product->image = value;
- else if (!strcmp(key, "description"))
- product->description = value;
- else if (!strcmp(key, "prod_group"))
- product->prod_group = value;
- }
- }
- json_object_iter_next(&iterator);
- }
- }
- ((void (*)(struct icclient_catalog *))fetch->userData)(catalog);
-}
-
+/*
static void print_user(icclient_fetch_t *fetch)
{
printf("%s\n", fetch->data);
}
-
+*/
int main(int argc, char *argv[])
{
- char *url_line = NULL;
- printf("\nURL: ");
- ssize_t url_nread = getline(&url_line, &(size_t){0}, stdin);
- char *url = malloc(--url_nread + 1);
- strncpy(url, url_line, url_nread);
- free(url_line);
-
- printf("\n");
- icclient_init(url, NULL);
- free(url);
-
- icclient_allproducts(print_catalog, handle_results);
-
+ icclient_init("https://demo.interchangecommerce.org/i/demo", "/demo/images", NULL);
+ icclient_allproducts(print_catalog, NULL);
+/*
char *name_line = NULL;
printf("\nName: ");
ssize_t name_nread = getline(&name_line, &(size_t){0}, stdin);
@@ -108,7 +52,7 @@ int main(int argc, char *argv[])
struct icclient_member *member = icclient_member_login(name, pass, NULL, NULL, NULL, print_user);
free(name);
free(pass);
- //icclient_member_logout(member);
-
+ icclient_member_logout(member);
+*/
icclient_cleanup();
}