Compare commits
2 Commits
25d4b373ce
...
5392d6c936
Author | SHA1 | Date | |
---|---|---|---|
5392d6c936 | |||
e879a947d8 |
@ -5,8 +5,8 @@
|
||||
|
||||
#include "include/curl.h"
|
||||
|
||||
#define API_URL "https://openlibrary.org/search.json?q="
|
||||
#define API_URL_LEN 38
|
||||
#define API_URL "https://openlibrary.org/search.json?page=1&q="
|
||||
#define API_URL_LEN 45
|
||||
|
||||
static void setup_api_link(const char* isbn, char** buf)
|
||||
{
|
||||
|
13
src/main.c
13
src/main.c
@ -7,6 +7,7 @@
|
||||
#include "include/json.h"
|
||||
|
||||
struct flags {
|
||||
char* isbn;
|
||||
bool json, db, print;
|
||||
};
|
||||
|
||||
@ -17,8 +18,8 @@ const char* argp_program_bug_address = "supernovaa41@gmx.com";
|
||||
static char doc[] = "Lookup details of a book from the ISBN. Using OpenLibrary API.";
|
||||
static char args_doc[] = "<ISBN>";
|
||||
static struct argp_option options[] = {
|
||||
{0, 'j', "json", 0, "output to json", 0},
|
||||
{0, 'd', "db", 0, "output to sqlite3 database", 0},
|
||||
{"json", 'j', 0, 0, "output to json", 0},
|
||||
{"db", 'd', 0, 0, "output to sqlite3 database", 0},
|
||||
{0, 'p', 0, 0, "print the full json response", 0},
|
||||
{0}
|
||||
};
|
||||
@ -44,7 +45,12 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state)
|
||||
case 'p':
|
||||
flags->print = true;
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
flags->isbn = arg;
|
||||
break;
|
||||
case ARGP_KEY_END:
|
||||
if (state->arg_num < 1)
|
||||
argp_usage(state);
|
||||
break;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
@ -63,7 +69,8 @@ int main(int argc, char* argv[])
|
||||
init_flags(&flags);
|
||||
argp_parse(&argp, argc, argv, 0, 0, &flags);
|
||||
|
||||
book_api_call("9780762437818", &resp);
|
||||
//book_api_call("9780762437818", &resp);
|
||||
book_api_call(flags.isbn, &resp);
|
||||
|
||||
if (flags.print)
|
||||
puts(resp.buf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user