Sha256: 9c002fb54cf5af0bc1e6f513c0b1b44b39da4025c9f423758e378c7d75870efa

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 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)
      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|
        api.in_parallel do
          enrollment_slice.each do |enrollment|
            lessons << 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

2 entries across 2 versions & 1 rubygems

Version Path
absorb_api-0.1.6 lib/absorb_api/course_enrollment.rb
absorb_api-0.1.5 lib/absorb_api/course_enrollment.rb