Sha256: d17496e3dbaf9d790ecb42443c07ab377305a3c6d48fa7265b43c489487524bf

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module CanvasFactory
  # assignment class
  class Assignment
    attr_reader :id, :name, :course_id, :html_url, :grading_type, :published, :due_at,
                :created_at, :request, :response

    def initialize(course_id, opts = {}, merge = true)
      @course_id = course_id
      @request = {
        assignment: {
          name: "Assignment-#{Time.now.to_i}",
          grading_type: %w(pass_fail percent letter_grade gpa_scale points).sample,
          submission_types: ['online_text_entry'],
          points_possible: 10,
          due_at: (DateTime.now + 1).iso8601,
          published: true
        }
      }
      @request = Mergie.deep_merge(@request, opts, merge)
      create_assignment
      self
    end

    private

    def create_assignment
      assign_end_point = "#{CANVAS_API_V1}/courses/#{@course_id}/assignments"
      @response = CanvasFactory.perform_post(assign_end_point, @request)
      @id = response['id']
      @name = response['name']
      @html_url = response['html_url']
      @grading_type = response['grading_type']
      @published = response['published']
      @created_at = response['created_at']
      @due_at = response['due_at']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
japanda-0.1.6 lib/japanda/canvas_factory/assignment.rb
japanda-0.1.5 lib/japanda/canvas_factory/assignment.rb
japanda-0.1.4 lib/japanda/canvas_factory/assignment.rb