Module: CourseSubjects

Included in:
Spartacus
Defined in:
lib/client/course_subjects.rb

Instance Method Summary collapse

Instance Method Details

#create_course_subject(name, display_name, occupation_name, options = {}) ⇒ CourseSubject

Create a course subject

Examples:

Create a course subject

Spartacus#create_course_subject()

Parameters:

  • name (String)

    Name of the subject.

  • display_name (String)

    User friendly name of the subject.

  • occupation_name (String)

    Name of a person who has this job.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :default_goal_options (Array)

    Default goal options.

  • :director_id (Integer)

    Id of the course director.

  • :director_slug (String)

    User friendly director name.

Returns:

  • (CourseSubject)

    The created course subject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/client/course_subjects.rb', line 15

def create_course_subject(name, display_name, occupation_name, options={})
  whitelist = ['default_goal_options', 'director_id', 'director_slug']

  options = convert_keys(options)
  course_subject_params = whitelist_params(options, whitelist)
  course_subject_params.merge!({ name: name, display_name: display_name, occupation_name: occupation_name })
  url = "#{@api_base_path}/course_subjects"

  handle_timeouts do
    response = self.class.post(url,
                               headers: auth_header,
                               body: { course_subject: course_subject_params })
    convert_response(response, "course_subject")
  end
end

#update_course_subject(id, options = {}) ⇒ CourseSubject

Update a course subject

Examples:

Update a course subject

Spartacus#update_course_subject()

Parameters:

  • id (Integer)

    A course subject id.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :name (String)

    Name of the subject.

  • :display_name (String)

    User friendly name of the subject.

  • :occupation_name (String)

    Name of a person who has this job.

  • :default_goal_options (Array)

    Default goal options.

  • :director_id (Integer)

    Id of the course director.

  • :director_slug (String)

    User friendly director name.

Returns:

  • (CourseSubject)

    The updated course subject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/client/course_subjects.rb', line 44

def update_course_subject(id, options={})
  whitelist = ['name', 'display_name', 'occupation_name', 'default_goal_options', 'director_id', 'director_slug']

  options = convert_keys(options)
  course_subject_params = whitelist_params(options, whitelist)
  url = "#{@api_base_path}/course_subjects/#{id}"

  handle_timeouts do
    response = self.class.put(url,
                               headers: auth_header,
                               body: { course_subject: course_subject_params })
    convert_response(response, "course_subject")
  end
end