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.
25 #include <curl/curl.h>
26 #include <yajl_parse.h>
32 main(int argc
, char **argv
)
38 char *assignment_id
= 0;
40 char *max_points_arg
= 0;
41 double max_points_d
= 0;
47 struct curl_httppost
*post
= 0;
50 setlocale(LC_ALL
, "");
52 while ((opt
= getopt(argc
, argv
, "a:c:n:m:d:g:")) != -1) {
58 assignment_id
= optarg
;
64 max_points_arg
= optarg
;
79 fprintf(stderr
, "course-id is mandatory\n");
85 fprintf(stderr
, "assignment-id is mandatory\n");
90 max_points_d
= strtod(max_points_arg
, 0);
91 len
= snprintf(0, 0, "%lf", max_points_d
);
94 ret
= errno
= EOVERFLOW
;
99 if (!(max_points
= malloc(len
+ 1))) {
105 sprintf(max_points
, "%lf", max_points_d
);
108 curl_global_init(CURL_GLOBAL_DEFAULT
);
110 if (!(url_base
= get_url_base())) {
113 /* Error should have already been printed */
117 if (!(auth_token
= get_auth_token())) {
120 /* Error should have already been printed */
124 len
= snprintf(0, 0, "%s/api/v1/courses/%s/assignments/%s", url_base
,
125 course_id
, assignment_id
);
128 ret
= errno
= EOVERFLOW
;
133 if (!(built_uri
= malloc(len
+ 1))) {
139 sprintf(built_uri
, "%s/api/v1/courses/%s/assignments/%s", url_base
,
140 course_id
, assignment_id
);
142 if (!(post
= make_assignment_post(name
, max_points
, due_date
,
144 /* XXX: pass back proper error code from make_assignment_post() */
148 if ((ret
= send_and_id_scan(built_uri
, auth_token
, post
, "PUT", 0))) {
159 curl_global_cleanup();