Sha256: 50d165e701e4d2b241a612f7390287ec08e0a83c7de6fa892a8c4d5a1d8def7a

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

module AbsorbApi
  class CourseEnrollment < Base
    attr_accessor :id, :course_id, :course_name, :course_version_id, :user_id, :full_name, :status, :progress, :score, :accepted_terms_and_conditions, :time_spent, :date_started, :date_completed, :enrollment_key_id, :certificate_id, :credits

    def lessons(**conditions)
      AbsorbApi.api.get("users/#{self.user_id}/enrollments/#{self.course_id}/lessons", conditions).body.map! do |lesson_attributes|
        LessonEnrollment.new(lesson_attributes)
      end
    end

    # gets all associated lessons given a collection of enrollments
    # all calls are called in parallel
    # enrollments are chunked in groups of 105 to keep typhoeus from getting bogged down
    # modifiedSince must be a DateTime object
    def self.lessons_from_collection(course_enrollments, **filters)
      lessons = []
      course_enrollments.each_slice(105) do |enrollment_slice|
        AbsorbApi.api.in_parallel do
          enrollment_slice.each do |enrollment|
            lessons << AbsorbApi.api.get("users/#{enrollment.user_id}/enrollments/#{enrollment.course_id}/lessons", filters)
          end
        end
      end
      lessons.map { |response| response.body.map { |body| LessonEnrollment.new(body) } }.flatten.reject { |lesson| AbsorbApi.configuration.ignored_lesson_types.include? lesson.type }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
absorb_api-0.1.11 lib/absorb_api/course_enrollment.rb
absorb_api-0.1.10 lib/absorb_api/course_enrollment.rb
absorb_api-0.1.9 lib/absorb_api/course_enrollment.rb
absorb_api-0.1.8 lib/absorb_api/course_enrollment.rb
absorb_api-0.1.7 lib/absorb_api/course_enrollment.rb