2 * Copyright (c) 2016-2019 S. Gilles <sgilles@math.umd.edu>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include <curl/curl.h>
25 #include <yajl_parse.h>
31 list_courses(const char *url_base
, const char *auth_token
)
37 const char *fn_courses
[] = { "id", "name", 0 };
39 char **courses_ids
= 0;
41 size_t courses_num
= 0;
43 len
= snprintf(0, 0, "%s/api/v1/courses?per_page=9999", url_base
);
46 ret
= errno
= EOVERFLOW
;
51 if (!(built_uri
= malloc(len
+ 1))) {
57 sprintf(built_uri
, "%s/api/v1/courses?per_page=9999", url_base
);
59 if ((ret
= key_value_extract(built_uri
, auth_token
, fn_courses
, 0,
64 map_get_keys(&courses
, &courses_ids
, &courses_num
);
66 for (j
= 0; j
< courses_num
; ++j
) {
67 c
= map_get(&courses
, courses_ids
[j
]);
70 printf("%s %s\n", courses_ids
[j
], c
[0]);
89 setlocale(LC_ALL
, "");
90 curl_global_init(CURL_GLOBAL_DEFAULT
);
92 if (!(url_base
= get_url_base())) {
95 /* Error should have already been printed */
99 if (!(auth_token
= get_auth_token())) {
102 /* Error should have already been printed */
106 if ((ret
= list_courses(url_base
, auth_token
))) {
114 curl_global_cleanup();