2 * Copyright (c) 2016-2018 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
)
42 char *drop_lowest_arg
= 0;
43 long long drop_lowest_ll
= 0;
44 char *drop_lowest
= 0;
45 char *drop_highest_arg
= 0;
46 long long drop_highest_ll
= 0;
47 char *drop_highest
= 0;
50 struct curl_httppost
*post
= 0;
54 setlocale(LC_ALL
, "");
56 while ((opt
= getopt(argc
, argv
, "c:n:w:d:D:")) != -1) {
68 drop_lowest_arg
= optarg
;
71 drop_highest_arg
= optarg
;
80 fprintf(stderr
, "course-id is mandatory\n");
86 fprintf(stderr
, "name is mandatory\n");
91 weight_d
= strtod(weight_arg
, 0);
92 len
= snprintf(0, 0, "%lf", weight_d
);
95 ret
= errno
= EOVERFLOW
;
100 if (!(weight
= malloc(len
+ 1))) {
106 sprintf(weight
, "%lf", weight_d
);
109 if (drop_lowest_arg
) {
110 drop_lowest_ll
= strtoll(drop_lowest_arg
, 0, 0);
111 len
= snprintf(0, 0, "%lld", drop_lowest_ll
);
114 ret
= errno
= EOVERFLOW
;
119 if (!(drop_lowest
= malloc(len
+ 1))) {
125 sprintf(drop_lowest
, "%lld", drop_lowest_ll
);
128 if (drop_highest_arg
) {
129 drop_highest_ll
= strtoll(drop_highest_arg
, 0, 0);
130 len
= snprintf(0, 0, "%lld", drop_highest_ll
);
133 ret
= errno
= EOVERFLOW
;
138 if (!(drop_highest
= malloc(len
+ 1))) {
144 sprintf(drop_highest
, "%lld", drop_highest_ll
);
147 curl_global_init(CURL_GLOBAL_DEFAULT
);
149 if (!(url_base
= get_url_base())) {
152 /* Error should have already been printed */
156 if (!(auth_token
= get_auth_token())) {
159 /* Error should have already been printed */
163 len
= snprintf(0, 0, "%s/api/v1/courses/%s/assignment_groups", url_base
,
167 ret
= errno
= EOVERFLOW
;
172 if (!(built_uri
= malloc(len
+ 1))) {
178 sprintf(built_uri
, "%s/api/v1/courses/%s/assignment_groups", url_base
,
181 if (!(post
= make_agroup_post(name
, weight
, drop_lowest
,
183 /* XXX: pass back proper error code from make_agroup_post() */
187 if ((ret
= send_and_id_scan(built_uri
, auth_token
, post
, "POST",
193 printf("%s\n", new_id
);
206 curl_global_cleanup();