2 * Copyright (c) 2016, 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>
31 int main(int argc
, char **argv
)
41 char *drop_lowest_arg
= 0;
42 long long drop_lowest_ll
= 0;
43 char *drop_lowest
= 0;
44 char *drop_highest_arg
= 0;
45 long long drop_highest_ll
= 0;
46 char *drop_highest
= 0;
49 struct curl_httppost
*post
= 0;
53 setlocale(LC_ALL
, "");
55 while ((opt
= getopt(argc
, argv
, "c:n:w:d:D:")) != -1) {
67 drop_lowest_arg
= optarg
;
70 drop_highest_arg
= optarg
;
79 fprintf(stderr
, "course-id is mandatory\n");
85 fprintf(stderr
, "name is mandatory\n");
90 weight_d
= strtod(weight_arg
, 0);
91 len
= snprintf(0, 0, "%lf", weight_d
);
94 ret
= errno
= EOVERFLOW
;
99 if (!(weight
= malloc(len
+ 1))) {
105 sprintf(weight
, "%lf", weight_d
);
108 if (drop_lowest_arg
) {
109 drop_lowest_ll
= strtoll(drop_lowest_arg
, 0, 0);
110 len
= snprintf(0, 0, "%lld", drop_lowest_ll
);
113 ret
= errno
= EOVERFLOW
;
118 if (!(drop_lowest
= malloc(len
+ 1))) {
124 sprintf(drop_lowest
, "%lld", drop_lowest_ll
);
127 if (drop_highest_arg
) {
128 drop_highest_ll
= strtoll(drop_highest_arg
, 0, 0);
129 len
= snprintf(0, 0, "%lld", drop_highest_ll
);
132 ret
= errno
= EOVERFLOW
;
137 if (!(drop_highest
= malloc(len
+ 1))) {
143 sprintf(drop_highest
, "%lld", drop_highest_ll
);
146 curl_global_init(CURL_GLOBAL_DEFAULT
);
148 if (!(url_base
= get_url_base())) {
151 /* Error should have already been printed */
155 if (!(auth_token
= get_auth_token())) {
158 /* Error should have already been printed */
162 len
= snprintf(0, 0, "%s/api/v1/courses/%s/assignment_groups", url_base
,
166 ret
= errno
= EOVERFLOW
;
171 if (!(built_uri
= malloc(len
+ 1))) {
177 sprintf(built_uri
, "%s/api/v1/courses/%s/assignment_groups", url_base
,
180 if (!(post
= make_agroup_post(name
, weight
, drop_lowest
,
182 /* XXX: pass back proper error code from make_agroup_post() */
186 if ((ret
= send_and_id_scan(built_uri
, auth_token
, post
, "POST",
192 printf("%s\n", new_id
);
205 curl_global_cleanup();