Exemplo n.º 1
0
        private Task <HttpResponseMessage> RawGetSingleAssignment(string courseId,
                                                                  string assignmentId,
                                                                  AssignmentInclusions inclusions,
                                                                  bool?overrideAssignmentDates,
                                                                  bool?needsGradingCountBySection,
                                                                  bool?allDates)
        {
            var args = inclusions.GetTuples()
                       .Append(("override_assignment_dates", overrideAssignmentDates?.ToShortString()))
                       .Append(("needs_grading_count_by_section", needsGradingCountBySection?.ToShortString()))
                       .Append(("all_dates", allDates?.ToShortString()));

            var url = $"courses/{courseId}/assignments/{assignmentId}" + BuildQueryString(args.ToArray());

            return(_client.GetAsync(url));
        }
Exemplo n.º 2
0
 private Task <HttpResponseMessage> RawListCourseAssignments(string courseId,
                                                             AssignmentInclusions inclusions,
                                                             [CanBeNull] string searchTerm,
                                                             bool?overrideAssignmentDates,
                                                             bool?needsGradingCountBySection,
                                                             AssignmentBucket?bucket,
                                                             [CanBeNull] IEnumerable <ulong> assignmentIds,
                                                             [CanBeNull] string orderBy)
 {
     return(RawListAssignmentsGeneric($"courses/{courseId}/assignments",
                                      inclusions,
                                      searchTerm,
                                      overrideAssignmentDates,
                                      needsGradingCountBySection,
                                      bucket,
                                      assignmentIds,
                                      orderBy));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a single assignment from this course.
        /// </summary>
        /// <param name="courseId">The course id.</param>
        /// <param name="assignmentId">The assignment id.</param>
        /// <param name="inclusions">Optional extra data to include in the assignment response.</param>
        /// <param name="overrideAssignmentDates">Apply assignment overrides to dates. Defaults to true.</param>
        /// <param name="needsGradingCountBySection">Split the NeedsGradingCount key into sections. Defaults to false.</param>
        /// <param name="allDates">Return all dates associated with the assignment, if applicable.</param>
        /// <returns>The assignment.</returns>
        /// <seealso cref="AssignmentInclusions"/>
        public async Task <Assignment> GetAssignment(ulong courseId,
                                                     ulong assignmentId,
                                                     AssignmentInclusions inclusions = AssignmentInclusions.Default,
                                                     bool?overrideAssignmentDates    = null,
                                                     bool?needsGradingCountBySection = null,
                                                     bool?allDates = null)
        {
            var response = await RawGetSingleAssignment(courseId.ToString(),
                                                        assignmentId.ToString(),
                                                        inclusions,
                                                        overrideAssignmentDates,
                                                        needsGradingCountBySection,
                                                        allDates);

            response.AssertSuccess();

            var model = JsonConvert.DeserializeObject <AssignmentModel>(await response.Content.ReadAsStringAsync());

            return(new Assignment(this, model));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Streams all assignments in this course that are visible to the current user.
        /// </summary>
        /// <param name="courseId">The course id.</param>
        /// <param name="inclusions">Optional extra data to include in the assignment response.</param>
        /// <param name="searchTerm">An optional search term.</param>
        /// <param name="overrideAssignmentDates">Apply assignment overrides to dates. Defaults to true.</param>
        /// <param name="needsGradingCountBySection">Split the NeedsGradingCount key into sections. Defaults to false.</param>
        /// <param name="bucket">An optional bucket to filter the returned assignments by.</param>
        /// <param name="assignmentIds">An optional list of ids to filter the returned assignments by.</param>
        /// <param name="orderBy">An optional string determining the order of assignments.</param>
        /// <returns>The stream of assignments.</returns>
        /// <seealso cref="AssignmentInclusions"/>
        /// <seealso cref="AssignmentBucket"/>
        public async IAsyncEnumerable <Assignment> StreamCourseAssignments(ulong courseId,
                                                                           AssignmentInclusions inclusions = AssignmentInclusions.Default,
                                                                           string searchTerm                 = null,
                                                                           bool?overrideAssignmentDates      = null,
                                                                           bool?needsGradingCountBySection   = null,
                                                                           AssignmentBucket?bucket           = null,
                                                                           IEnumerable <ulong> assignmentIds = null,
                                                                           string orderBy = null)
        {
            var response = await RawListCourseAssignments(courseId.ToString(),
                                                          inclusions,
                                                          searchTerm,
                                                          overrideAssignmentDates,
                                                          needsGradingCountBySection,
                                                          bucket,
                                                          assignmentIds,
                                                          orderBy);

            await foreach (var model in StreamDeserializePages <AssignmentModel>(response))
            {
                yield return(new Assignment(this, model));
            }
        }
Exemplo n.º 5
0
        private Task <HttpResponseMessage> RawListAssignmentsGeneric(string url,
                                                                     AssignmentInclusions inclusions,
                                                                     [CanBeNull] string searchTerm,
                                                                     bool?overrideAssignmentDates,
                                                                     bool?needsGradingCountBySection,
                                                                     AssignmentBucket?bucket,
                                                                     [CanBeNull] IEnumerable <ulong> assignmentIds,
                                                                     [CanBeNull] string orderBy)
        {
            var args = inclusions.GetTuples()
                       .Append(("search_term", searchTerm))
                       .Append(("override_assignment_dates", overrideAssignmentDates?.ToShortString()))
                       .Append(("needs_grading_count_by_section", needsGradingCountBySection?.ToShortString()))
                       .Append(("bucket", bucket?.GetApiRepresentation()))
                       .Append(("order_by", orderBy));

            if (assignmentIds != null)
            {
                args = args.Concat(assignmentIds.Select(id => id.ToString())
                                   .Select(s => ("assignment_ids[]", s)));
            }

            return(_client.GetAsync(url + BuildQueryString(args.ToArray())));
        }
Exemplo n.º 6
0
 internal static IEnumerable <(string, string)> GetTuples(this AssignmentInclusions includes)
 {
     return(includes.GetFlags().Select(f => ("include[]", f.GetApiRepresentation())).ToList());
 }