class Object
Public Instance Methods
# File lib/d2l_sdk/requests.rb, line 254 def _course_content_upload(path, json, file, method) # name = the content name, # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers" # filename = the File's name in the directory. # method = POST or PUT # json = the json appended to the end of the request body # auth_uri = path auth_uri = create_authenticated_uri(path, method) uri = URI.parse(auth_uri) boundary = "xxBOUNDARYxx" header = { "Content-Type" => "multipart/mixed; boundary=#{boundary}" } # setup the post body post_body = [] post_body << "--#{boundary}\r\n" post_body << "Content-Type: application/json\r\n\r\n" post_body << json.to_json post_body << "\r\n" post_body << "--#{boundary}\r\n" post_body << "Content-Disposition: form-data; name = \"\"; filename=\"#{File.basename(file)}\"\r\n\r\n" post_body << "Content-Type: text/plain\r\n" post_body << File.read(file) post_body << "\r\n\r\n--#{boundary}--\r\n" # Create the HTTP objects http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri, header) request.body = post_body.join # Send the request response = http.request(request) JSON.parse(response) end
Upload a file to the learning repository.
# File lib/d2l_sdk/requests.rb, line 153 def _course_package_upload(path, file, method) # name = the content name, # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers" # file = the File's name in the directory. # method = POST or PUT # json = the json appended to the end of the request body # auth_uri = path auth_uri = create_authenticated_uri(path, method) uri = URI.parse(auth_uri) boundary = "xxBOUNDARYxx" header = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" } # setup the post body post_body = [] post_body << "--#{boundary}\n" post_body << "Content-Disposition: form-data; name = \"Resource\"; filename=\"#{File.basename(file)}\"\r\n" post_body << "Content-Type: #{MIME::Types.type_for(file)}\r\n\r\n" post_body << File.read(file) post_body << "\r\n\r\n--#{boundary}--\r\n" # Create the HTTP objects http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri, header) request.body = post_body.join # Send the request response = http.request(request) JSON.parse(response) end
Performs a delete request by creating an authenticated uri and using the RestClient delete method and specifying the content_type as being JSON.
# File lib/d2l_sdk/requests.rb, line 107 def _delete(path, isD2l = true, headers = {}) headers[:content_type] = :json auth_uri = path auth_uri = create_authenticated_uri(path, 'DELETE') if isD2l == true RestClient.delete(auth_uri, headers) end
# File lib/d2l_sdk/requests.rb, line 290 def _dropbox_upload(path, json, file, method) # name = the content name, # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers" # filename = the File's name in the directory. # method = POST or PUT # json = the json appended to the end of the request body # auth_uri = path auth_uri = create_authenticated_uri(path, method) uri = URI.parse(auth_uri) boundary = "xxBOUNDARYxx" header = { "Content-Type" => "multipart/mixed; boundary=#{boundary}" } # setup the post body post_body = [] post_body << "--#{boundary}\r\n" post_body << "Content-Type: application/json\r\n\r\n" post_body << json.to_json # e.g. {"Text" => "Here you go", "Html" => null} post_body << "\r\n" post_body << "--#{boundary}\r\n" post_body << "Content-Disposition: form-data; name = \"\"; filename=\"#{File.basename(file)}\"\r\n" post_body << "Content-Type: #{MIME::Types.type_for(file)}\r\n\r\n" post_body << File.read(file) post_body << "\r\n\r\n--#{boundary}--\r\n" # Create the HTTP objects http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri, header) request.body = post_body.join # Send the request response = http.request(request) JSON.parse(response) end
# File lib/d2l_sdk/requests.rb, line 214 def _ePortfolio_upload(path, file, method, description) # name = the content name, # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers" # filename = the File's name in the directory. # method = POST or PUT # json = the json appended to the end of the request body # auth_uri = path auth_uri = create_authenticated_uri(path, method) uri = URI.parse(auth_uri) boundary = "xxBOUNDARYxx" header = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" } # setup the post body post_body = [] post_body << "--#{boundary}\r\n" post_body << "Content-Type: text/plain\r\n" post_body << "Content-Disposition: form-data; name = \"name\"\r\n\r\n" post_body << "#{File.basename(file)}\r\n" post_body << "--#{boundary}\r\n" post_body << "Content-Type: text/plain\r\n" post_body << "Content-Disposition: form-data; name = \"description\"\r\n\r\n" post_body << "#{description}\r\n" post_body << "--#{boundary}\r\n" post_body << "Content-Type: text/plain\r\n" post_body << "Content-Disposition: form-data; name = \"file\"; filename=\"#{File.basename(file)}\"\r\n\r\n" post_body << File.read(file) post_body << "\r\n\r\n--#{boundary}--\r\n" # Create the HTTP objects http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri, header) request.body = post_body.join # Send the request response = http.request(request) JSON.parse(response) end
performs a get request on a particular path of the host. To do this, a uniform resource identifier string is created using the path and specifying that this is a get request. Then, the RestClient get method is used to retrieve the data and parse it as a JSON. Then, the parsed response is returned. Otherwise, nothing is returned and the response code is printed
returns: JSON parsed response.
# File lib/d2l_sdk/requests.rb, line 18 def _get(path, isD2l = true) uri_string = path uri_string = create_authenticated_uri(path, 'GET') if isD2l == true ap uri_string if @debug RestClient.get(uri_string) do |response, _request, _result| begin # ap _request case response.code when 200 # ap JSON.parse(response) # Here is the JSON fmt'd response printed JSON.parse(response) else display_response_code(response.code) ap JSON.parse(response.body) if @debug end rescue # => e display_response_code(response.code) ap JSON.parse(response.body) if @debug raise end end end
# File lib/d2l_sdk/requests.rb, line 41 def _get_raw(path, isD2l = true) uri_string = path uri_string = create_authenticated_uri(path, 'GET') if isD2l == true RestClient.get(uri_string) do |response, _request, _result| begin case response.code when 200 # ap JSON.parse(response) # Here is the JSON fmt'd response printed response else display_response_code(response.code) ap response.body end rescue # => e display_response_code(response.code) ap response.body raise end end end
Used as a helper method for create_authenticated_uri
in order to properly create a query string that will (hopefully) work with the Valence API. the arguments path and http_method are used as arguments with the current time for format_signature
and build_authenticated_uri_query_string
.
returns: String::query_string
# File lib/d2l_sdk/auth.rb, line 85 def _get_string(path, http_method) timestamp = Time.now.to_i signature = format_signature(path, http_method, timestamp) if !path.include? "/auth/api/token" build_authenticated_uri_query_string(signature, timestamp) else # build authenticated query string not using typical schema build_authenticated_token_uri_query_string(signature, timestamp) end # returns: String::query_string end
get_user_by_string uses arguments search_string and range. To use these, a range is created, an array of matching names is initialized, and then the entire range is iterated to check for names that have the search_string in them. Upon reaching a page that has an empty items JSON array, the search ends. This is due to the fact that pages with zero items will not have any more users past them. The array of matching names is then returned.
returns: array::matching_names
# File lib/d2l_sdk/user.rb, line 168 def _get_user_by_string(parameter, search_string, range, regex = false) # puts "searching from #{range.min.to_s} to #{range.max.to_s}" baseline = range.min matching_names = [] # Average difference between each paged bookmarks beginnings is 109.6 while baseline.to_i < range.max # path = "/d2l/api/lp/#{$lp_ver}/users/?bookmark=" + baseline.to_s response = get_users_by_bookmark(baseline.to_s) if response['PagingInfo']['HasMoreItems'] == false # ap 'response returned zero items, last page possible for this thread..' return matching_names end response['Items'].each do |user| if regex && !user[parameter].nil? matching_names.push(user) unless (user[parameter] =~ search_string).nil? elsif !user[parameter].nil? matching_names.push(user) if user[parameter].include? search_string end end baseline = response['PagingInfo']['Bookmark'] end matching_names end
REVIEW: image upload process
# File lib/d2l_sdk/requests.rb, line 184 def _image_upload(path, file, method) # name = the content name, # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers" # file = the File's name in the directory. # method = POST or PUT # json = the json appended to the end of the request body # auth_uri = path auth_uri = create_authenticated_uri(path, method) uri = URI.parse(auth_uri) boundary = "xxBOUNDARYxx" header = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" } # setup the post body post_body = [] post_body << "--#{boundary}\n" post_body << "Content-Disposition: form-data; name = \"profileImage\"; filename=\"#{File.basename(file)}\"\r\n" post_body << "Content-Type: image/png\r\n\r\n" post_body << File.read(file) post_body << "\r\n\r\n--#{boundary}--\r\n" # Create the HTTP objects http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri, header) request.body = post_body.join # Send the request response = http.request(request) JSON.parse(response) end
Upload a file to the learning repository.
# File lib/d2l_sdk/requests.rb, line 122 def _learning_repository_upload(path, file, method) # name = the content name, # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers" # file = the File's name in the directory. # method = POST or PUT # json = the json appended to the end of the request body # auth_uri = path auth_uri = create_authenticated_uri(path, method) uri = URI.parse(auth_uri) boundary = "xxBOUNDARYxx" header = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" } # setup the post body post_body = [] post_body << "--#{boundary}\n" post_body << "Content-Disposition: form-data; name = \"Resource\"; filename=\"#{File.basename(file)}\"\r\n" post_body << "Content-Type: application/zip\r\n\r\n" post_body << File.read(file) post_body << "\r\n\r\n--#{boundary}--\r\n" # Create the HTTP objects http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri, header) request.body = post_body.join # Send the request response = http.request(request) JSON.parse(response) end
function to upload 1+ files to a news event. e.g. uploading 2 attachments to a news event (a text file; a png)
# File lib/d2l_sdk/requests.rb, line 328 def _news_upload(path, json, files, method) # name = the content name, # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers" # files = array of filenames # method = POST or PUT # json = the json appended to the end of the request body # auth_uri = path auth_uri = create_authenticated_uri(path, method) uri = URI.parse(auth_uri) boundary = "xxBOUNDARYxx" header = { "Content-Type" => "multipart/mixed; boundary=#{boundary}" } # setup the post body post_body = [] post_body << "--#{boundary}\r\n" post_body << "Content-Type: application/json\r\n\r\n" post_body << json.to_json # e.g. {"Text" => "Here you go", "Html" => null} file_iteration = 0 files.each do |file| post_body << "\r\n--#{boundary}\r\n" post_body << "Content-Disposition: form-data; name = \"file #{file_iteration}\"; filename=\"#{File.basename(file)}\"\r\n" post_body << "Content-Type: text/plain\r\n\r\n" post_body << File.read(file) file_iteration += 1 end post_body << "\r\n\r\n--#{boundary}--\r\n" # Create the HTTP objects http = Net::HTTP.new(uri.host, uri.port) http.set_debug_output($stdout) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri, header) request.body = post_body.join puts request.body # Send the request response = http.request(request) response.body end
performs a post request using the path and the payload arguments. First, an authenticated uri is created to reference a particular resource. Then, the post method is executed using the payload and specifying that it is formatted as JSON.
# File lib/d2l_sdk/requests.rb, line 68 def _post(path, payload, isD2l = true) auth_uri = path auth_uri = create_authenticated_uri(path, 'POST') if isD2l == true RestClient.post(auth_uri, payload.to_json, content_type: :json) do |response| case response.code when 200 return nil if response == "" JSON.parse(response) ap JSON.parse(response.body) else display_response_code(response.code) ap JSON.parse(response.body) if $debug end end end
performs a put request using the path and the payload arguments. After first creating an authenticated uri, the put request is performed using the authenticated uri, the payload argument, and specifying that the payload is formatted in JSON.
# File lib/d2l_sdk/requests.rb, line 88 def _put(path, payload, isD2l = true) auth_uri = path auth_uri = create_authenticated_uri(path, 'PUT') if isD2l == true # Perform the put action, updating the data; Provide feedback to client. RestClient.put(auth_uri, payload.to_json, content_type: :json) do |response| case response.code when 200 return nil if response == "" JSON.parse(response) # ap JSON.parse(response.body) else display_response_code(response.code) ap JSON.parse(response.body) if $debug end end end
bridge function ~~~
# File lib/d2l_sdk/requests.rb, line 370 def _upload_post_data(path, json, files, method) _news_upload(path, json, files, method) end
REVIEW: Add a user to the list of those an auditor is auditing. INPUT:
JSON Param - auditee_id (D2LID as single JSON number) - Auditee to be added
RETURNS: nil?
# File lib/d2l_sdk/enroll.rb, line 210 def add_auditor_auditee(auditor_id, auditee_id) path = "/d2l/api/le/#{$le_ver}/auditing/auditors/#{auditor_id}/auditees/" _post(path, auditee_id) # RETURNS: nil? end
Adds a child to the org unit by using org_unit_id to reference the soon-to-be parent of the child_org_unit and referencing the soon-to-be child through the child_org_unit_id argument. Then, a path is created to reference the children of the soon-to-be parent and executing a post http method that adds the child.
TL;DR, this adds a child org_unit to the children of an org_unit.
# File lib/d2l_sdk/org_unit.rb, line 206 def add_child_org_unit(org_unit_id, child_org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/children/" _post(path, child_org_unit_id) end
TODO: Add a child module
or topic
to a specific module’s structure. Can be used in multiple ways. D2L categorizes it into 3 different ways: –Module: add child module to parent module –Link Topic: add child topic to parent module structure consisting of a LINK
type topic.
–File Topic: add child topic to parent module structure consisting of a FILE
type topic.
INPUT: (depends upon if its module, link topic, or file topic) –Module: POST body containing a ContentObjectData
JSON data block of type Module –Link Topic: POST body containing a ContentObjectData
JSON data block of type Topic
URL property in it points to resource you want to the link to point to.
–File Topic: Multipart/mixed post body w/ 2 parts
1. +ContentObjectData+ JSON data block of type Topic 2. File attachment data itself you want to store in OU content area
Returns (if successful) a JSON data block containing properties of the newly created object
# File lib/d2l_sdk/course_content.rb, line 69 def add_child_to_module(org_unit_id, module_id, child = {}) # POST path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/modules/#{module_id}/structure/" payload = {} # TODO: Add child module to a module if child.key?("module") payload = { "Title" => "title_string", # String "ShortTitle" => "title_short_string", # String "Type" => 0, "ModuleStartDate" => nil, # nil || string:UTCDateTime "ModuleEndDate" => nil, # nil || string:UTCDateTime "ModuleDueDate" => nil, # nil || string:UTCDateTime "IsHidden" => false, "IsLocked" => false, "description" => { "Text" => "blank", "HTML" => "" }, "Duration" => nil, # nil, number }.merge!(child["module"]) _post(path, payload) # TODO: Add child link-type topics to a module elsif child.key?("link") payload = { "Title" => "title_string", # String "ShortTitle" => "title_short_string", # String "Type" => 1, "TopicType" => 3, # <number:TOPIC_T> "Url" => "URL", # the URL you want to fetch when the user opens the link-type topic. "StartDate" => nil, # nil || string:UTCDateTime "EndDate" => nil, # nil || string:UTCDateTime "DueDate" => nil, # nil || string:UTCDateTime "IsHidden" => false, "IsLocked" => false, "OpenAsExternalResource" => nil, # or boolean "description" => { "Text" => "", "HTML" => nil # -or- HTML formatted string }, "MajorUpdate" => nil, # or bool "MajorUpdateText" => "MajorUpdateText", "ResetCompletionTracking" => nil, # or bool "Duration" => nil, # nil, number }.merge!(child["module"]) _post(path, payload) # TODO: Add child file-type topics to a module elsif child.key?("file") _course_content_upload(query_string, payload, file, "POST") end end
Moreso a bridge function, but assists in adding a course to a particular semester. This is done by referencing each of these resources by ids. This returns a 200 response is the ids are correct.
# File lib/d2l_sdk/semester.rb, line 59 def add_course_to_semester(course_id, semester_id) add_child_org_unit(semester_id, course_id) end
REVIEW: Add a group to the group restriction list for a discussion forum topic.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/groupRestrictions/¶ ↑
# File lib/d2l_sdk/discussions.rb, line 276 def add_group_to_group_restriction_list(org_unit_id, forum_id, topic_id, group_id) raise ArgumentError, "Argument 'group_id' is not numeric value." unless group_id.is_a? Numeric path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/groupRestrictions/" payload = { "GroupRestriction" => { "GroupId" => group_id } } _put(path, payload) # RETURNS: ?? end
TODO: Add an attachment to a news item for an org unit. INPUT: Use a multipart/form-data POST body to provide the attachment data to
add to the news item, with the part’s Content-Disposition header’s name field set to “file”.
# File lib/d2l_sdk/news.rb, line 103 def add_news_item_attachment(org_unit_id, news_item_id, attachment_data) # POST /d2l/api/le/(version)/(orgUnitId)/news/(newsItemId)/attachments/ end
performs a post method to assign a parent to a particular child org unit. This is done by first referencing all the parents of the child_ou
and then POSTing the id of another org unit that is to be added to the parents.
# File lib/d2l_sdk/org_unit.rb, line 214 def add_parent_to_org_unit(parent_ou_id, child_ou_id) # Must follow structure of data # (course <-- semester <== org -->custom dept--> dept -->templates--> courses) # Refer to valence documentation for further structural understanding.. path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{child_ou_id}/parents/" _post(path, parent_ou_id) end
Builds an authenticated uniform resource identifier query string that works properly with the Valence API.
Required Variables:
-
app_id, user_id, app_key, user_key
returns: String::'authenticated_uri'
# File lib/d2l_sdk/auth.rb, line 49 def build_authenticated_uri_query_string(signature, timestamp) "?x_a=#{$app_id}"\ "&x_b=#{$user_id}"\ "&x_c=#{get_base64_hash_string($app_key, signature)}"\ "&x_d=#{get_base64_hash_string($user_key, signature)}"\ "&x_t=#{timestamp}" # returns: String::'authenticated_uri' end
TODO: Attempt to exempt or unexempt a set of grades for a user. INPUT: a BulkGradeObjectExemptionUpdate. NOTE: If a grade has been changed since the provided ExemptionAccessDate,
a conflict will be added to the result set and that grade will not be exempted or unexempted.
RETURNS: a JSON array of BulkGradeObjectExemptionConflict blocks.
# File lib/d2l_sdk/grades.rb, line 489 def bulk_grade_exemption_update(org_unit_id, user_id, bulk_grade_exemption_update_block) # Grade.BulkGradeObjectExemptionUpdate JSON data block example: # {"ExemptedIds" => [0,1,2,3], # D2LIDs # "UnexemptedIds" => [0,1,2,3], # D2LIDs # "ExemptionAccessDate" => 'UTCDateTime'} # POST /d2l/api/le/(version)/(orgUnitId)/grades/exemptions/(userId) # RETURNS: a JSON array of BulkGradeObjectExemptionConflict blocks. end
NOTE: Not inherent d2l_api function. This is to check that the update_status
is actually a boolean and return a formatted UpdateStatus JSON block.
# File lib/d2l_sdk/config_variables.rb, line 184 def check_and_create_update_status_payload(update_status) if update_status != true && update_status != false raise ArgumentError, 'update_status is not a boolean' end payload = { 'Status' => update_status } # Tools.UpdateStatus JSON data block payload end
Check the validity of the Calendar.EventData that is passed as a payload
# File lib/d2l_sdk/calendar.rb, line 122 def check_calendar_event_data_validity(event_data) schema = { 'type' => 'object', 'required' => %w(Title Description StartDateTime EndDateTime StartDay EndDay GroupId RecurrenceInfo HasVisibilityRestrictions VisibilityRestrictions CalendarEventViewUrl), 'properties' => { 'Title' => { 'type' => 'integer' }, "Description" => { 'type' => 'integer' }, "StartDateTime" => { 'type' => %w(string nil) }, # UTCDateTime || nil "EndDateTime" => { 'type' => %w(string nil) }, # UTCDateTime || nil "StartDay" => { 'type' => %w(string nil) }, # LocalDateTime || nil "EndDay" => { 'type' => %w(string nil) }, # LocalDateTime || nil "GroupId" => { 'type' => %w(integer nil) }, # D2LID || nil "RecurrenceInfo" => { 'type' => 'object', 'required' => %w(RepeatType RepeatEvery RepeatOnInfo RepeatUntilDate), 'properties' => { "RepeatType" => { 'type' => 'integer' }, # number -- repeat type "RepeatEvery" => { 'type' => 'integer' }, # number "RepeatOnInfo" => # Calendar.RepeatOnInfo { 'type' => 'object', 'required' => %w(Monday Tuesday Wednesday Thursday Friday Saturday Sunday), 'properties' => { "Monday" => { 'type' => 'boolean' }, # boolean "Tuesday" => { 'type' => 'boolean' }, # boolean "Wednesday" => { 'type' => 'boolean' }, # boolean "Thursday" => { 'type' => 'boolean' }, # boolean "Friday" => { 'type' => 'boolean' }, # boolean "Saturday" => { 'type' => 'boolean' }, # boolean "Sunday" => { 'type' => 'boolean' }, # boolean } }, "RepeatUntilDate" => { 'type' => 'string' } # UTCDATETIME } }, # Calendar.RecurrenceInfo "HasVisibilityRestrictions" => { 'type' => 'boolean' }, "VisibilityRestrictions" => { 'type' => 'object', 'required' => %w(Type Range HiddenRangeUnitType StartDate EndDate), 'properties' => { "Type" => { 'type' => 'integer' }, # <number:VISIBILITY_T>, "Range" => { 'type' => %w(integer nil) }, # <number>|null, "HiddenRangeUnitType" => { 'type' => %w(integer nil) }, # <number:HIDDENUNIT_T>|null, "StartDate" => { 'type' => %w(string nil) }, # <string:UTCDateTime>|null, "EndDate" => { 'type' => %w(string nil) } # <string:UTCDateTime>|null, } }, # Calendar.VisibilityInfo "CalendarEventViewUrl" => { 'type' => 'string' } # url } } JSON::Validator.validate!(schema, event_data, validate_schema: true) end
# File lib/d2l_sdk/course_content.rb, line 120 def check_content_module_validity(content_module) schema = { 'type' => 'object', 'required' => %w(Title ShortTitle Type ModuleStartDate ModuleEndDate ModuleDueDate IsHidden IsLocked Description Duration), 'properties' => { 'Title' => { 'type' => 'string' }, 'ShortTitle' => { 'type' => 'string' }, 'Type' => { 'type' => 'integer' }, 'ModuleStartDate' => { 'type' => %w(string null) }, 'ModuleEndDate' => { 'type' => %w(string null) }, 'ModuleDueDate' => { 'type' => %w(string null) }, 'IsHidden' => { 'type' => %w(string null) }, 'IsLocked' => { 'type' => 'boolean' }, 'Description' => { 'type' => 'object', 'properties' => { "Content" => "string", "Type" => "string" # "Text|HTML" } }, # Added with LE v1.10 API 'Duration' => { 'type' => %w(integer null) } # Added in LE's unstable contract as of LE v10.6.8 } } JSON::Validator.validate!(schema, content_module, validate_schema: true) end
# File lib/d2l_sdk/course_content.rb, line 149 def check_content_topic_validity(content_topic) schema = { 'type' => 'object', 'required' => %w(Title ShortTitle Type TopicType Url StartDate EndDate DueDate IsHidden IsLocked OpenAsExternalResource Description MajoyUpdate MajorUpdateText ResetCompletionTracking), 'properties' => { 'Title' => { 'type' => 'string' }, 'ShortTitle' => { 'type' => 'string' }, 'Type' => { 'type' => 'integer' }, 'TopicType' => { 'type' => 'integer' }, 'StartDate' => { 'type' => %w(string null) }, 'EndDate' => { 'type' => %w(string null) }, 'DueDate' => { 'type' => %w(string null) }, 'IsHidden' => { 'type' => %w(string null) }, 'IsLocked' => { 'type' => 'boolean' }, 'OpenAsExternalResource' => { 'type' => %w(boolean null) }, # Added with LE v1.6 API 'Description' => { # Added with LE v1.10 API 'type' => 'object', 'properties' => { "Content" => "string", "Type" => "string" # "Text|HTML" } }, 'MajorUpdate' => { 'type' => %w(boolean null) }, # Added with LE v1.12 API 'MajorUpdateText' => { 'type' => 'string' }, # Added with LE v1.12 API 'ResetCompletionTracking' => { 'type' => %w(boolean null) } # Added with LE v1.12 API } } JSON::Validator.validate!(schema, content_topic, validate_schema: true) end
Checks whether the created course data conforms to the valence api for the course data JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/course.rb, line 50 def check_course_data_validity(course_data) schema = { 'type' => 'object', 'required' => %w(Name Code CourseTemplateId SemesterId StartDate EndDate LocaleId ForceLocale ShowAddressBook), 'properties' => { 'Name' => { 'type' => 'string' }, 'Code' => { 'type' => 'string' }, 'CourseTemplateId' => { 'type' => 'integer' }, 'SemesterId' => { 'type' => %w(integer null) }, 'StartDate' => { 'type' => %w(string null) }, 'EndDate' => { 'type' => %w(string null) }, 'LocaleId' => { 'type' => %w(integer null) }, 'ForceLocale' => { 'type' => 'boolean' }, 'ShowAddressBook' => { 'type' => 'boolean' } } } JSON::Validator.validate!(schema, course_data, validate_schema: true) end
Checks if the created course template data conforms to the valence api for the course template JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/course_template.rb, line 45 def check_course_template_data_validity(course_template_data) schema = { 'type' => 'object', 'required' => %w(Name Code Path ParentOrgUnitIds), 'properties' => { 'Name' => { 'type' => 'string' }, 'Code' => { 'type' => 'string' }, 'Path' => { 'type' => 'string' }, 'ParentOrgUnitIds' => { 'type' => 'array', 'items' => { 'type' => 'integer', 'minItems' => 1 } } } } JSON::Validator.validate!(schema, course_template_data, validate_schema: true) end
Checks if the updated course template data conforms to the valence api for the course template JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception. TODO: get rid of this, and make the template update only require 2 more args.
# File lib/d2l_sdk/course_template.rb, line 97 def check_course_template_updated_data_validity(course_template_data) schema = { 'type' => 'object', 'required' => %w(Name Code), 'properties' => { 'Name' => { 'type' => 'string' }, 'Code' => { 'type' => 'string' } } } JSON::Validator.validate!(schema, course_template_data, validate_schema: true) end
# File lib/d2l_sdk/course.rb, line 180 def check_create_copy_job_request_validity(create_copy_job_request) schema = { 'type' => 'object', 'required' => %w(SourceOrgUnitId Components CallbackUrl), 'properties' => { 'SourceOrgUnitId' => { 'type' => 'integer' }, 'Components' => { 'type' => %w(array null), 'items' => { 'type' => 'string' } }, 'CallbackUrl' => { 'type' => %w(string null) } } } JSON::Validator.validate!(schema, create_copy_job_request, validate_schema: true) end
Additional function added to check that the demographics data (create form) conforms to the JSON schema required by D2L's backend.
# File lib/d2l_sdk/demographics.rb, line 152 def check_create_demographics_field(demographics_data) schema = { 'type' => 'object', 'required' => %w(Name Description DataTypeId), 'properties' => { 'Name' => { 'type' => 'string' }, 'Description' => { 'type' => 'string' }, 'DataTypeId' => { 'type' => 'string' } } } JSON::Validator.validate!(schema, demographics_data, validate_schema: true) end
Check the validity of the CreateEnrollmentData that is passed as a payload
# File lib/d2l_sdk/enroll.rb, line 114 def check_create_enrollment_data_validity(enrollment_data) schema = { 'type' => 'object', 'required' => %w(OrgUnitId UserId RoleId), 'properties' => { 'OrgUnitId' => { 'type' => 'integer' }, 'UserId' => { 'type' => 'integer' }, 'RoleId' => { 'type' => 'integer' } } } JSON::Validator.validate!(schema, enrollment_data, validate_schema: true) end
# File lib/d2l_sdk/lti.rb, line 29 def check_create_lti_link_data_validity(create_lti_link_data) schema = { 'type' => 'object', 'required' => %w(Title Url Description Key PlainSecret IsVisible SignMessage SignWithTc SendTcInfo SendContextInfo SendUserId SendUserName SendUserEmail SendLinkTitle SendLinkDescription SendD2LUserName SendD2LOrgDefinedId SendD2LOrgRoleId UseToolProviderSecuritySettings CustomParameters), 'properties' => { 'Title' => { 'type' => 'string' }, 'Url' => { 'type' => 'string' }, 'Description' => { 'type' => 'string' }, 'Key' => { 'type' => 'string' }, 'PlainSecret' => { 'type' => 'string' }, 'IsVisible' => { 'type' => 'boolean' }, 'SignMessage' => { 'type' => 'boolean' }, 'SignWithTc' => { 'type' => 'boolean' }, 'SendTcInfo' => { 'type' => 'boolean' }, 'SendContextInfo' => { 'type' => 'boolean' }, 'SendUserId' => { 'type' => 'boolean' }, 'SendUserName' => { 'type' => 'boolean' }, 'SendUserEmail' => { 'type' => 'boolean' }, 'SendLinkTitle' => { 'type' => 'boolean' }, 'SendLinkDescription' => { 'type' => 'boolean' }, 'SendD2LUserName' => { 'type' => 'boolean' }, 'SendD2LOrgDefinedId' => { 'type' => 'boolean' }, 'SendD2LOrgRoleId' => { 'type' => 'boolean' }, 'UseToolProviderSecuritySettings' => { 'type' => 'boolean' }, 'CustomParameters' => { # define the CustomParameter array # 'description' => 'The array of CustomParameters 'type' => %w(array null), 'items' => { 'type' => 'object', "properties" => { "Name" => { 'type' => 'string' }, "Value" => { 'type' => 'string' } } } } } } JSON::Validator.validate!(schema, create_lti_link_data, validate_schema: true) end
Schema to check the CreateLtiProviderData JSON block validity.
# File lib/d2l_sdk/lti.rb, line 174 def check_create_lti_provider_data_validity(create_lti_provider_data) schema = { 'type' => 'object', 'required' => %w(LaunchPoint Secret UseDefaultTcInfo Key Name Description ContactEmail SendTcInfo SendContextInfo SendUserId SendUserName SendUserEmail SendLinkTitle SendLinkDescription SendD2LUserName SendD2LOrgDefinedId SendD2LOrgRoleId), 'properties' => { 'LaunchPoint' => { 'type' => 'string' }, 'Secret' => { 'type' => 'string' }, 'UseDefaultTcInfo' => { 'type' => 'string' }, 'Key' => { 'type' => 'string' }, 'Name' => { 'type' => 'string' }, 'Description' => { 'type' => 'string' }, 'ContactEmail' => { 'type' => 'string' }, 'IsVisible' => { 'type' => 'boolean' }, 'SendTcInfo' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendContextInfo' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendUserId' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendUserName' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendUserEmail' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendLinkTitle' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendLinkDescription' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendD2LUserName' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendD2LOrgDefinedId' => { 'type' => 'boolean' }, # LE's 1.12+ 'SendD2LOrgRoleId' => { 'type' => 'boolean' } # LE's 1.12+ } } JSON::Validator.validate!(schema, create_lti_provider_data, validate_schema: true) end
# File lib/d2l_sdk/org_unit.rb, line 371 def check_create_org_unit_type_data_validity(org_unit_type_data) schema = { 'type' => 'object', 'required' => %w(Code Name Description SortOrder), 'properties' => { 'Code' => { 'type' => 'string' }, 'Name' => { 'type' => 'string' }, 'Description' => { 'type' => 'string' }, 'SortOrder' => { 'type' => 'integer' } } } JSON::Validator.validate!(schema, org_unit_type_data, validate_schema: true) end
# File lib/d2l_sdk/discussions.rb, line 385 def check_create_post_data_validity(create_post_data) schema = { 'type' => 'object', 'required' => %w(ParentPostId Subject Message IsAnonymous), 'properties' => { 'ParentPostId' => { 'type' => %w(integer null) }, 'Subject' => { 'type' => "string" }, 'Message' => { 'type' => 'object', 'properties' => { "Content" => { 'type' => "string" }, "Type" => { 'type' => "string" } } }, 'IsAnonymous' => { 'type' => 'boolean' } } } JSON::Validator.validate!(schema, create_post_data, validate_schema: true) end
# File lib/d2l_sdk/discussions.rb, line 165 def check_create_topic_data_validity(create_topic_data) schema = { 'type' => 'object', 'required' => %w(Name Description AllowAnonymousPosts StartDate EndDate UnlockStartDate UnlockEndDate IsHidden IsLocked RequiresApproval ScoreOutOf IsAutoScore IncludeNonScoredValues ScoringType MustPostToParticipate RatingType DisplayInCalendar DisplayUnlockDatesInCalendar), 'properties' => { 'Name' => { 'type' => 'string' }, 'Description' => { 'type' => 'object', 'properties' => { "Content" => { 'type' => "string" }, "Type" => { 'type' => "string" } } }, 'AllowAnonymousPosts' => { 'type' => 'boolean' }, 'StartDate' => { 'type' => %w(string null) }, 'EndDate' => { 'type' => %w(string null) }, 'UnlockStartDate' => { 'type' => %w(string null) }, 'UnlockEndDate' => { 'type' => %w(string null) }, 'IsHidden' => { 'type' => 'boolean' }, 'IsLocked' => { 'type' => 'boolean' }, 'RequiresApproval' => { 'type' => 'boolean' }, #: <boolean>, 'ScoreOutOf' => { 'type' => %w(integer null) }, 'IsAutoScore' => { 'type' => 'boolean' }, # Added with LE API v1.11 'IncludeNonScoredValues' => { 'type' => 'boolean' }, 'ScoringType' => { 'type' => %w(string null) }, 'MustPostToParticipate' => { 'type' => 'boolean' }, #: <boolean>, 'RatingType' => { 'type' => %w(string null) }, 'DisplayInCalendar' => { 'type' => %w(boolean null) }, # Added with LE API v1.12 'DisplayUnlockDatesInCalendar' => { 'type' => %w(boolean null) } # Added with LE API v1.12 } } JSON::Validator.validate!(schema, create_topic_data, validate_schema: true) end
# File lib/d2l_sdk/demographics.rb, line 68 def check_demographics_entry_data_validity(demographics_entry_data) # A hash with one value, "EntryValues", which is an array of hashes that # include the keys "Name" and "Values", where "Name" is a string and "Values" # is an array of string. # { "key" => [ { "key" => "string", "key" => [] } ] } schema = { 'type' => 'object', 'required' => %w(EntryValues), 'properties' => { 'EntryValues' => # DemographicsEntryData { 'type' => 'array', 'items' => # Items = <composite:DemographicsEntry> { 'type' => 'object', 'minItems' => 1, 'required' => %w(Name Values), 'properties' => { 'Name' => { 'type' => 'string' }, 'Values' => { 'type' => 'array', 'items' => { 'type' => 'string', 'minItems' => 1 } } } } } } } JSON::Validator.validate!(schema, demographics_entry_data, validate_schema: true) end
# File lib/d2l_sdk/dropbox.rb, line 30 def check_dropbox_folder_update_data_validity(dropbox_folder_update_data) schema = { 'type' => 'object', 'required' => %w(CategoryId Name CustomInstructions Availability GroupTypeId DueDate DisplayInCalendar NotificationEmail), 'properties' => { 'CategoryId' => { 'type' => %w(integer null) }, 'Name' => { 'type' => 'string' }, 'CustomInstructions' => { 'type' => 'object', 'properties' => { 'Content' => { 'type' => 'string' }, 'Type' => { 'type' => 'string' } # either 'Text' or 'HTML' } }, 'Availability' => { 'type' => %w(object null), 'properties' => { 'StartDate' => { 'type' => 'string' }, 'EndDate' => { 'type' => 'string' } } }, 'GroupTypeId' => { 'type' => %w(integer null) }, 'DueDate' => { 'type' => %w(string null) }, 'DisplayInCalendar' => { 'type' => 'boolean' }, 'NotificationEmail' => { 'type' => %w(string null) } } } JSON::Validator.validate!(schema, dropbox_folder_update_data, validate_schema: true) end
# File lib/d2l_sdk/discussions.rb, line 29 def check_forum_data_validity(forum_data) schema = { 'type' => 'object', 'required' => %w(Name Description ShowDescriptionInTopics StartDate EndDate PostStartDate PostEndDate IsHidden IsLocked RequiresApproval MustPostToParticipate DisplayInCalendar DisplayPostDatesInCalendar), 'properties' => { 'Name' => { 'type' => 'string' }, 'Description' => { 'type' => 'object', 'properties' => { "Text" => { 'type' => "string" }, "Html" => { 'type' => %w(string null) } } }, 'ShowDescriptionInTopics' => { 'type' => %w(boolean null) }, 'StartDate' => { 'type' => %w(string null) }, 'EndDate' => { 'type' => %w(string null) }, 'PostStartDate' => { 'type' => %w(string null) }, 'PostEndDate' => { 'type' => %w(string null) }, 'IsHidden' => { 'type' => 'boolean' }, 'IsLocked' => { 'type' => 'boolean' }, 'RequiresApproval' => { 'type' => 'boolean' }, #: <boolean>, 'MustPostToParticipate' => { 'type' => %w(boolean null) }, 'DisplayInCalendar' => { 'type' => %w(boolean null) }, # Added with LE API v1.11 'DisplayPostDatesInCalendar' => { 'type' => %w(boolean null) } } } JSON::Validator.validate!(schema, forum_data, validate_schema: true) end
determine if a specific product component supports a particular API version
# File lib/d2l_sdk/requests.rb, line 440 def check_if_product_supports_api_version(product_code, version) path = "/d2l/api/#{product_code}/versions/#{version}" _get(path) end
# File lib/d2l_sdk/grades.rb, line 30 def check_numeric_grade_object { 'MaxPoints' => 0.0, # <number:decimal>, 'CanExceedMaxPoints' => true, # <boolean>, 'IsBonus' => true, # <boolean>, 'ExcludeFromFinalGradeCalculation' => true, # <boolean>, 'GradeSchemeId' => nil, # <number:D2LID>|null, 'Id' => 0, # <number:D2LID>, // not on input actions 'Name' => '', # <string>, 'ShortName' => '', # <string>, 'GradeType' => 0, # "Numeric", 'CategoryId' => nil, # <number:D2LID>|null, 'Description' => # { <composite:RichTextInput> } on input actions { 'Content' => '', 'Type' => 'Text|HTML' }, 'GradeSchemeUrl' => '', # <string:APIURL>, // not on input actions 'Weight' => 0.0, # <number:decimal>, // not on input actions 'ActivityId' => nil, # <string:D2LID>|null, // not on input actions 'AssociatedTool' => # { <composite:AssociatedTool> }|null { 'ToolId' => 0, # <string:D2LID> 'ToolItemId' => 0 # <string:D2LID> } } end
Checks whether the created org unit data conforms to the valence api for the org unit data JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/org_unit.rb, line 166 def check_org_unit_data_validity(org_unit_data) schema = { 'type' => 'object', 'required' => %w(Type Name Code Parents), 'properties' => { 'Type' => { 'type' => 'integer' }, 'Name' => { 'type' => 'string' }, 'Code' => { 'type' => 'string' }, 'Parents' => { 'type' => 'array', 'items' => { 'type' => 'integer', 'minItems' => 1 } } } } JSON::Validator.validate!(schema, org_unit_data, validate_schema: true) end
# File lib/d2l_sdk/config_variables.rb, line 235 def check_org_unit_information_validity(data_block) schema = { 'type' => 'object', 'required' => %w(ToolId DisplayName OrgUnitId Status CustomNavbarName), 'properties' => { 'ToolId' => { 'type' => 'string' }, 'DisplayName' => { 'type' => 'string' }, 'CallbackUrl' => { 'type' => 'integer' }, 'Status' => { 'type' => 'boolean' }, 'CustomNavbarName' => { 'type' => 'string' } } } JSON::Validator.validate!(schema, data_block, validate_schema: true) end
Checks whether the updated org unit data conforms to the valence api for the org unit data JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/org_unit.rb, line 226 def check_org_unit_updated_data_validity(org_unit_data) schema = { 'type' => 'object', 'required' => %w(Identifier Name Code Path Type), 'properties' => { 'Identifier' => { 'type' => 'string' }, 'Name' => { 'type' => 'string' }, 'Code' => { 'type' => 'string' }, 'Path' => { 'type' => 'string' }, 'Type' => { 'required' => %w(Id Code Name), 'properties' => { 'Id' => { 'type' => 'integer' }, 'Code' => { 'type' => 'string' }, 'Name' => { 'type' => 'string' } } } } } JSON::Validator.validate!(schema, org_unit_data, validate_schema: true) end
determine versions supported by the back-end Brightspace API requires: JSON SupportedVersionRequest data block
# File lib/d2l_sdk/requests.rb, line 463 def check_product_versions(supported_version_request) payload = [ { "ProductCode" => "9.9", "Version" => "9.9" } ].merge!(supported_version_request) # requires: JSON SupportedVersionRequest data block check_supported_version_request_validity(payload) path = "/d2l/api/versions/check" _post(path, payload) # returns: BulkSupportedVersionResponse JSON block end
Check the validity of the SectionData that is passed as a payload
# File lib/d2l_sdk/section.rb, line 36 def check_section_data_validity(section_data) schema = { 'type' => 'object', 'required' => %w(Name Code Description), 'properties' => { 'Name' => { 'type' => 'string' }, 'Code' => { 'type' => 'string' }, 'Description' => { 'type' => 'object', 'properties' => { 'Content' => 'string', 'Type' => 'string' } } } } JSON::Validator.validate!(schema, section_data, validate_schema: true) end
Check the validity of the SectionEnrollment that is passed as a payload
# File lib/d2l_sdk/section.rb, line 74 def check_section_enrollment_validity(section_enrollment) schema = { 'type' => 'object', 'required' => %w(UserId), 'properties' => { 'UserId' => { 'type' => 'integer' } } } JSON::Validator.validate!(schema, section_enrollment, validate_schema: true) end
Check the validity of the SectionPropertyData that is passed as a payload
# File lib/d2l_sdk/section.rb, line 96 def check_section_property_data_validity(section_property_data) schema = { 'type' => 'object', 'required' => %w(Name Code Description), 'properties' => { 'EnrollmentStyle' => { 'type' => 'integer' }, 'EnrollmentQuantity' => { 'type' => 'integer' }, 'AutoEnroll' => { 'type' => 'boolean' }, 'RandomizeEnrollments' => { 'type' => 'boolean' } } } JSON::Validator.validate!(schema, section_property_data, validate_schema: true) end
Checks if the created semester data conforms to the valence api for the semester JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/semester.rb, line 15 def check_semester_data_validity(semester_data) check_org_unit_data_validity(semester_data) end
Checks if the updated semester data conforms to the valence api for the semester JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/semester.rb, line 108 def check_semester_updated_data_validity(semester_data) check_org_unit_updated_data_validity(semester_data) end
# File lib/d2l_sdk/requests.rb, line 445 def check_supported_version_request_validity(supported_version_request) schema = { 'type' => 'array', 'items' => { 'type' => "object", "properties" => { "Productcode" => { 'type' => "string" }, "Version" => { 'type' => "string" } } } } JSON::Validator.validate!(schema, supported_version_request, validate_schema: true) end
Additional function added to check that the demographics data (update form) conforms to the JSON schema required by D2L's backend.
# File lib/d2l_sdk/demographics.rb, line 183 def check_update_demographics_field(demographics_data) schema = { 'type' => 'object', 'required' => %w(Name Description), 'properties' => { 'Name' => { 'type' => 'string' }, 'Description' => { 'type' => 'string' } } } JSON::Validator.validate!(schema, demographics_data, validate_schema: true) end
Checks whether the updated course data conforms to the valence api for the update data JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/course.rb, line 108 def check_updated_course_data_validity(course_data) schema = { 'type' => 'object', 'required' => %w(Name Code StartDate EndDate IsActive), 'properties' => { 'Name' => { 'type' => 'string' }, 'Code' => { 'type' => 'string' }, 'StartDate' => { 'type' => %w(string null) }, 'EndDate' => { 'type' => %w(string null) }, 'IsActive' => { 'type' => 'boolean' } } } JSON::Validator.validate!(schema, course_data, validate_schema: true) end
Checks whether the updated user data conforms to the valence api for the user data JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/user.rb, line 208 def check_updated_user_data_validity(user_data) schema = { 'type' => 'object', 'required' => %w(OrgDefinedId FirstName MiddleName LastName ExternalEmail UserName Activation), 'properties' => { 'OrgDefinedId' => { 'type' => %w(string null) }, 'FirstName' => { 'type' => 'string' }, 'MiddleName' => { 'type' => %w(string null) }, 'LastName' => { 'type' => 'string' }, 'ExternalEmail' => { 'type' => %w(string null) }, 'UserName' => { 'type' => 'string' }, 'Activation' => { 'required' => ['IsActive'], 'properties' => { 'IsActive' => { 'type' => 'boolean' } } } } } JSON::Validator.validate!(schema, user_data, validate_schema: true) end
Checks whether the created user data conforms to the valence api for the user data JSON object. If it does conform, then nothing happens and it simply returns true. If it does not conform, then the JSON validator raises an exception.
# File lib/d2l_sdk/user.rb, line 13 def check_user_data_validity(user_data) schema = { 'type' => 'object', 'required' => %w(OrgDefinedId FirstName MiddleName LastName ExternalEmail UserName RoleId IsActive SendCreationEmail), 'properties' => { 'OrgDefinedId' => { 'type' => 'string' }, 'FirstName' => { 'type' => 'string' }, 'MiddleName' => { 'type' => %w(string null) }, 'LastName' => { 'type' => 'string' }, 'ExternalEmail' => { 'type' => %w(string null) }, 'UserName' => { 'type' => 'string' }, 'RoleId' => { 'type' => 'integer' }, 'IsActive' => { 'type' => 'boolean' }, 'SendCreationEmail' => { 'type' => 'boolean' } } } JSON::Validator.validate!(schema, user_data, validate_schema: true) end
simple schema check to assure the course component is an actual course component returns: boolean
# File lib/d2l_sdk/course.rb, line 201 def course_component?(key) valid_components = %w(AttendanceRegisters Glossary News Checklists Grades QuestionLibrary Competencies GradesSettings Quizzes Content Groups ReleaseConditions CourseFiles Homepages Rubrics Discussions IntelligentAgents Schedule DisplaySettings Links SelfAssessments Dropbox LtiLink Surveys Faq LtiTP ToolNames Forms Navbars Widgets) valid_components.include?(key) # returns whether the key is actually a course component end
Creates an authenticated uniform resource identifier that works with Valence by calling URI.parse
using the path downcased, then creating a query string by calling _get_string
with the parsed_url and the http_method. These are used as the Variables and then returned as the finished uri.
Input that is required is:
* path: The path to the resource you are trying to accessing * http_method: The method utilized to access/modify the resource
returns: String::uri
# File lib/d2l_sdk/auth.rb, line 32 def create_authenticated_uri(path, http_method) parsed_url = URI.parse(path.downcase) uri_scheme = 'https' query_string = _get_string(parsed_url.path, http_method) uri = uri_scheme + '://' + $hostname + parsed_url.path + query_string uri << '&' + parsed_url.query if parsed_url.query uri # returns: String::uri end
TODO: Create a new course completion for an org unit. RETURNS: a CourseCompletion JSON block with the newly created course completion record.
# File lib/d2l_sdk/grades.rb, line 382 def create_course_completion(org_unit_id, course_completion_data) # CourseCompletionCreationData JSON data block example: # {"UserId" => 0, # "CompletedDate" => "UTCDateTime", # "ExpiryDate" => "UTCDateTime" || nil} # POST /d2l/api/le/(version)/(orgUnitId)/grades/courseCompletion/ end
Creates the course based upon a merged result of the argument course_data and a preformatted payload. This is then passed as a new payload in the _post
method in order to create the defined course. Required: “Name”, “Code” Creates the course offering
# File lib/d2l_sdk/course.rb, line 76 def create_course_data(course_data) # ForceLocale- course override the user’s locale preference # Path- root path to use for this course offering’s course content # if your back-end service has path enforcement set on for # new org units, leave this property as an empty string # Define a valid, empty payload and merge! with the user_data. Print it. # can be an issue if more than one course template associated with # a course and the last course template parent to a course cannot be deleted payload = { 'Name' => '', # String 'Code' => 'off_SEMESTERCODE_STARNUM', # String 'Path' => '', # String 'CourseTemplateId' => 99_989, # number: D2L_ID 'SemesterId' => nil, # number: D2L_ID | nil 'StartDate' => nil, # String: UTCDateTime | nil 'EndDate' => nil, # String: UTCDateTime | nil 'LocaleId' => nil, # number: D2L_ID | nil 'ForceLocale' => false, # bool 'ShowAddressBook' => false # bool }.merge!(course_data) check_course_data_validity(payload) # ap payload # requires: CreateCourseOffering JSON block path = "/d2l/api/lp/#{$lp_ver}/courses/" _post(path, payload) # puts '[+] Course creation completed successfully'.green end
REVIEW: Create a new course import job request. INPUT: simple file upload process – using “course package” as the uploaded file
# File lib/d2l_sdk/course.rb, line 272 def create_course_import_request(org_unit_id, file_path, callback_url = '') path = "/d2l/le/#{$le_ver}/import/#{org_unit_id}/imports/" path += "?callbackUrl=#{callback_url}" if callback_url != '' # TODO: (SCHEMA) Find out WTH a 'course package' entails as far as standards. _course_package_upload(path, file_path, "POST") # RETURNS: Parsed CreateImportJobResponse JSON block. end
This method creates a course template using a merged payload between a pre-formatted payload and the argument “course_template_data”. Upon this merge the path is defined for the POST http method that is then executed to create the course_template object. Required: “Name”, “Code” /d2l/api/lp/(version)/coursetemplates/ [POST]
# File lib/d2l_sdk/course_template.rb, line 68 def create_course_template(course_template_data) # TODO: make a bridge function that allows this to be done with 4 arguments, rather than # just a JSON. # Path- root path to use for this course offering’s course content # if your back-end service has path enforcement set on for # new org units, leave this property as an empty string # Define a valid, empty payload and merge! with the user_data. Print it. payload = { 'Name' => '', # String 'Code' => 'off_SEMESTERCODE_STARNUM', # String 'Path' => '', # String 'ParentOrgUnitIds' => [99_989], # number: D2L_ID }.merge!(course_template_data) check_course_template_data_validity(payload) puts 'Creating Course Template:' ap payload # Define a path referencing the courses path # requires: CreateCourseTemplate JSON block path = "/d2l/api/lp/#{$lp_ver}/coursetemplates/" _post(path, payload) puts '[+] Course template creation completed successfully'.green # returns: CourseTemplate JSON block containing the new data. end
Functions considered for basic added functionality to api, not sure if needed.
# File lib/d2l_sdk/org_unit.rb, line 184 def create_custom_org_unit(org_unit_data) # Requires the type to have the correct parent. This will work fine in this # sample, as the department (101) can have the parent Organiation (6606) payload = { 'Type' => 101, # Number:D2LID 'Name' => 'custom_ou_name', # String 'Code' => 'custom_ou_code', # String 'Parents' => [6606], # Number:D2LID }.merge!(org_unit_data) check_org_unit_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/" # Requires: OrgUnitCreateData JSON block _post(path, payload) # returns: OrgUnit JSON data block end
# File lib/d2l_sdk/org_unit.rb, line 385 def create_custom_outype(create_org_unit_type_data) payload = { 'Code' => '', 'Name' => '', 'Description' => '', 'SortOrder' => 0 }.merge!(create_org_unit_type_data) # validate schema check_create_org_unit_type_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/outypes/" _post(path, payload) # returns OrgUnitType JSON data block end
REVIEW: Create new demographic field Input: DemographicsField (Demographics.Demographicsfield) RETURNS: fetch form of a DemographicsField JSON block
# File lib/d2l_sdk/demographics.rb, line 168 def create_demographic_field(demographics_field) # POST /d2l/api/lp/(version)/demographics/fields/ path = "/d2l/api/lp/#{$lp_ver}/demographics/fields/" payload = { "Name" => "String", "Description" => "String", "DataTypeId" => "String:GUID" }.merge!(demographics_field) check_create_demographics_field(payload) _post(path, payload) # RETURNS: fetch form of a DemographicsField JSON block end
REVIEW: Create a new dropbox folder in an org unit.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 68 def create_dropbox_folder(org_unit_id, dropbox_folder_update_data) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/" payload = { "CategoryId" => nil, # or a number "Name" => "string", "CustomInstructions" => { "Content" => "string", "Text" => "Text|HTML" }, "Availability" => { "StartDate" => "string or nil", # or nil "EndDate" => "string or nil" # or nil }, "GroupTypeId" => nil, # or a number "DueDate" => nil, "DisplayInCalendar" => false, "NotificationEmail" => nil # or a string --- Added in LE v1.21 }.merge!(dropbox_folder_update_data) check_dropbox_folder_update_data_validity(payload) _post(path, payload) # RETURNS: DropboxFolder JSON block end
REVIEW: Create a new dropbox folder category for the provided org unit.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/categories/¶ ↑
INPUT: DropboxCategory JSON data block RETURNS: a single DropboxCategory block. NOTE: Few enough required values in the JSON data block,
so they can simply be passed as arguments and checked for conformity by themselves.
# File lib/d2l_sdk/dropbox.rb, line 280 def create_dropbox_folder_category(org_unit_id, dropbox_category_id, dropbox_category_name) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/categories/" # Check that the values conform to the JSON schema. if !dropbox_category_id.is_a? Numeric raise ArgumentError, "Argument 'dropbox_category_id' with value #{dropbox_category_id} is not an integer value." elsif !dropbox_category_name.is_a? String raise ArgumentError, "Argument 'dropbox_category_name' with value #{dropbox_category_name} is not a String value." end payload = { 'Id' => dropbox_category_id, 'Name' => dropbox_category_name } _post(path, payload) end
REVIEW: Create Schema checker; Check that this payload conforms to it. Create a new event. INPUT: Calendar.EventData RETURNS:a EventDataInfo data block for the newly created event.
# File lib/d2l_sdk/calendar.rb, line 189 def create_event(org_unit_id, event_data) # POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/" payload = { # Calendar.EventDataInfo "Title" => "", "Description" => "", "StartDateTime" => nil, # UTCDateTime || nil "EndDateTime" => nil, # UTCDateTime || nil "StartDay" => nil, # LocalDateTime || nil "EndDay" => nil, # LocalDateTime || nil "GroupId" => nil, # D2LID || nil "RecurrenceInfo" => # Calendar.RecurrenceInfo { "RepeatType" => 0, # number -- repeat type "RepeatEvery" => 0, # number "RepeatOnInfo" => # Calendar.RepeatOnInfo { "Monday" => false, # boolean "Tuesday" => false, # boolean "Wednesday" => false, # boolean "Thursday" => false, # boolean "Friday" => false, # boolean "Saturday" => false, # boolean "Sunday" => false, # boolean }, "RepeatUntilDate" => "" # UTCDATETIME }, "HasVisibilityRestrictions" => false, "VisibilityRestrictions" => # Calendar.VisibilityInfo { "Type" => 0, # <number:VISIBILITY_T>, "Range" => nil, # <number>|null, "HiddenRangeUnitType" => nil, # <number:HIDDENUNIT_T>|null, "StartDate" => nil, # <string:UTCDateTime>|null, "EndDate" => nil # <string:UTCDateTime>|null, }, "CalendarEventViewUrl" => "" # String:URL }.merge!(event_data) check_calendar_event_data_validity(payload) # NOTE: Test later _post(path, payload) end
Create an export job for the requested data set
# File lib/d2l_sdk/datahub.rb, line 68 def create_export_job(create_export_job_data) # init payload and merge with export job data payload = { 'DataSetId' => '', 'Filters' => [] # {"Name"=> "startDate", "Value" => UTCDATETIME STRING} }.merge!(create_export_job_data) validate_create_export_job_data(payload) # Requires: CreateExportJobData JSON parameter path = "/d2l/api/lp/#{$lp_ver}/dataExport/create" _post(path, payload) # returns ExportJobData JSON block end
REVIEW: Create a new topic for the provided discussion forum in an org unit.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/¶ ↑
# File lib/d2l_sdk/discussions.rb, line 208 def create_forum_topic(org_unit_id, forum_id, create_topic_data) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/" payload = { "Name" => "", # : <string>, "Description" => { "Text" => "", # <string:plaintext_version_of_text>, "Html" => nil # <string:HTML_formatted_version_of_text>|null }, # { <composite:RichTextInput> }, "AllowAnonymousPosts" => false, # <boolean>, "StartDate" => nil, # <string:UTCDateTime>|null, "EndDate" => nil, # : <string:UTCDateTime>|null, "IsHidden" => false, # : <boolean>, "UnlockStartDate" => nil, # : <string:UTCDateTime>|null, "UnlockEndDate" => nil, # : <string:UTCDateTime>|null, "RequiresApproval" => false, # : <boolean>, "ScoreOutOf" => nil, # : <number>|null, "IsAutoScore" => false, # : <boolean>, "IncludeNonScoredValues" => "", # : <boolean>, "ScoringType" => nil, # : <string:SCORING_T>|null, "IsLocked" => false, # : <boolean>, "MustPostToParticipate" => false, # : <boolean>, "RatingType" => nil, # : <string:RATING_T>|null, "DisplayInCalendar" => nil, # : <boolean>|null, // Added with LE API v1.12 "DisplayUnlockDatesInCalendar" => nil, # : <boolean>|null // Added with LE API v1.12 }.merge!(create_topic_data) check_create_topic_data_validity(payload) # REVIEW: Validity check of topic data _post(path, payload) # RETURNS: Topic JSON data block end
Create a new association between an ISBN and an org unit.
# File lib/d2l_sdk/course_content.rb, line 317 def create_isbn_org_unit_association(org_unit_id, isbn_association_data) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}content/isbn/" payload = { "OrgUnitId" => 0, "Isbn" => "" # "IsRequired" => false ## optional }.merge!(isbn_association_data) _post(query_string, payload) # Returns: a IsbnAssociation JSON data block specifying # the association between an org unit and an ISBN. end
REVIEW: Build a new quicklink around an existing LTI link.
> POST /d2l/api/le/(version)/lti/quicklink/(orgUnitId)/(ltiLinkId)¶ ↑
# File lib/d2l_sdk/lti.rb, line 112 def create_lti_quicklink(org_unit_id, lti_link_id) path = "/d2l/api/le/#{$le_ver}/lti/quicklink/#{org_unit_id}/#{lti_link_id}" _post(path, {}) end
# File lib/d2l_sdk/course.rb, line 213 def create_new_copy_job_request(org_unit_id, create_copy_job_request) payload = { 'SourceOrgUnitId' => 0, # int 'Components' => nil, # [Str,...] || nil 'CallbackUrl' => nil # str | nil }.merge!(create_copy_job_request) # Check that the payload conforms to the JSON Schema of CreateCopyJobRequest check_create_copy_job_request_validity(payload) # Check each one of the components to see if they are valid Component types payload["Components"].each do |component| # If one of the components is not valid, cancel the CopyJobRequest operation next if course_component?(key) puts "'#{component}' specified is not a valid Copy Job Request component" puts "Please retry with a valid course component such as 'Dropbox' or 'Grades'" break end path = "/d2l/api/le/#{$le_ver}/import/#{org_unit_id}/copy/" _post(path, payload) # Returns CreateCopyJobResponse JSON block end
TODO: –UNSTABLE – Create a new role copied from an existing role. INPUT: deep_copy_role_id = d2lID; role_copy_data = User.role_copy_data RETURN: a Role JSON data block representing the newly-created copy of the role.
# File lib/d2l_sdk/user.rb, line 396 def create_new_role_from_existing_role(deep_copy_role_id, role_copy_data) # POST /d2l/api/lp/(version)/roles/ end
TODO: Create a news item for an org unit. INPUT: multipart/mixed POST body
part 1: news item data JSON part 2: attachments
# File lib/d2l_sdk/news.rb, line 68 def create_news_item(org_unit_id, news_item_data, attachments = []) # POST /d2l/api/le/(version)/(orgUnitId)/news/ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/" json = { "Title" => "Placeholder_title", "Body" => { # Composite: RichText "Text" => "plaintext_text_here", "HTML" => nil # OR the HTML_Formatted_version_of_text }, "StartDate" => "UTCDateTime", "EndDate" => nil, # nil or UTCDateTime -- e.g. 2017-03-28T18:54:56.000Z "IsGlobal" => false, "IsPublished" => false, # sets it as a draft "ShowOnlyInCourseOfferings" => false }.merge!(news_item_data) files = attachments method = "POST" ap json ap _news_upload(path, json, files, method) # RETURNS a NewsItem JSON data block end
REVIEW: Create a new forum for an org unit.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/¶ ↑
# File lib/d2l_sdk/discussions.rb, line 64 def create_org_unit_discussion(org_unit_id, forum_data) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/" payload = { 'Name' => '', #: <string>, 'Description' => #: { <composite:RichText> }, { "Text" => "", # <string:plaintext_version_of_text>, "Html" => nil # <string:HTML_formatted_version_of_text>|null }, 'ShowDescriptionInTopics' => nil, # : <boolean>|null, // Added with LE API v1.14 'StartDate' => nil, #: <string:UTCDateTime>|null, 'EndDate' => nil, #: <string:UTCDateTime>|null, 'PostStartDate' => nil, #: <string:UTCDateTime>|null, 'PostEndDate' => nil, # <string:UTCDateTime>|null, 'AllowAnonymous' => false, # <boolean>, 'IsLocked' => false, #: <boolean>, 'IsHidden' => false, #: <boolean>, 'RequiresApproval' => '', #: <boolean>, 'MustPostToParticipate' => nil, #: <boolean>|null, 'DisplayInCalendar' => nil, #: <boolean>|null, // Added with LE API v1.11 'DisplayPostDatesInCalendar' => nil, #: <boolean>|null // Added with LE API v1.11 }.merge!(forum_data) # REVIEW: Validate payload check_forum_data_validity(payload) _post(path, payload) end
REVIEW: Create a new grade category for a provided org unit. Return. This action returns the newly created grade object category in a GradeObjectCategory JSON block, so that you can quickly gather its grade category ID.
# File lib/d2l_sdk/grades.rb, line 205 def create_org_unit_grade_category(org_unit_id, grade_category_data) # POST /d2l/api/le/(version)/(orgUnitId)/grades/ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/" payload = { 'Name' => '', # <string>, 'ShortName' => '', # <string>, 'CanExceedMax' => false, # <boolean>, 'ExcludeFromFinalGrade' => false, # <boolean>, 'StartDate' => nil, # <string:UTCDateTime>|null, 'EndDate' => nil, # <string:UTCDateTime>|null, 'Weight' => nil, # <number:decimal>|null, 'MaxPoints' => nil, # <number:decimal>|null, 'AutoPoints' => nil, # <boolean>|null, 'WeightDistributionType' => nil, # <number>|null, 'NumberOfHighestToDrop' => nil, # <number>|null, 'NumberOfLowestToDrop' => nil, # <number>|null }.merge!(grade_category_data) # TODO: Validity check of 'create_org_unit_grade_category'! _post(path, payload) # Return. This action returns the newly created grade object category in a # GradeObjectCategory JSON block, so that you can quickly gather its grade # category ID. end
TODO: Create validity functions for grade objects within this. Create a new grade object for a particular org unit. Return: This action returns a GradeObject JSON block for the grade object that the service just created, so you can quickly retrieve the grade object ID
# File lib/d2l_sdk/grades.rb, line 62 def create_org_unit_grade_object(org_unit_id, grade_object, type) # POST /d2l/api/le/(version)/(orgUnitId)/grades/ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/" payload = {} # NOTE: must be grade object of type numeric, passfail, selectbox, or text # NOTE: the name must be unique! if type == 'Numeric' || type == 'numeric' payload = { 'MaxPoints' => 0.0, # <number:decimal>, 'CanExceedMaxPoints' => true, # <boolean>, 'IsBonus' => true, # <boolean>, 'ExcludeFromFinalGradeCalculation' => true, # <boolean>, 'GradeSchemeId' => nil, # <number:D2LID>|null, 'Name' => '', # <string>, 'ShortName' => '', # <string>, 'GradeType' => 'Numeric', # 'CategoryId' => nil, # <number:D2LID>|null, 'Description' => # { <composite:RichTextInput> } on input actions { 'Content' => '', 'Type' => 'Text|HTML' }, 'AssociatedTool' => # { <composite:AssociatedTool> }|null { 'ToolId' => 0, # <string:D2LID> 'ToolItemId' => 0 # <string:D2LID> } }.merge!(grade_object) # TODO: check numeric grade object validity elsif type == 'PassFail' || type == 'passfail' payload = { 'MaxPoints' => 0.0, # <number:decimal>, 'IsBonus' => true, # <boolean>, 'ExcludeFromFinalGradeCalculation' => true, # <boolean>, 'GradeSchemeId' => nil, # <number:D2LID>|null 'Name' => '', # <string>, 'ShortName' => '', # <string>, 'GradeType' => 'PassFail', # 'CategoryId' => nil, # <number:D2LID>|null, 'Description' => # { <composite:RichTextInput> } on input actions { 'Content' => '', 'Type' => 'Text|HTML' }, 'AssociatedTool' => # { <composite:AssociatedTool> }|null { 'ToolId' => 0, # <string:D2LID> 'ToolItemId' => 0 # <string:D2LID> } }.merge!(grade_object) # TODO: check PassFail grade object validity elsif type == 'SelectBox' || type == 'selectbox' payload = { 'MaxPoints' => 0.0, # <number:decimal>, 'IsBonus' => true, # <boolean>, 'ExcludeFromFinalGradeCalculation' => true, # <boolean>, 'GradeSchemeId' => nil, # nil/null on input 'Name' => '', # <string>, 'ShortName' => '', # <string>, 'GradeType' => 'SelectBox', # 'CategoryId' => nil, # <number:D2LID>|null, 'Description' => # { <composite:RichTextInput> } on input actions { 'Content' => '', 'Type' => 'Text|HTML' }, 'AssociatedTool' => # { <composite:AssociatedTool> }|null { 'ToolId' => 0, # <string:D2LID> 'ToolItemId' => 0 # <string:D2LID> } }.merge!(grade_object) # TODO: check SelectBox grade object validity elsif type == 'Text' || type == 'text' payload = { 'Name' => '', # <string>, 'ShortName' => '', # <string>, 'GradeType' => 'Text', 'CategoryId' => nil, # <number:D2LID>|null, 'Description' => # { <composite:RichTextInput> } on input actions { 'Content' => '', 'Type' => 'Text|HTML' }, 'AssociatedTool' => # { <composite:AssociatedTool> }|null { 'ToolId' => 0, # <string:D2LID> 'ToolItemId' => 0 # <string:D2LID> } }.merge!(grade_object) # TODO: check Text grade object validity else raise ArgumentError, 'Grade Object Type not a valid type' end _post(path, payload) # Return: This action returns a GradeObject JSON block for the grade object # that the service just created, so you can quickly retrieve the grade object # ID end
Create a new group for an org unit.
# File lib/d2l_sdk/group.rb, line 145 def create_org_unit_group(org_unit_id, group_category_id, group_data) payload = { "Name" => "string", "Code" => "string", "Description" => {} }.merge!(group_data) # Requires: JSON block of GroupData path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}/groups/" _post(path, payload) # returns a GroupData JSON block, in the Fetch form, of the new group end
See +validate_create_group_category_data+ for details on schema formal requirements of values
Create a new group category for an org unit.
# File lib/d2l_sdk/group.rb, line 101 def create_org_unit_group_category(org_unit_id, group_category_data) payload = { 'Name' => '', # String 'Description' => {}, # RichTextInput 'EnrollmentStyle' => 0, # number : group_enroll 'EnrollmentQuantity' => nil, # number | null 'AutoEnroll' => false, # bool 'RandomizeEnrollments' => false, # bool 'NumberOfGroups' => nil, # number | nil 'MaxUsersPerGroup' => nil, # number | nil 'AllocateAfterExpiry' => false, # bool 'SelfEnrollmentExpiryDate' => nil, # string: UTCDateTime | nil 'GroupPrefix' => nil, # String | nil }.merge!(group_category_data) # Requires: JSON block of GroupCategoryData path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/" _post(path, payload) # returns a GroupCategoryData JSON block, in the Fetch form, of the new categ. end
Create a new section in a particular org unit.
# File lib/d2l_sdk/section.rb, line 58 def create_org_unit_section(org_unit_id, section_data) payload = { 'Name' => '', # String 'Code' => '', # String 'Description' => {}, # RichTextInput -- e.g. {'Content'=>'x', 'Type'=>'y'} }.merge!(section_data) # Check the validity of the SectionData that is passed as a payload check_section_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/" # JSON param: SectionData _post(path, payload) # returns the SectionData JSON block, in its Fetch form, for the # org unit's new section. end
Uses a min and max to create a range. returns: range obj
# File lib/d2l_sdk/user.rb, line 107 def create_range(min, max) (min..max) # returns: range obj end
Create a new root module for an org unit. INPUT: ContentObjectData (of type Module) – New root module property data. Returns JSON array of ContentObject data blocks of type Module
# File lib/d2l_sdk/course_content.rb, line 185 def create_root_module(org_unit_id, content_module) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/root/" payload = { "Title" => "", "ShortTitle" => "", "Type" => 0, "ModuleStartDate" => nil, # <string:UTCDateTime>|null "ModuleEndDate" => nil, # <string:UTCDateTime>|null "ModuleDueDate" => nil, # <string:UTCDateTime>|null "IsHidden" => false, "IsLocked" => false, "Description" => nil, # { <composite:RichTextInput> }|null --Added with LE v1.10 API "Duration" => nil # <number>|null --Added in LE's +unstable+ contract as of LE v10.6.8 }.merge!(content_module) check_content_module_validity(payload) _post(query_string, payload) end
creates a properly formatted section code, based on WIU's standard section code. RETURNS: formatted section code
# File lib/d2l_sdk/section.rb, line 169 def create_section_code(star_num, course_date) "sec_#{course_date}_#{star_num}" end
Creates a semester based upon a merged result from merging a preformatted payload and the inputed semester data. This is then created server-side via executing a POST http method using a predefined path and the new payload.
# File lib/d2l_sdk/semester.rb, line 22 def create_semester_data(semester_data) # Define a valid, empty payload and merge! with the semester_data. Print it. payload = { 'Type' => 5, # Number:D2LID 'Name' => 'Winter 2013 Semester', # String 'Code' => '201701', # String #YearNUM where NUM{sp:01,su:06,fl:08} 'Parents' => [6606], # ARR of Number:D2LID }.merge!(semester_data) # ap payload check_semester_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/" _post(path, payload) puts '[+] Semester creation completed successfully'.green end
This is simply a helper function that can assist in preformatting a path that conforms to the required 'Path' for updating semester data.
returns: preformatted semester 'Path' string
# File lib/d2l_sdk/semester.rb, line 100 def create_semester_formatted_path(org_id, code) "/content/enforced/#{org_id}-#{code}/" end
REVIEW: Create a new post in a discussion forum topic.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/¶ ↑
NOTE: No file attachments? Send it normally :) NOTE: File attachments? Send using Multipart/Mixed body conforming to RFC2388 RETURNS: Post JSON data block
# File lib/d2l_sdk/discussions.rb, line 413 def create_topic_post(org_unit_id, forum_id, topic_id, create_post_data, files = []) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/" payload = { "ParentPostId" => nil, # integer or nil "Subject" => "", "Message" => { "Content" => "", "Type" => "Text|Html" }, "IsAnonymous" => false }.merge!(create_post_data) check_create_post_data_validity(payload) if files == [] # can do a simple POST request. _post(path, payload) else # Have to do multipart/mixed body custom POST request. _upload_post_data(path, payload, files, "POST") end end
Creates the user using user_data as an argument. A Hash is merged with the user_data. The data types for each Hash key is specified below. For the ExternalEmail, there must be either nil for the value or a WELL FORMED email address. The username must be unique, meaning no other user has that name. All of the rest can remain the same, assuming roleId 110 exists in your system.
# File lib/d2l_sdk/user.rb, line 40 def create_user_data(user_data) # Define a valid, empty payload and merge! with the user_data. Print it. payload = { 'OrgDefinedId' => '', # String 'FirstName' => 'TestUser', # String 'MiddleName' => 'Test', # String 'LastName' => 'Test', # String 'ExternalEmail' => nil, # String (nil or well-formed email addr) 'UserName' => 'test12345a', # String 'RoleId' => 110, # number 'IsActive' => false, # bool 'SendCreationEmail' => false, # bool }.merge!(user_data) # requires: UserData JSON block # Define a path referencing the course data using the course_id check_user_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/users/" _post(path, payload) puts '[+] User creation completed successfully'.green # returns a UserData JSON block for the newly created user end
Create a new enrollment for a user.
# File lib/d2l_sdk/enroll.rb, line 128 def create_user_enrollment(course_enrollment_data) payload = { 'OrgUnitId' => '', # String 'UserId' => '', # String 'RoleId' => '', # String }.merge!(course_enrollment_data) # ap payload # requires: CreateEnrollmentData JSON block path = "/d2l/api/lp/#{$lp_ver}/enrollments/" _post(path, payload) puts '[+] User successfully enrolled'.green # Returns: EnrollmentData JSON block for the newly enrolled user. end
As a more streamlined approach to deleting many course templates conforming to a particular naming style, this function performs deletions based on a string. Using the name argument, get_course_template_by_name
is called in order to retrieve all matching templates. They are then deleted by referencing each of their Identifiers as arguments for delete_course_template
.
# File lib/d2l_sdk/course_template.rb, line 183 def delete_all_course_templates_with_name(name) puts "[!] Deleting all course templates with the name: #{name}" get_course_template_by_name(name).each do |course_template| puts '[!] Deleting the following course:'.red ap course_template delete_course_template(course_template['Identifier']) end end
Deletes a course based, referencing it via its org_unit_id This reference is created through a formatted path appended with the id. Then, a delete http method is executed using this path, deleting the course.
# File lib/d2l_sdk/course.rb, line 12 def delete_course_by_id(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/courses/#{org_unit_id}" # setup user path # ap path _delete(path) puts '[+] Course data deleted successfully'.green end
REVIEW: Delete a course completion. RETURNS: nil
# File lib/d2l_sdk/grades.rb, line 338 def delete_course_completion(org_unit_id, completion_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/courseCompletion/#{completion_id}" _delete(path) end
Simply, a course template can be deleted by refencing it using its Identifier as an argument for this method. The argument is then used to refernce the obj by a path and then the path is passed in for a delete http method. /d2l/api/lp/(version)/coursetemplates/(orgUnitId) [DELETE]
# File lib/d2l_sdk/course_template.rb, line 11 def delete_course_template(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/coursetemplates/#{org_unit_id}" _delete(path) puts '[+] Course template data deleted successfully'.green end
TODO: (HOMEBREW) Delete course templates by using regular expressions to filter them.
# File lib/d2l_sdk/course_template.rb, line 193 def delete_course_templates_by_regex(regex); end
REVIEW: DELETE /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Rating/MyRating
> Delete the current user context’s rating for a particular post from a discussion forum topic.¶ ↑
# File lib/d2l_sdk/discussions.rb, line 297 def delete_current_user_context_post_rating path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Rating/MyRating" _delete(path) # NOTE: Doing so is actually an update, setting the current user's rating # of a post to null end
REVIEW: Remove the pin from the provided org unit.
# File lib/d2l_sdk/enroll.rb, line 147 def delete_current_user_org_unit_pin(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/enrollments/myenrollments/#{org_unit_id}/pin" _delete(path) # RETURNS: nil end
REVIEW: Delete a single demographic field, provided it has no associated entries.
# File lib/d2l_sdk/demographics.rb, line 130 def delete_demographics_field(field_id) path = "/d2l/api/lp/#{$lp_ver}/demographics/fields/#{field_id}" _delete(path) end
Delete a particular group from an org unit.
# File lib/d2l_sdk/group.rb, line 14 def delete_group(org_unit_id, group_category_id, group_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}/groups/#{group_id}" _delete(path) end
Delete a particular group category from an org unit.
# File lib/d2l_sdk/group.rb, line 8 def delete_group_category(org_unit_id, group_category_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}" _delete(path) end
Remove the association between an ISBN and org unit.
# File lib/d2l_sdk/course_content.rb, line 274 def delete_isbn_association(org_unit_id, isbn) # DELETE query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/isbn/#{isbn}" _delete(query_string) end
Delete a specific module from an org unit.
# File lib/d2l_sdk/course_content.rb, line 7 def delete_module(org_unit_id, module_id) # DELETE query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/modules/#{module_id}" _delete(query_string) end
REVIEW: Delete a particular news item from an org unit.
# File lib/d2l_sdk/news.rb, line 8 def delete_news_item(org_unit_id, news_item_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}" _delete(path) end
REVIEW: Delete an attachment from an org unit’s news item.
# File lib/d2l_sdk/news.rb, line 14 def delete_news_item_attachment(org_unit_id, news_item_id, file_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/attachments/#{file_id}" _delete(path) end
Calendar ######
REVIEW: Remove a calendar event from a particular org unit. Returns: ?
# File lib/d2l_sdk/calendar.rb, line 9 def delete_org_unit_calendar_event(org_unit_id, event_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}" _delete(path) end
REVIEW: Delete a particular discussion forum from an org unit.
> DELETE /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}¶ ↑
# File lib/d2l_sdk/discussions.rb, line 10 def delete_org_unit_discussion(org_unit_id, forum_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}" _delete(path) end
REVIEW: Delete a specific grade category for a provided org unit.
# File lib/d2l_sdk/grades.rb, line 180 def delete_org_unit_grade_category(org_unit_id, category_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/categories/#{category_id}" _delete(path) end
REVIEW: Delete a specific grade object for a particular org unit. Return: nil
# File lib/d2l_sdk/grades.rb, line 9 def delete_org_unit_grade_object(org_unit_id, grade_object_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}" _delete(path) end
Delete a particular org unit type
# File lib/d2l_sdk/org_unit.rb, line 338 def delete_outype(outype_id) path = "/d2l/api/lp/#{$lp_ver}/outypes/#{outype_id}" _delete(path) end
deletes a particular org unit. This is done via referencing the org unit by its id and performing a delete method.
# File lib/d2l_sdk/org_unit.rb, line 300 def delete_recycled_org_unit(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}" _delete(path) end
This deletes the relationship between a parent ou and a child ou by performing a delete method from the parent's children and specifying this child through its id.
# File lib/d2l_sdk/org_unit.rb, line 23 def delete_relationship_of_child_with_parent(parent_ou_id, child_ou_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{parent_ou_id}/children/#{child_ou_id}" _delete(path) end
This deletes the relationship between a child ou and a parent ou by performing a delete method from the child's parents and specifying this parent through its id.
# File lib/d2l_sdk/org_unit.rb, line 31 def delete_relationship_of_parent_with_child(parent_ou_id, child_ou_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{child_ou_id}/parents/#{parent_ou_id}" _delete(path) end
Delete a section from a provided org unit.
# File lib/d2l_sdk/section.rb, line 9 def delete_section(org_unit_id, section_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/#{section_id}" _delete(path) end
REVIEW: Delete the subscription for messages of a particular type,
delivered by a particular carrier.
# File lib/d2l_sdk/user.rb, line 313 def delete_subscription(carrier_id, message_type_id) path = "/d2l/api/lp/#{$lp_ver}/notifications/instant/carriers/#{carrier_id}/subscriptions/#{message_type_id}" _delete(path) end
Delete a specific topic from an org unit.
# File lib/d2l_sdk/course_content.rb, line 13 def delete_topic(org_unit_id, topic_id) # DELETE query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/topics/#{topic_id}" _delete(query_string) end
REVIEW: Delete a group restriction for a discussion forum topic.
> DELETE /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/groupRestrictions/¶ ↑
# File lib/d2l_sdk/discussions.rb, line 139 def delete_topic_group_restriction(org_unit_id, forum_id, topic_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/groupRestrictions/" _delete(path) end
REVIEW: Delete a particular post from a discussion forum topic.
> DELETE /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}¶ ↑
# File lib/d2l_sdk/discussions.rb, line 290 def delete_topic_post(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}" _delete(path) end
Deletes the user's data (identified by user_id). By forming a path that is correctly referencing this user's data, a delete http method is executed and effectively deleted the user that is referenced.
# File lib/d2l_sdk/user.rb, line 264 def delete_user_data(user_id) # Define a path referencing the user data using the user_id path = "/d2l/api/lp/#{$lp_ver}/users/#{user_id}" # setup user path _delete(path) puts '[+] User data deleted successfully'.green end
Delete one or more of a particular user's associated demographics entries. if no entries specified, it DELETES ALL. entry_ids are added as additional variables entry_ids is a CSV formatted string
# File lib/d2l_sdk/demographics.rb, line 12 def delete_user_demographics(user_id, entry_ids = '') path = "/d2l/api/lp/#{$lp_ver}/demographics/users/#{user_id}" path += "?entryIds=" + entry_ids if entry_ids != '' _delete(path) end
Delete a user’s enrollment in a provided org unit.
# File lib/d2l_sdk/enroll.rb, line 9 def delete_user_enrollment(user_id, org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/users/#{user_id}/orgUnits/#{org_unit_id}" _delete(path) # Returns: EnrollmentData JSON block showing the enrollment status # just before this action deleted the enrollment of the user end
Delete a user’s enrollment in a provided org unit.
# File lib/d2l_sdk/enroll.rb, line 17 def delete_user_enrollment_alternative(user_id, org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/enrollments/orgUnits/#{org_unit_id}/users/#{user_id}" _delete(path) # Returns: EnrollmentData JSON block showing the enrollment status # just before this action deleted the enrollment of the user end
REVIEW: Clear a particular user’s password.
# File lib/d2l_sdk/user.rb, line 343 def delete_user_password(user_id) path = "/d2l/api/lp/#{$lp_ver}/users/#{user_id}/password" _delete(path) end
based upon the specific code that is returned from the http method, this displays the response, in the case that it is an error within the request or the server. This is simply informative and assists in describing the lacking response information from the valence api. In the case of a Bad Request, it is likely that it cannot be further specified without looking back at the d2l_api documentation or looking at the documentation on the docs.valence.desire2learn.com website.
# File lib/d2l_sdk/requests.rb, line 383 def display_response_code(code) case code when 400 then puts '[!] 400: Bad Request' when 401 then puts '[!] 401: Unauthorized' when 403 then puts '[!] Error Code Forbidden 403: accessing the page or resource '\ 'you were trying to reach is absolutely forbidden for some reason.' when 404 then puts '[!] 404: Not Found' when 405 then puts '[!] 405: Method Not Allowed' when 406 then puts 'Unacceptable Type'\ 'Unable to provide content type matching the client\'s Accept header.' when 412 then puts '[!] 412: Precondition failed\n'\ 'Unsupported or invalid parameters, or missing required parameters.' when 415 then puts '[!] 415: Unsupported Media Type'\ 'A PUT or POST payload cannot be accepted.' when 423 then puts '[!] 423' when 500 then puts '[!] 500: General Service Error\n'\ 'Empty response body. The service has encountered an unexpected'\ 'state and cannot continue to handle your action request.' when 504 then puts '[!] 504: Service Error' end end
Checks whether a username already exists returns: true if the the user exists already
# File lib/d2l_sdk/user.rb, line 114 def does_user_exist(username) !get_user_by_username(username.to_s).nil? end
Downloads the identified job and stores the zip within the working directory Extracts zipped job contents in “export_jobs” folder of working directory
# File lib/d2l_sdk/datahub.rb, line 101 def download_job_csv(export_job_id) attempt = 0 puts "Attempting to download job: #{export_job_id}" while attempt < 20 # Attempts 20 times (~3 mins) unless job failed. status = get_job_status_code(export_job_id) case status when 2 # If the status was okay, break loop + return download of job zip_fname = 'export1.zip' puts "Job complete, writing to zip: #{zip_fname}" File.write(zip_fname, _get_raw("/d2l/api/lp/#{$lp_ver}/dataExport/download/#{export_job_id}")) unzip(zip_fname, /sec_|off_/) # unzip file; filter if Enrollments + CSV puts "file downloaded and unzipped" break when /3|4/ puts "Job download failed due to status: #{status}" if status == 3 puts "Status description: Error - An error occurred when processing the export" else puts "Status description: Deleted - File was deleted from file system" end break else # else, print out the status and wait 10 seconds before next attempt puts "The job is not currently ready to download\n Status Code: #{status}" if status.zero? puts "Status description: Queued - Export job has been received for processing." else puts "Status description: Processing - Currently in process of exporting data set." end puts "Sleeping for 10 seconds.." sleep 10 attempt += 1 end # returns: ZIP file containing a CSV file of data from the export job end end
Enroll a user in a group
# File lib/d2l_sdk/group.rb, line 184 def enroll_user_in_group(org_unit_id, group_category_id, group_id, user_id) payload = { "UserId" => user_id } # Requires: JSON block of GroupEnrollment path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}/groups/#{group_id}/enrollments/" validate_group_enrollment_data(payload) _post(path, payload) end
Enroll a user in a section for a particular org unit.
# File lib/d2l_sdk/section.rb, line 86 def enroll_user_in_org_unit_section(org_unit_id, section_id, section_data) payload = { 'UserId' => 9999 }.merge!(section_data) # Number : D2LID # Check the validity of the SectionEnrollment that is passed as a payload check_section_enrollment_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/#{section_id}/enrollments/" # JSON param: SectionEnrollment _post(path, payload) end
REVIEW: Exempt a user from a grade. RETURNS: a User JSON block.
# File lib/d2l_sdk/grades.rb, line 457 def exempt_user_from_grade(org_unit_id, grade_object_id, user_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}/exemptions/#{user_id}" _post(path, {}) # RETURNS: a User JSON block. end
Filter all enrollments and withdrawals in a csv file, excluding data that is not properly formatted (based on ou code), not a current or future course, or nil for their ou code.
# File lib/d2l_sdk/datahub.rb, line 177 def filter_formatted_enrollments(csv_fname, instr_fname, regex_filter = //) # Create csv with 'filtered' pre-appended to '.csv' substring filtered_csv = csv_fname.gsub(/\.csv/, "filtered.csv") File.open(filtered_csv, 'w') do |file| # set row num to 0 to keep track of headers row_num = 0 current = get_current_courses(instr_fname) # for each row puts "Filtering #{csv_fname}" CSV.foreach(csv_fname) do |row| # the line is initialized as an empty string line = "" # Skip the row if not a valid # or skip in-filter OU_code, # or skip if the header # or skip if not within the INSTR SET of current/future courses if row[3].nil? || row_num > 0 && (row[3] !~ regex_filter) || (!current.include? row[3][4..-1]) row_num += 1 next end # for values not filtered from above ^ # for all of these values row[0..-1].each do |value| # If it a UTC date time value, then parse as Time. if value =~ /\b[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]*Z\b/ # if the value is UTC formatted line << "\"#{Time.parse(value)}\"" elsif value == row[-1] # if its the last value in the row line << "\"#{value}\"" # then dont put a comma at the end. else # not the last value in the row, line << "\"#{value}\"," # throw a comma after the value end end file.write(line + "\n") # append this line to the csv row_num += 1 # increment the row number end end end
uses the path, http_method, and timestamp arguments to create a properly formatted signature. Then, this is returned.
returns: String::signature
# File lib/d2l_sdk/auth.rb, line 62 def format_signature(path, http_method, timestamp) http_method.upcase + '&' + path.encode('UTF-8') + '&' + timestamp.to_s # returns: String::signature end
This retrieves a paged result of all the childless org units within the organization. As this is paged, it only retrieves the first 100 from the beginning of the request. If bookmark is not specified, then it only retrieves the first 100 results.
return: JSON array of childless org units.
# File lib/d2l_sdk/org_unit.rb, line 65 def get_all_childless_org_units(org_unit_type = '', org_unit_code = '', org_unit_name = '', bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/orgstructure/childless/?" params = [] params << "orgUnitType=#{org_unit_type}" if org_unit_type != '' params << "orgUnitCode=#{org_unit_code}" if org_unit_code != '' params << "orgUnitName=#{org_unit_name}" if org_unit_name != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # ONLY RETRIEVES FIRST 100 end
Retrieve the definitions for all the configuration variables the user has access to view.
# File lib/d2l_sdk/config_variables.rb, line 14 def get_all_config_var_definitions(search = '', bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/configVariables/definitions/?" params = [] params << "search=#{search}" if search != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # returns paged result set of Definition JSON data blocks end
Retrieve all the org unit override values for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 52 def get_all_config_var_org_unit_override_values(variable_id, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/orgUnits/" path += "?bookmark=#{bookmark}" if bookmark != '' _get(path) # returns paged result set of OrgUnitValue data blocks end
Retrieve all the role override values for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 75 def get_all_config_var_org_unit_role_override_values(variable_id, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/roles/" path += "?bookmark=#{bookmark}" if bookmark != '' _get(path) # returns paged result set with RoleValue JSON data blocks end
Instead of explicitly retrieving a single course template, this method uses the routing table to retrieve all of the organizations descendants with the outTypeId of 2. What this means is that it is literally retrieving any and all course templates that have an ancestor of the organization…which should be all of them.
returns: JSON array of course template data objects
# File lib/d2l_sdk/course_template.rb, line 146 def get_all_course_templates path = "/d2l/api/lp/#{$lp_ver}/orgstructure/6606/descendants/?ouTypeId=2" _get(path) # return: JSON array of course template data objects end
# File lib/d2l_sdk/course.rb, line 302 def get_all_courses path = "/d2l/api/lp/#{$lp_ver}/orgstructure/6606/descendants/?ouTypeId=3" _get(path) end
Lists all available data sets
# File lib/d2l_sdk/datahub.rb, line 25 def get_all_data_sets _get("/d2l/api/lp/#{$lp_ver}/dataExport/list") # returns a JSON array of DataSetData blocks end
Retrieve list of all demographics fields
# File lib/d2l_sdk/demographics.rb, line 136 def get_all_demographic_fields(bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/demographics/fields/" path += bookmark.to_s if bookmark != '' _get(path) # returns paged result set of DemographicsField JSON blocks end
Retrieve the list of all demographics data types uses DataTypeId's as a paging control value
# File lib/d2l_sdk/demographics.rb, line 217 def get_all_demographic_types(bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/demographics/dataTypes/" path += bookmark.to_s if bookmark != '' _get(path) # returns paged result set of DemographicsDataType JSON blocks end
Retrieve all demographics entries for all users with specified filters
# File lib/d2l_sdk/demographics.rb, line 44 def get_all_demographics(field_ids = '', role_ids = '', user_ids = '', search = '', bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/demographics/users/?" params = [] params << "fieldIds=#{field_ids}" if field_ids != '' params << "roleIds=#{role_ids}" if role_ids != '' params << "userIds=#{user_ids}" if user_ids != '' params << "search=#{search}" if search != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # returns paged result set of DemographicsUserEntryData JSON blocks end
Retrieve all the demographics entries for all users enrolled in an OU optional params: fieldIds, roleIds, and userIds are CSV formatted Strings
search and bookmark are Strings
# File lib/d2l_sdk/demographics.rb, line 21 def get_all_demographics_by_org_unit(org_unit_id, field_ids = '', role_ids = '', user_ids = '', search = '', bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/demographics/orgUnits/#{org_unit_id}/users/?" params = [] params << "fieldIds=#{field_ids}" if field_ids != '' params << "roleIds=#{role_ids}" if role_ids != '' params << "userIds=#{user_ids}" if user_ids != '' params << "search=#{search}" if search != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # returns paged result set of DemographicsUserEntryData JSON blocks end
Retrieve all the demographics entries for a specific user within an OU
# File lib/d2l_sdk/demographics.rb, line 36 def get_all_demographics_by_org_unit_by_user(org_unit_id, user_id, field_ids = '') path = "/d2l/api/lp/#{$lp_ver}/demographics/orgUnits/#{org_unit_id}/users/(#{user_id})" path += "?fieldIds=#{field_ids}" if field_ids != '' _get(path) # returns DemographicsUserEntryData JSON block end
Retrieve the list of all enrollments for the current user Optional params: –orgUnitTypeId: CSV of D2LIDs –bookmark: String –sortBy: string –isActive: bool –startDateTime: UTCDateTime –endDateTime: UTCDateTime –canAccess: bool
# File lib/d2l_sdk/enroll.rb, line 40 def get_all_enrollments_of_current_user(bookmark = '', sort_by = '', is_active = nil, start_date_time = '', end_date_time = '', can_access = nil) path = "/d2l/api/lp/#{$lp_ver}/enrollments/myenrollments/?" params = [] params << "bookmark=#{bookmark}" if bookmark != '' params << "sortBy=#{sort_by}" if sort_by != '' params << "isActive=#{is_active}" unless is_active.nil? params << "startDateTime=#{start_date_time}" if start_date_time != '' params << "endDateTime=#{end_date_time}" if end_date_time != '' params << "canAccess=#{can_access}" unless can_access.nil? path = path + params.join('&') _get(path) # Returns: paged result set containing the resulting MyOrgUnitInfo data blocks end
Retrieve a list of all enrollments for the provided user. Optional params: –orgUnitTypeId (CSV of D2LIDs) –roleId: D2LIDs –bookmark: string
# File lib/d2l_sdk/enroll.rb, line 93 def get_all_enrollments_of_user(user_id, org_unit_type_id = 0, role_id = 0, bookmark = '') path = "/d2l/api/lp/1.3/enrollments/users/#{user_id}/orgUnits/?" params = [] params << "orgUnitTypeId=#{org_unit_type_id}" if org_unit_type_id != 0 params << "roleId=#{role_id}" if role_id != 0 params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # Returns: paged result set w/ the resulting UserOrgUnit data blocks end
List all available export jobs that you have previously submitted
# File lib/d2l_sdk/datahub.rb, line 82 def get_all_export_jobs(bookmark = '') # optional parameter page -- integer path = "/d2l/api/lp/#{$lp_ver}/dataExport/jobs" path += "?bookmark=#{bookmark}" if bookmark != '' _get(path) # returns: JSON array of paged ExportJobData blocks, sorted by SubmitDate end
REVIEW: Retrieve each user’s grade value for a particular grade object. INPUT: sort = string, page_size = number, is_graded = boolean, search_text = string RETURN: This action returns an ObjectListPage JSON block containing a list of user grade values for your provided grade object.
# File lib/d2l_sdk/grades.rb, line 294 def get_all_grade_object_grades(org_unit_id, grade_object_id, sort = '', page_size = 0, is_graded = nil, search_text = '') path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}/values/?" params = [] params << "sort=#{sort}" if sort != '' params << "pageSize=#{page_size}" if page_size != 0 params << "isGraded=#{is_graded}" unless is_graded.nil? params << "searchText=#{search_text}" if search_text != '' path = path + params.join('&') _get(path) # RETURN: This action returns an ObjectListPage JSON block containing a list # of user grade values for your provided grade object. end
Retrieve a list of all the groups in a specific group category for an OrgUnit
# File lib/d2l_sdk/group.rb, line 38 def get_all_group_category_groups(org_unit_id, group_category_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}/groups/" _get(path) end
NOTE: UNSTABLE optional parameter 'bookmark' for querying with a paging offset Retrieve the collection of all known locales.
# File lib/d2l_sdk/user.rb, line 675 def get_all_locales(bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/locales/" path += "?bookmark=#{bookmark}" if bookmark != '' _get(path) # returns paged result set containing Locale data blocks end
retrieve all current log messages with MANY parameters possible for filtering. REQUIRED PARAMS: date_range_start; date_range_end logLevel is CSV formatted, so simple delimit each value with a comma
# File lib/d2l_sdk/logging.rb, line 11 def get_all_logs(date_range_start, date_range_end, search = '', log_level = '', logger_assembly = '', user_id = 0, message_group_id = 0, include_traces = nil, org_unit_id = 0, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/logging/?" params = [] params << "dateRangeStart=#{date_range_start}" params << "dateRangeEnd=#{date_range_end}" params << "search=#{search}" if search != '' params << "logLevel=#{log_level}" if log_level != '' params << "loggerAssembly=#{logger_assembly}" if logger_assembly != '' params << "userId=#{user_id}" if user_id != 0 params << "messageGroupId=#{message_group_id}" if message_group_id != 0 params << "includeTraces=#{include_traces}" unless include_traces.nil? params << "orgUnitId=#{org_unit_id}" if org_unit_id != 0 params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') ap path _get(path) # returns paged result set of Message data blocks end
retrieve all current log arranged in message groups REQUIRED PARAMS: date_range_start; date_range_end logLevel is CSV formatted, so simple delimit each value with a comma
# File lib/d2l_sdk/logging.rb, line 35 def get_all_message_group_logs(date_range_start, date_range_end, search = '', log_level = '', logger_assembly = '', user_id = 0, message_group_id = 0, org_unit_id = 0, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/logging/grouped/?" params = [] params << "dateRangeStart=#{date_range_start}" params << "dateRangeEnd=#{date_range_end}" params << "search=#{search}" if search != '' params << "logLevel=#{log_level}" if log_level != '' params << "loggerAssembly=#{logger_assembly}" if logger_assembly != '' params << "userId=#{user_id}" if user_id != 0 params << "messageGroupId=#{message_group_id}" if message_group_id != 0 params << "orgUnitId=#{org_unit_id}" if org_unit_id != 0 params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # returns paged result set of MessageGroupSummary data blocks end
Retrieve all the carrier channels for delivering notification messages. RETURNS: a JSON array of CarrierOutput data blocks.
# File lib/d2l_sdk/user.rb, line 320 def get_all_notification_carrier_channels path = "/d2l/api/lp/#{$lp_ver}/notifications/instant/carriers/" _get(path) end
Retrieve a list of all the group categories for the provided org unit.
# File lib/d2l_sdk/group.rb, line 26 def get_all_org_unit_group_categories(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/" _get(path) end
Retrieves the org units that are a particular id. This is done by obtaining all of the children of the organization and then filtering by this id.
return: JSON array of all org units of an outype.
# File lib/d2l_sdk/org_unit.rb, line 426 def get_all_org_units_by_type_id(outype_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/6606/children/?ouTypeId=#{outype_id}" _get(path) end
Retrieves a paged result of all orphaned org units within the organization. This is a paged result, so only for the first 100 from the beginning bookmark are retrieved. Simply put, if the bookmark is not defined, it only gets the first 100 orphans.
return: JSON array of orphaned org units.
# File lib/d2l_sdk/org_unit.rb, line 84 def get_all_orphans(org_unit_type = '', org_unit_code = '', org_unit_name = '', bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/orgstructure/orphans/" path += "?orgUnitType=#{org_unit_type}" if org_unit_type != '' path += "?orgUnitCode=#{org_unit_code}" if org_unit_code != '' path += "?orgUnitName=#{org_unit_name}" if org_unit_name != '' path += "?bookmark=#{bookmark}" if bookmark != '' _get(path) end
retrieves all outypes that are known and visible. This is returned as a JSON array of orgunittype data blocks.
# File lib/d2l_sdk/org_unit.rb, line 345 def get_all_outypes path = "/d2l/api/lp/#{$lp_ver}/outypes/" _get(path) end
Versions #####
# File lib/d2l_sdk/requests.rb, line 408 def get_all_products_supported_versions path = "/d2l/api/versions/" _get(path) # returns array of product codes in a JSON block end
This retrieves all semesters via getting all children from the main organization and filtering them by the default data type of semesters.
Returns: Array of all semester JSON formatted data
# File lib/d2l_sdk/semester.rb, line 41 def get_all_semesters path = "/d2l/api/lp/#{$lp_ver}/orgstructure/6606/children/?ouTypeId=5" _get(path) end
Retrieve all the current subscriptions for notification messages. RETURNS: a JSON array of SubscriptionOutput data blocks.
# File lib/d2l_sdk/user.rb, line 327 def get_all_subscriptions_by_carrier(carrier_id) path = "/d2l/api/lp/#{$lp_ver}/notifications/instant/carriers/#{carrier_id}/subscriptions/" _get(path) end
retrieve list of all known user roles
# File lib/d2l_sdk/user.rb, line 370 def get_all_user_roles path = "/d2l/api/lp/#{$lp_ver}/roles/" _get(path) # RETURNS: a JSON array of Role data blocks end
REVIEW: Retrieve information for an auditee. RETURNS: a AuditedUser JSON block.
# File lib/d2l_sdk/enroll.rb, line 184 def get_auditee(auditee_id) path = "/d2l/api/le/#{$le_ver}/auditing/auditees/#{auditee_id}" _get(path) # RETURNS: a AuditedUser JSON block. end
REVIEW: Retrieve information for an auditor. RETURNS: a Auditor JSON block.
# File lib/d2l_sdk/enroll.rb, line 192 def get_auditor(auditor_id) path = "/d2l/api/le/#{$le_ver}/auditing/auditors/#{auditor_id}" _get(path) # RETURNS: a Auditor JSON block end
REVIEW: Retrieve the list of users an auditor is auditing. RETURNS: a JSON array of Auditee blocks.
# File lib/d2l_sdk/enroll.rb, line 200 def get_auditor_auditees(auditor_id) path = "/d2l/api/le/#{$le_ver}/auditing/auditors/#{auditor_id}/auditees/" _get(path) # RETURNS: a JSON array of Auditee blocks. end
uses the key and signature as arguments to create a hash using OpenSSL::HMAC.digest
with an additional argument denoting the hashing algorithm as 'sha256'. The hash is then encoded properly and all “=” are deleted to officially create a base64 hash string.
returns: String::base64_hash_string
# File lib/d2l_sdk/auth.rb, line 73 def get_base64_hash_string(key, signature) hash = OpenSSL::HMAC.digest('sha256', key, signature) Base64.urlsafe_encode64(hash).delete('=') # returns: String::base64_hash_string end
Retrieve a list of topics that have been bookmarked.
# File lib/d2l_sdk/course_content.rb, line 511 def get_bookmarked_topics(org_unit_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/bookmarks" _get(query_string) # Returns: a JSON array of Topic ToC entries. end
REVIEW: Retrieve a count of calling user’s calendar events, within a number of org units RETURNS: An ObjectListPage JSON block containing a list of EventCountInfo JSON data blocks.
# File lib/d2l_sdk/calendar.rb, line 63 def get_calendar_event_count(org_unit_ids_csv, start_date_time, end_date_time, association = nil, event_type = nil) path = "/d2l/api/le/#{$le_ver}/calendar/events/myEvents/itemCounts/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_csv}" params << "startDateTime=#{start_date_time}" params << "endDateTime=#{end_date_time}" params << "association=#{association}" unless association.nil? params << "eventType=#{event_type}" unless event_type.nil? path = path + params.join('&') _get(path) end
REVIEW: Retrieve quantity of the calling user’s scheduled items still due for a particular org unit. GET /d2l/api/le/(version)/#{org_unit_id}/content/myItems/due/itemCount
# File lib/d2l_sdk/course_content.rb, line 469 def get_calling_user_due_items_count(org_unit_id, completion = nil, start_date_time = '', end_date_time = '') # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/myItems/due/itemCount?" params = [] params << "completion=#{completion}" unless completion.nil? params << "startDateTime=#{start_date_time}" unless start_date_time == '' params << "endDateTime=#{end_date_time}" unless end_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
REVIEW: Retrieve the quantity of the calling user scheduled items for provided org unit. GET /d2l/api/le/(version)/#{org_unit_id}/content/myItems/itemCount
# File lib/d2l_sdk/course_content.rb, line 455 def get_calling_user_overdue_items_count(org_unit_id, completion = nil, start_date_time = '', end_date_time = '') # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/myItems/itemCount?" params = [] params << "completion=#{completion}" unless completion.nil? params << "startDateTime=#{start_date_time}" unless start_date_time == '' params << "endDateTime=#{end_date_time}" unless end_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
REVIEW: Retrieve the calling user scheduled items.
# File lib/d2l_sdk/course_content.rb, line 334 def get_calling_user_scheduled_items(org_unit_ids_CSV, completion = nil, start_date_time = '', end_date_time = '') # GET query_string = "/d2l/api/le/#{$le_ver}/content/myItems/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_CSV}" params << "completion=#{completion}" unless completion.nil? params << "startDateTime=#{start_date_time}" unless start_date_time == '' params << "endDateTime=#{end_date_time}" unless end_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
Retrieve the current org value for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 45 def get_config_var_current_org_value(variable_id) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/org" _get(path) # returns OrgValue JSON data block end
Retrieve the definitions for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 25 def get_config_var_definitions(variable_id) path = "/d2l/api/lp/#{$lp_ver}/configVariables/(#{variable_id}/definition" _get(path) # returns Definition JSON data block end
NOTE: UNSTABLE!!! Retrieve the effective value for a configuration variable within an org unit.
# File lib/d2l_sdk/config_variables.rb, line 68 def get_config_var_org_unit_effective_value(variable_id, org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/effectiveValues/orgUnits/#{org_unit_id}" _get(path) # returns OrgUnitValue JSON block end
Retrieve an org unit override value for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 60 def get_config_var_org_unit_override_value(variable_id, org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/orgUnits/#{org_unit_id}" _get(path) # returns OrgUnitValue JSON block end
NOTE: UNSTABLE!!! REVIEW: Retrieve the resolution strategy for an org unit configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 138 def get_config_var_resolver(variable_id) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/resolver" _get(path) end
# File lib/d2l_sdk/config_variables.rb, line 82 def get_config_var_role_override_value(variable_id, role_id) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/roles/#{role_id}" _get(path) end
# File lib/d2l_sdk/config_variables.rb, line 87 def get_config_var_system_value(variable_id) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/system" _get(path) end
Retrieve the value summary for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 38 def get_config_var_values(variable_id) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values" _get(path) # returns Values JSON data block end
COPYING COURSES:######
# File lib/d2l_sdk/course.rb, line 168 def get_copy_job_request_status(org_unit_id, job_token) path = "/d2l/api/le/#{$le_ver}/import/#{org_unit_id}/copy/#{job_token}" _get(path) # returns GetCopyJobResponse JSON block # GetImportJobResponse: # {"JobToken" => <string:COPYJOBSTATUS_T>, # "TargetOrgUnitID" => <number:D2LID>, # "Status" => <string:IMPORTJOBTSTATUS_T>} # States of getImport: UPLOADING, PROCESSING, PROCESSED, IMPORTING, # IMPORTFAILED, COMPLETED end
TODO: UNSTABLE!!!! Retrieve the list of logs for course copy jobs. Query Params: –OPTIONAL– -bookmark : string -page_size : number -source_org_unit_id : number -destination_org_unit_id : number -start_date : UTCDateTime -end_date : UTCDateTime RETURNS: An object list page containing the resulting CopyCourseLogMessage data blocks
# File lib/d2l_sdk/course.rb, line 245 def get_copy_jobs_logs(bookmark = '', page_size = 0, source_org_unit_id = 0, destination_org_unit_id = 0, start_date = '', end_date = '') # GET /d2l/api/le/(version)/ccb/logs end
Performs a get request to retrieve a particular course using the org_unit_id of this particular course. If the course does not exist, as specified by the org_unit_id, the response is typically a 404 error.
returns: JSON object of the course
# File lib/d2l_sdk/course.rb, line 31 def get_course_by_id(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/courses/#{org_unit_id}" _get(path) # returns: JSON object of the course end
# File lib/d2l_sdk/course.rb, line 37 def get_course_image(org_unit_id, width = 0, height = 0) path = "/d2l/api/lp/#{$lp_ver}/courses/#{org_unit_id}/image" if width > 0 && height > 0 path += "?width=#{width}" path += "&height=#{height}" end _get(path) end
# File lib/d2l_sdk/course.rb, line 263 def get_course_import_job_request_logs(org_unit_id, job_token, bookmark = '') path = "/d2l/api/le/#{$le_ver}/import/#{org_unit_id}/imports/#{job_token}/logs" path += "?bookmark=#{bookmark}" if bookmark != '' _get(path) # returns PAGED RESULT of ImportCourseLog JSON blocks following bookmark param end
IMPORTING COURSES:####
# File lib/d2l_sdk/course.rb, line 254 def get_course_import_job_request_status(org_unit_id, job_token) path = "/d2l/api/le/#{$le_ver}/import/#{org_unit_id}/imports/#{job_token}" _get(path) # returns GetImportJobResponse JSON block # example: # {"JobToken" => <string:COPYJOBSTATUS_T>} # States: PENDING, PROCESSING, COMPLETE, FAILED, CANCELLED end
Retrieve the overview for a course offering.
# File lib/d2l_sdk/course_content.rb, line 254 def get_course_overview(org_unit_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/overview" ap query_string _get(query_string) # Returns: a Overview JSON data block containing # the course offering overview’s details. end
Retrieve the overview file attachment for a course offering.
# File lib/d2l_sdk/course_content.rb, line 263 def get_course_overview_file_attachment(org_unit_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/overview/attachment" _get(query_string) # Returns: a file stream containing the course offering’s overview attachment. end
Retrieves a course template based upon an explicitly defined course template org_unit_id or Identifier. This is done by using the identifier as a component of the path, and then performing a GET http method that is then returned.
returns: JSON course template data /d2l/api/lp/(version)/coursetemplates/(orgUnitId) [GET]
# File lib/d2l_sdk/course_template.rb, line 23 def get_course_template(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/coursetemplates/#{org_unit_id}" _get(path) # return: JSON course template data end
This method retrieves all course templates that have a specific string, as specified by org_unit_name, within their names. This is done by first defining that none are found yet and initializing an empty array. Then, by searching through all course templates for ones that do have a particular string within their name, the matches are pushed into the previously empty array of matches. This array is subsequently returned; if none were found, a message is returned
returns: JSON array of matching course template data objects
# File lib/d2l_sdk/course_template.rb, line 160 def get_course_template_by_name(org_unit_name) course_template_not_found = true course_template_results = [] puts "[+] Searching for templates using search string: \'#{org_unit_name}\'".yellow results = get_all_course_templates results.each do |x| if x['Name'].downcase.include? org_unit_name.downcase course_template_not_found = false course_template_results.push(x) end end if course_template_not_found puts '[-] No templates could be found based upon the search string.'.yellow end course_template_results # return: JSON array of matching course template data objects end
Moreso a helper method, but this really just returns the schema of the course templates. This is predefined in the routing table, and retrieved via a GET http method.
returns: JSON of course templates schema /d2l/api/lp/(version)/coursetemplates/schema [GET]
# File lib/d2l_sdk/course_template.rb, line 35 def get_course_templates_schema path = "/d2l/api/lp/#{$lp_ver}/coursetemplates/schema" _get(path) # This action returns a JSON array of SchemaElement blocks. end
much slower means of getting courses if less than 100 courses
# File lib/d2l_sdk/course.rb, line 308 def get_courses_by_code(org_unit_code) all_courses = get_all_courses courses = [] all_courses.each do |course| courses.push(course) if course["Code"].downcase.include? org_unit_code.to_s.downcase end courses end
Retrieves all courses that have a particular string (org_unit_name) within their names. This is done by first defining that none are found yet and then searching through all course for ones that do have a particular string within their name, the matches are pushed into the previously empty array of matches. This array is subsequently returned; if none were found, a message is returned
returns: JSON array of matching course data objects
# File lib/d2l_sdk/course.rb, line 324 def get_courses_by_name(org_unit_name) get_courses_by_property_by_string('Name', org_unit_name) end
Retrieves all courses that have the specified prop match a regular expression. This is done by iterating through all courses and returning an array of all that match a regular expression.
returns: array of JSON course objects (with property that matches regex)
# File lib/d2l_sdk/course.rb, line 355 def get_courses_by_property_by_regex(property, regex) puts "[+] Searching for courses using regex: #{regex}".yellow + + " -- And property: #{property}" courses_results = [] results = get_all_courses results.each do |x| courses_results.push(x) unless (x[property] =~ regex).nil? end courses_results # returns array of all matching courses in JSON format. end
Retrieves all matching courses that are found using a property and a search string. First, it is considered that the class is not found. Then, all courses are retrieved and stored as a JSON array in the varaible results
. After this each of the results
is iterated, downcased, and checked for their matching of the particular search string. If there is a match, they are pushed to an array called courses_results
. This is returned at the end of this op.
returns: array of JSON course objects (that match the search string/property)
# File lib/d2l_sdk/course.rb, line 336 def get_courses_by_property_by_string(property, search_string) puts "[+] Searching for courses using search string: #{search_string}".yellow + + " -- And property: #{property}" courses_results = [] results = get_all_courses results.each do |x| if x[property].downcase.include? search_string.downcase courses_results.push(x) end end courses_results # returns array of all matching courses in JSON format. end
Get all 'current' courses, assuming all instr courses are current and add their sec/off course_term_star_num codes to a set. return: set of current classes formatted as “#{course_term}_#{star_number}”
# File lib/d2l_sdk/datahub.rb, line 163 def get_current_courses(csv_fname) puts "Retrieving current courses from #{csv_fname}" instr_courses = Set.new CSV.foreach(csv_fname, headers: true) do |row| star_number = row[0] course_term = row[10] instr_courses.add("#{course_term}_#{star_number}") end instr_courses end
REVIEW: Retrieve a list of org units for which the current user context has an
assessment role on their dropbox folders (can see submissions and provide feedback).
> GET /d2l/api/le/#{$le_ver}/dropbox/orgUnits/feedback/¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 119 def get_current_user_assessable_folders(type = nil) path = "/d2l/api/le/#{$le_ver}/dropbox/orgUnits/feedback/" path += "?type=#{type}" if type.zero? || type == 1 _get(path) end
REVIEW: Retrieve all the calendar events for the calling user,
within the provided org unit context.
RETURNS: This action returns a JSON array of EventDataInfo data blocks.
# File lib/d2l_sdk/calendar.rb, line 24 def get_current_user_calendar_events_by_org_unit(org_unit_id, associated_events_only = nil) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/" path += "?associatedEventsOnly=#{associated_events_only}" unless associated_events_only.nil? _get(path) end
REVIEW: Retrieve the calling user’s calendar events, within a
number of org units (see query parameter)
RETURNS: An ObjectListPage JSON block containing a list of EventDataInfo JSON data blocks.
# File lib/d2l_sdk/calendar.rb, line 33 def get_current_user_calendar_events_by_org_units(org_unit_ids_csv, start_date_time, end_date_time, association = nil, event_type = nil) path = "/d2l/api/le/#{$le_ver}/calendar/events/myEvents/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_csv}" params << "startDateTime=#{start_date_time}" params << "endDateTime=#{end_date_time}" params << "association=#{association}" unless association.nil? params << "eventType=#{event_type}" unless event_type.nil? path = path + params.join('&') _get(path) end
REVIEW: Retrieve the calling user completed scheduled items. GET /d2l/api/le/(version)/content/myItems/completions/
# File lib/d2l_sdk/course_content.rb, line 395 def get_current_user_completed_scheduled_items(org_unit_ids_CSV, completion_from_date_time = '', completed_to_date_time = '') query_string = "/d2l/api/le/#{$le_ver}/content/myItems/completions/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_CSV}" params << "completedFromDateTime=#{completion_from_date_time}" unless completion_from_date_time == '' params << "completedToDateTime=#{completed_to_date_time}" unless completed_to_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
REVIEW: Retrieve the calling user’s completed scheduled items that have a due date. GET /d2l/api/le/(version)/content/myItems/completions/due/
# File lib/d2l_sdk/course_content.rb, line 410 def get_current_user_completed_scheduled_items_with_due_date(org_unit_ids_CSV, completion_from_date_time = '', completed_to_date_time = '') query_string = "/d2l/api/le/#{$le_ver}/content/myItems/completions/due/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_CSV}" params << "completedFromDateTime=#{completion_from_date_time}" unless completion_from_date_time == '' params << "completedToDateTime=#{completed_to_date_time}" unless completed_to_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
REVIEW: Retrieve the calling user’s events for a particular org unit. RETURNS: An ObjectListPage JSON block containing a list of EventDataInfo JSON data blocks.
# File lib/d2l_sdk/calendar.rb, line 49 def get_current_user_events_by_org_unit(start_date_time, end_date_time, association = nil, event_type = nil) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/myEvents/?" params = [] params << "startDateTime=#{start_date_time}" params << "endDateTime=#{end_date_time}" params << "association=#{association}" unless association.nil? params << "eventType=#{event_type}" unless event_type.nil? path = path + params.join('&') _get(path) end
REVIEW: Fetch the feed for the current user context. if since not specified, only includes most 'recent' feed items if since specified but until is not, all items since 'since' are fetched if since and until are specified, all items between these two dates are fetched if since > until, an empty feed list is returned purpose: fetch the feed for the current user context
# File lib/d2l_sdk/news.rb, line 25 def get_current_user_feed(since = "", until_ = "") path = "/d2l/api/lp/#{$lp_ver}/feed/" # if since is specified, then until can be. Until is not required though. if since != "" path += "?since=#{since}" path += "&until=#{until_}" if until_ != "" end _get(path) end
REVIEW: Retrieve the final grade value for the current user context. Return: This action returns a GradeValue JSON block containing the final calculated grade value for the current user context.
# File lib/d2l_sdk/grades.rb, line 257 def get_current_user_final_grade(org_unit_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/final/values/myGradeValue" _get(path) # Return: This action returns a GradeValue JSON block containing the final # calculated grade value for the current user context. end
TODO: Retrieve a list of final grade values for the current user context across a number of org units. -INPUT: Input. When calling this action, you must provide a list of org unit IDs that amount to some or all of the calling user’s active enrollments. -RETURN: This action returns an ObjectListPage JSON block containing a list of final calculated grade values sorted by the OrgUnitIds that match the provided query parameter filters.
# File lib/d2l_sdk/grades.rb, line 271 def get_current_user_final_grades(org_unit_ids_csv) # RETURN: This action returns an ObjectListPage JSON block containing a list # of final calculated grade values sorted by the OrgUnitIds that match the # provided query parameter filters. end
REVIEW: Retrieve the current user context’s rating data for a particular post in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Rating/MyRating¶ ↑
# File lib/d2l_sdk/discussions.rb, line 355 def get_current_user_forum_topic_post_rating_data(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Rating/MyRating" _get(path) # RETURNS: UserRatingData JSON data block end
REVIEW: Retrieve the current user’s vote data for a particular post in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Votes/MyVote¶ ↑
# File lib/d2l_sdk/discussions.rb, line 379 def get_current_user_forum_topic_post_vote_data(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Votes/MyVote" _get(path) # RETURNS: UserVoteData JSON data block end
REVIEW: Retrieve the current user’s locale account settings.
# File lib/d2l_sdk/user.rb, line 619 def get_current_user_locale_settings path = "/d2l/api/lp/#{$lp_ver}/accountSettings/mySettings/locale/" _get(path) # RETURNS: a Locale JSON block end
REVIEW: Retrieve all the grade objects for the current user context assigned in a particular org unit.
# File lib/d2l_sdk/grades.rb, line 319 def get_current_user_org_unit_grades(org_unit_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/values/myGradeValues/" _get(path) # RETURN: This action returns a JSON array of GradeValue blocks. end
REVIEW: Retrieve the calling user’s scheduled items still due for a particular org unit. GET /d2l/api/le/(version)/#{org_unit_id}/content/myItems/due/
# File lib/d2l_sdk/course_content.rb, line 440 def get_current_user_org_unit_scheduled_items(org_unit_id, completion = nil, start_date_time = '', end_date_time = '') # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/myItems/due/?" params = [] params << "completion=#{completion}" unless completion.nil? params << "startDateTime=#{start_date_time}" unless start_date_time == '' params << "endDateTime=#{end_date_time}" unless end_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
REVIEW: Retrieve the quantities of the calling user scheduled items, organized by org unit. GET /d2l/api/le/(version)/content/myItems/itemCounts/
# File lib/d2l_sdk/course_content.rb, line 363 def get_current_user_organized_scheduled_items(org_unit_ids_CSV, completion = nil, start_date_time = '', end_date_time = '') query_string = "/d2l/api/le/#{$le_ver}/content/myItems/itemCounts/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_CSV}" params << "completion=#{completion}" unless completion.nil? params << "startDateTime=#{start_date_time}" unless start_date_time == '' params << "endDateTime=#{end_date_time}" unless end_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
Retrieves the calling user’s overdue items, within a number of org units. org_unit_ids_CSV is a CSV of D2LIDs or rather Org unit IDs (optional) Returns: An ObjectListPage JSON block containing a list of OverdueItem. NOTE: If using a support account, try not to use this without defining a csv…
It will consider all courses designated as somehow linked to the acc. and return ALL overdue items EVER for the support account.
# File lib/d2l_sdk/course_content.rb, line 499 def get_current_user_overdue_items(org_unit_ids_CSV = nil) # GET query_string = "/d2l/api/le/#{$le_ver}/overdueItems/myItems" query_string += "?orgUnitIdsCSV=#{org_unit_ids_CSV}" unless org_unit_ids_CSV.nil? _get(query_string) # Returns: An ObjectListPage JSON block containing a list of OverdueItem. end
retrieve personal profile info for the current user context Returns: UserProfile JSON data block
# File lib/d2l_sdk/user.rb, line 424 def get_current_user_profile path = "/d2l/api/lp/#{$lp_ver}/profile/myProfile" _get(path) # Returns: UserProfile JSON data block end
Retrieve the current user’s profile image. INPUT: size (integer) determines the thumbnail size RETURNS: This action returns a file stream containing the current user’s
profile image. Note that the back-end service may return a profile image larger than your provided size.
# File lib/d2l_sdk/user.rb, line 435 def get_current_user_profile_image(size = 0) path = "/d2l/api/lp/#{$lp_ver}/profile/myProfile/image" path += "?size=#{size}" if size != 0 _get(path) # RETURNS: This action returns a file stream containing the current user’s # profile image. Note that the back-end service may return a # profile image larger than your provided size. end
Retrieves the aggregate count of completed and required content topics in an org unit for the calling user. levels: 1=OrgUnit, 2=RootModule, 3=Topic
# File lib/d2l_sdk/course_content.rb, line 539 def get_current_user_progress(org_unit_id, level) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/completions/mycount/" query_string += "?level=#{level}" _get(query_string) # Returns: ObjectListPage JSON block containing # a list of ContentAggregateCompletion items. end
REVIEW: Retrieve the quantities of the calling user’s scheduled items still due. GET /d2l/api/le/(version)/content/myItems/due/itemCounts/
# File lib/d2l_sdk/course_content.rb, line 380 def get_current_user_scheduled_item_count(org_unit_ids_CSV, completion = nil, start_date_time = '', end_date_time = '') # GET query_string = "/d2l/api/le/#{$le_ver}/content/myItems/due/itemCounts/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_CSV}" params << "completion=#{completion}" unless completion.nil? params << "startDateTime=#{start_date_time}" unless start_date_time == '' params << "endDateTime=#{end_date_time}" unless end_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
REVIEW: Retrieve the calling user scheduled items for a particular org unit. GET /d2l/api/le/(version)/#{org_unit_id}/content/myItems/
# File lib/d2l_sdk/course_content.rb, line 425 def get_current_user_scheduled_items_by_org_unit(org_unit_id, completion = nil, start_date_time = '', end_date_time = '') query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/myItems/?" params = [] params << "completion=#{completion}" unless completion.nil? params << "startDateTime=#{start_date_time}" unless start_date_time == '' params << "endDateTime=#{end_date_time}" unless end_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
REVIEW: Retrieve the calling user scheduled items still due.
# File lib/d2l_sdk/course_content.rb, line 348 def get_current_user_scheduled_items_still_due(org_unit_ids_CSV, completion = nil, start_date_time = '', end_date_time = '') query_string = "/d2l/api/le/#{$le_ver}/content/myItems/due/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_CSV}" params << "completion=#{completion}" unless completion.nil? params << "startDateTime=#{start_date_time}" unless start_date_time == '' params << "endDateTime=#{end_date_time}" unless end_date_time == '' query_string = query_string + params.join('&') _get(query_string) # Returns: An ObjectListPage JSON block containing a list of ScheduledItem blocks end
Retrieves information about a data export job that you have previously submitted.
# File lib/d2l_sdk/datahub.rb, line 90 def get_data_export_job(export_job_id) _get("/d2l/api/lp/#{$lp_ver}/dataExport/jobs/#{export_job_id}") # returns: ExportJobData JSON block end
Retrieve a data set
# File lib/d2l_sdk/datahub.rb, line 31 def get_data_set(data_set_id) _get("/d2l/api/lp/#{$lp_ver}/dataExport/list/#{data_set_id}") # returns a DataSetData JSON block end
NOTE: UNSTABLE!!! REVIEW: Retrieve data blocks containing the properties of deleted news items.
# File lib/d2l_sdk/news.rb, line 44 def get_deleted_news(org_unit_id, global = nil) # GET /d2l/api/le/(version)/(orgUnitId)/news/deleted/ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/deleted/" path += "?global=#{global}" unless global.nil? _get(path) end
Retrieve a single demographic field
# File lib/d2l_sdk/demographics.rb, line 144 def get_demographic_field(field_id) path = "/d2l/api/lp/#{$lp_ver}/demographics/fields/#{field_id}" _get(path) # returns fetch form of DemographicsField JSON block end
retrieve a single demographic data type
# File lib/d2l_sdk/demographics.rb, line 225 def get_demographic_type(data_type_id) path = "/d2l/api/lp/#{$lp_ver}/demographics/dataTypes/#{data_type_id}" _get(path) # returns DemographicsDataType JSON block end
retrieve org unit type of department org units
# File lib/d2l_sdk/org_unit.rb, line 358 def get_department_outype path = "/d2l/api/lp/#{$lp_ver}/outypes/department" _get(path) # returns OrgUnitType JSON data block end
REVIEW: Retrieve a file attachment (identified by file ID) from a specific dropbox folder.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/attachments/#{file_id}¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 25 def get_dropbox_file_attachment(org_unit_id, folder_id, file_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/attachments/#{file_id}" _get(path) end
REVIEW: Retrieve all dropbox folder categories for the provided org unit.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/categories/¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 261 def get_dropbox_folder_categories(org_unit_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/categories/" _get(path) end
REVIEW: Retrieve the information for a specific dropbox folder category.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/categories/#{category_id}¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 268 def get_dropbox_folder_category_info(org_unit_id, category_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/categories/#{category_id}" _get(path) end
REVIEW: Retrieve the feedback entry from a dropbox folder for the provided entity.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 177 def get_dropbox_folder_entity_feedback_entry(org_unit_id, folder_id, entity_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}" _get(path) end
REVIEW: Retrieve all the submissions for a specific dropbox folder.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/submissions/¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 131 def get_dropbox_folder_submissions(org_unit_id, folder_id, active_only = nil) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/submissions/" path += "?activeOnly=#{active_only}" if active_only == true || active_only == false _get(path) end
REVIEW: Retrieve one of the files included in a submission for a particular dropbox folder.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/submissions/#{submission_id}/files/#{file_id}¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 139 def get_dropbox_submission_file(org_unit_id, folder_id, submission_id, file_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/submissions/#{submission_id}/files/#{file_id}" _get(path) end
Retrieve a list of all the enrolled user roles the calling user can view in an org unit
# File lib/d2l_sdk/user.rb, line 385 def get_enrolled_roles_in_org_unit(org_unit_id) # this only lists ones viewable by the CALLING user # also, only includes roles that are enrolled in the org unit path = "/d2l/api/#{$lp_ver}/#{org_unit_id}/roles/" _get(path) # returns JSON array of Role data blocks end
Retrieve the enrolled users in the classlist for an org unit
# File lib/d2l_sdk/enroll.rb, line 25 def get_enrolled_users_in_classlist(org_unit_id) path = "/d2l/api/le/#{$lp_ver}/#{org_unit_id}/classlist/" _get(path) # Returns: JSON array of ClasslistUser data blocks. end
Retrieve the enrollment details for the current user in the provided org unit.
# File lib/d2l_sdk/enroll.rb, line 57 def get_enrollments_details_of_current_user(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/enrollments/myenrollments/#{org_unit_id}/" _get(path) # Returns: MyOrgUnitInfo JSON block. end
REVIEW: Retrieve a feedback entry’s file attachment from a dropbox folder for the provided entity.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}/attachments/#{file_id}¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 184 def get_feedback_entry_file_attachment(org_unit_id, folder_id, entity_id, file_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}/attachments/#{file_id}" _get(path) end
REVIEW: Retrieve a particular topic from the provided discussion forum in an org unit.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}¶ ↑
# File lib/d2l_sdk/discussions.rb, line 153 def get_forum_topic(org_unit_id, forum_id, topic_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}" _get(path) end
REVIEW: Retrieve the group restrictions for a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/groupRestrictions/¶ ↑
# File lib/d2l_sdk/discussions.rb, line 160 def get_forum_topic_group_restrictions(org_unit_id, forum_id, topic_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/groupRestrictions/" _get(path) end
REVIEW: Retrieve a particular post in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}¶ ↑
# File lib/d2l_sdk/discussions.rb, line 323 def get_forum_topic_post(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}" _get(path) # RETURNS: Post data block end
REVIEW: Retrieve the approval status for a particular post in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Approval¶ ↑
# File lib/d2l_sdk/discussions.rb, line 331 def get_forum_topic_post_approval_status(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Approval" _get(path) # RETURNS: ApprovalData JSON data block end
REVIEW: Retrieve the flagged status for a particular post in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Flag¶ ↑
# File lib/d2l_sdk/discussions.rb, line 339 def get_forum_topic_post_flagged_status(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Flag" _get(path) # RETURNS: FlagData JSON data block end
REVIEW: Retrieve the rating data for a particular post in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Rating¶ ↑
# File lib/d2l_sdk/discussions.rb, line 347 def get_forum_topic_post_rating_data(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Rating" _get(path) # RETURNS: RatingData JSON data block end
REVIEW: Retrieve the current read status for a particular post in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/ReadStatus¶ ↑
# File lib/d2l_sdk/discussions.rb, line 363 def get_forum_topic_post_read_status(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/ReadStatus" _get(path) # RETURNS: ReadStatusData JSON data block end
REVIEW: Retrieve all the vote data for a particular post in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Votes¶ ↑
# File lib/d2l_sdk/discussions.rb, line 371 def get_forum_topic_post_vote_data(org_unit_id, forum_id, topic_id, post_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Votes" _get(path) # RETURNS: VotesData JSON data block end
REVIEW: Retrieve all posts in a discussion forum topic.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/¶ ↑
RETURNS: JSON array of Post data blocks containing the properties for all the post
# File lib/d2l_sdk/discussions.rb, line 307 def get_forum_topic_posts(org_unit_id, forum_id, topic_id, page_size = 0, page_number = 0, threads_only = nil, thread_id = 0, sort = '') path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/?" params = [] params << "pageSize=#{page_size}" unless page_size.zero? params << "pageNumber=#{page_number}" unless page_number.zero? params << "threadsOnly=#{threads_only}" unless threads_only.nil? params << "threadId=#{thread_id}" unless thread_id.zero? params << "sort=#{sort}" unless sort == '' path = path + params.join('&') _get(path) # RETURNS: JSON array of Post data blocks containing the properties for all the post end
REVIEW: Retrieve topics from the provided discussion forum in an org unit.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/¶ ↑
# File lib/d2l_sdk/discussions.rb, line 146 def get_forum_topics(org_unit_id, forum_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/" _get(path) end
REVIEW: Retrieve all the exempt users for a provided grade. RETURNS: a JSON array of User blocks.
# File lib/d2l_sdk/grades.rb, line 441 def get_grade_exempt_users(org_unit_id, grade_object_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}/exemptions/" _get(path) # RETURNS: a JSON array of User blocks. end
REVIEW: Get statistics for a specified grade item. RETURNS: a GradeStatisticsInfo JSON block.
# File lib/d2l_sdk/grades.rb, line 405 def get_grade_item_statistics(org_unit_id, grade_object_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}/statistics" _get(path) # RETURNS: a GradeStatisticsInfo JSON block. end
REVIEW: Determine if a user is exempt from a grade. RETURNS: a User JSON block.
# File lib/d2l_sdk/grades.rb, line 449 def get_is_user_exempt(org_unit_id, grade_object_id, user_id) path = "GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}/exemptions/#{user_id}" _get(path) # RETURNS: a User JSON block. end
Retrieve the association between a ISBN and org unit.
# File lib/d2l_sdk/course_content.rb, line 296 def get_isbn_org_unit_association(org_unit_id, isbn) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}content/isbn/#{isbn}" _get(query_string) # Returns: a IsbnAssociation JSON data block specifying # the association between an org unit and an ISBN. end
Retrieve all ISBNs associated with an org unit.
# File lib/d2l_sdk/course_content.rb, line 288 def get_isbns_of_org_unit(org_unit_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}content/isbn/" _get(query_string) # Returns: JSON array of IsbnAssociation data blocks specifying # all the org units associated with the provided ISBN. end
# File lib/d2l_sdk/datahub.rb, line 95 def get_job_status_code(export_job_id) get_data_export_job(export_job_id)["Status"] # if 2 is OKAY/COMPLETED end
# File lib/d2l_sdk/requests.rb, line 420 def get_latest_product_version(product_code) begin get_product_supported_versions(product_code)["SupportedVersions"][-1] rescue SocketError => e puts "\n[!] Error likely caused by an incorrect 'd2l_config.json' hostname value: #{e}" exit rescue NoMethodError => e puts "\n[!] Error likely caused by incorrect 'd2l_config.json' api or user values: #{e}" exit end end
NOTE: UNSTABLE REVIEW: retrieve list of known LIS roles
# File lib/d2l_sdk/user.rb, line 579 def get_lis_roles(lis_urn = "") path = "/d2l/api/lp/#{$lp_ver}/imsconfig/roles/" path += lis_urn.to_s if lis_urn != "" _get(path) # returns array of LIS role data blocks end
REVIEW: retrieve the locale account settings for a particular user.
# File lib/d2l_sdk/user.rb, line 626 def get_locale_account_settings(user_id) path = "/d2l/api/lp/#{$lp_ver}/accountSettings/#{user_id}/locale/" _get(path) # returns Locale JSON block end
NOTE: UNSTABLE Retrieve the properties for a particular locale.
# File lib/d2l_sdk/user.rb, line 684 def get_locale_properties(locale_id) path = "/d2l/api/lp/#{$lp_ver}/locales/#{locale_id}" _get(path) # returns Locale JSON block end
retrieve identified log message
# File lib/d2l_sdk/logging.rb, line 56 def get_log_message(log_message_id, include_traces = nil) path = "/d2l/api/lp/#{$lp_ver}/logging/#{log_message_id}/" path += "?includeTraces=#{include_traces}" unless include_traces.nil? _get(path) # returns Message JSON block end
Retrieve a specific module for an org unit. Returns ContentObject JSON data block of type Module
# File lib/d2l_sdk/course_content.rb, line 20 def get_module(org_unit_id, module_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/modules/#{module_id}" _get(query_string) end
Retrieve the structure for a specific module in an org unit. Returns JSON array of ContentObject data blocks (either Module or Topic)
# File lib/d2l_sdk/course_content.rb, line 27 def get_module_structure(org_unit_id, module_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/modules/#{module_id}/structure/" _get(query_string) end
Retrieve a list of the most recently visited topics.
# File lib/d2l_sdk/course_content.rb, line 518 def get_most_recently_visited_topics(org_unit_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/recent" _get(query_string) # Returns: a JSON array of Topic ToC entries. end
REVIEW: Retrieve an attachment for an org unit’s news item.
# File lib/d2l_sdk/news.rb, line 58 def get_news_item_attachment(org_unit_id, news_item_id, file_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/attachments/#{file_id}" _get(path) end
In order to retrieve an entire department's class list, this method uses a predefined org_unit identifier. This identifier is then appended to a path and all classes withiin the department are returned as JSON objects in an arr.
returns: JSON array of classes.
# File lib/d2l_sdk/course.rb, line 294 def get_org_department_classes(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}" _get(path) # returns: JSON array of classes. end
REVIEW: Retrieve the current information for a tool enabled for the provided org unit.
> GET /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)/(toolId)¶ ↑
# File lib/d2l_sdk/config_variables.rb, line 230 def get_org_enabled_tool_info(org_unit_id, tool_id) path = "/d2l/api/lp/#{$lp_ver}/tools/orgUnits/#{org_unit_id}/#{tool_id}" _get(path) end
REVIEW: Retrieve the current information for all tools enabled for the provided org unit.
> GET /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)¶ ↑
# File lib/d2l_sdk/config_variables.rb, line 222 def get_org_enabled_tools_info(org_unit_id, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/tools/orgUnits/#{org_unit_id}?" path += "bookmark=#{bookmark}" unless bookmark == '' _get(path) end
REVIEW: Retrieve the current organization-level information for a tool.
> GET /d2l/api/lp/(version)/tools/org/(toolId)¶ ↑
RETURNS: an OrgInformation JSON block
# File lib/d2l_sdk/config_variables.rb, line 176 def get_org_tool_info(tool_id) path = "GET /d2l/api/lp/#{$lp_ver}/tools/org/#{tool_id}" _get(path) # RETURNS: an OrgInformation JSON block end
REVIEW: Retrieve the current organization-level information for all tools.
> GET /d2l/api/lp/(version)/tools/org/¶ ↑
RETURNS: paged result set containing the resulting OrgInformation data blocks
# File lib/d2l_sdk/config_variables.rb, line 163 def get_org_tools_info(include_restricted_tools = nil, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/tools/org/?" params = [] params << "includeRestrictedTools=#{includeRestrictedTools}" unless include_restricted_tools.nil? params << "bookmark=#{bookmark}" unless bookmark == '' path = path + params.join('&') _get(path) # RETURNS: paged result set containing the resulting OrgInformation data blocks end
Gets all org unit ancestors. Simply, this method references all of the ancestors of the particular org unit and then returns them in a JSON array.
return: JSON array of org_unit ancestors.
# File lib/d2l_sdk/org_unit.rb, line 98 def get_org_unit_ancestors(org_unit_id, ou_type_id = 0) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/ancestors/" path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0 _get(path) # return json of org_unit ancestors end
TODO: –UNSTABLE– Retrieve an assessment in an org unit. RETURNS: a RubricAssessment JSON structure.
# File lib/d2l_sdk/grades.rb, line 512 def get_org_unit_assessment(org_unit_id, assessment_type, object_type, object_id, user_id) # GET /d2l/api/le/(version)/(orgUnitId)/assessment # RETURNS: a RubricAssessment JSON structure. end
REVIEW: Retrieve a calendar event from a particular org unit. Returns: a EventDataInfo JSON data block
# File lib/d2l_sdk/calendar.rb, line 16 def get_org_unit_calendar_event(org_unit_id, event_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}" _get(path) end
REVIEW: Retrieve a count of calling user’s calendar events, within the
provided org unit context.
RETURNS: An EventCountInfo JSON data block.
# File lib/d2l_sdk/calendar.rb, line 79 def get_org_unit_calendar_event_count(start_date_time, end_date_time, association = nil, event_type = nil) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/myEvents/itemCounts/?" params = [] params << "startDateTime=#{start_date_time}" params << "endDateTime=#{end_date_time}" params << "association=#{association}" unless association.nil? params << "eventType=#{event_type}" unless event_type.nil? path = path + params.join('&') _get(path) end
gets all children of a particular org unit, as referenced by the “org_unit_id” argument. A get request is then performed by a preformatted path.
# File lib/d2l_sdk/org_unit.rb, line 108 def get_org_unit_children(org_unit_id, ou_type_id = 0) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/children/" path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0 _get(path) # return json of org_unit children end
REVIEW: Retrieve all the course completion records for an org unit. RETURNS: This action returns a paged result set containing the resulting CourseCompletion data blocks for the segment following your bookmark parameter (or the first segment if the parameter is empty or missing).
# File lib/d2l_sdk/grades.rb, line 347 def get_org_unit_completion_records(org_unit_id, user_id = 0, start_expiry = '', end_expiry = '', bookmark = '') path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/courseCompletion/?" params = [] params << "userId=#{user_id}" if user_id != 0 params << "startExpiry=#{start_expiry}" if startExpiry != '' params << "endExpiry=#{end_expiry}" if endExpiry != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # RETURNS: This action returns a paged result set containing the resulting # CourseCompletion data blocks for the segment following your bookmark # parameter (or the first segment if the parameter is empty or missing). end
gets all descendents of a particular org unit, as referenced by the “org_unit_id” argument. A get request is then performed by a preformatted path.
# File lib/d2l_sdk/org_unit.rb, line 130 def get_org_unit_descendants(org_unit_id, ou_type_id = 0) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/descendants/" path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0 _get(path) # return JSON array of OrgUnit data blocks end
REVIEW: Retrieve a particular discussion forum for an org unit.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}¶ ↑
# File lib/d2l_sdk/discussions.rb, line 24 def get_org_unit_discussion(org_unit_id, forum_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}" _get(path) end
REVIEW: Retrieve all dropbox folders for an org unit.
> GET /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 10 def get_org_unit_dropbox_folders(org_unit_id, only_current_students_and_groups = nil) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/" path += "?onlyCurrentStudentsAndGroups=#{only_current_students_and_groups}" if only_current_students_and_groups == true || only_current_students_and_groups == false _get(path) end
Retrieve enrollment details for a user in the provided org unit. Note: Same as get_user_enrollment_data_by_org_unit
This call is equivalent to the route that fetches by specifying the user first, and then the org unit.
# File lib/d2l_sdk/enroll.rb, line 82 def get_org_unit_enrollment_data_by_user(org_unit_id, user_id) path = "/d2l/api/lp/#{$lp_ver}/orgUnits/#{org_unit_id}/users/#{user_id}" _get(path) # Returns: EnrollmentData JSON block. end
Retrieve the collection of users enrolled in the identified org unit. Optional params: –roleId: D2LID –bookmark: String
# File lib/d2l_sdk/enroll.rb, line 67 def get_org_unit_enrollments(org_unit_id, role_id = 0, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/enrollments/orgUnits/#{org_unit_id}/users/?" params = [] params << "roleId=#{role_id}" if role_id != 0 params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # Returns: paged result set containing the resulting OrgUnitUser data blocks end
REVIEW: Retrieve a list of all grade categories for a provided org unit. Return: This action retrieves a JSON array of GradeObjectCategory blocks.
# File lib/d2l_sdk/grades.rb, line 187 def get_org_unit_grade_categories(org_unit_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/categories/" _get(path) # Return: This action retrieves a JSON array of GradeObjectCategory blocks. end
REVIEW: Retrieve a specific grade category for a provided org unit. Return: This action retrieves a GradeObjectCategory JSON block.
# File lib/d2l_sdk/grades.rb, line 195 def get_org_unit_grade_category(org_unit_id, category_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/categories/#{category_id}" _get(path) # Return: This action retrieves a GradeObjectCategory JSON block. end
REVIEW: Retrieve the grades configuration for the org unit. RETURNS: a GradeSetupInfo JSON block.
# File lib/d2l_sdk/grades.rb, line 417 def get_org_unit_grade_config(org_unit_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/setup/" _get(path) # RETURNS: a GradeSetupInfo JSON block. end
REVIEW: Retrieve a specific grade object for a particular org unit. Return: This action returns a GradeObject JSON block.
# File lib/d2l_sdk/grades.rb, line 24 def get_org_unit_grade_object(org_unit_id, grade_object_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}" _get(path) # RETURN: This action returns a GradeObject JSON block. end
REVIEW: Retrieve a particular grade scheme. Return: This action returns a GradeScheme JSON block.
# File lib/d2l_sdk/grades.rb, line 244 def get_org_unit_grade_scheme(org_unit_id, grade_scheme_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/schemes/#{grade_scheme_id}" _get(path) # Return: This action returns a GradeScheme JSON block. end
REVIEW: Retrieve all the grade schemes for a provided org unit. Return: This action returns a JSON array of GradeScheme blocks.
# File lib/d2l_sdk/grades.rb, line 236 def get_org_unit_grade_schemes(org_unit_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/schemes/" _get(path) # Return: This action returns a JSON array of GradeScheme blocks. end
REVIEW: Retrieve all the current grade objects for a particular org unit. Return: This action returns a JSON array of GradeObject blocks.
# File lib/d2l_sdk/grades.rb, line 16 def get_org_unit_grades(org_unit_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/" _get(path) # RETURN: This action returns a JSON array of GradeObject blocks. end
Retrieve a particular group in an org unit.
# File lib/d2l_sdk/group.rb, line 44 def get_org_unit_group(org_unit_id, group_category_id, group_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}/groups/#{group_id}" _get(path) end
Retrieve a particular group category for an org unit.
# File lib/d2l_sdk/group.rb, line 32 def get_org_unit_group_category(org_unit_id, group_category_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}" _get(path) end
REVIEW: Retrieve a particular news item for an org unit.
# File lib/d2l_sdk/news.rb, line 52 def get_org_unit_news_item(org_unit_id, news_item_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}" _get(path) end
REVIEW: Retrieve a list of news items for an org unit.
# File lib/d2l_sdk/news.rb, line 36 def get_org_unit_news_items(org_unit_id, since = "") path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/" path += "?since=#{since}" if since != "" _get(path) end
gets all parents of a particular org unit, as referenced by the “org_unit_id” argument. A get request is then performed by a preformatted path.
# File lib/d2l_sdk/org_unit.rb, line 155 def get_org_unit_parents(org_unit_id, ou_type_id = 0) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/parents/" path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0 _get(path) # return json of org_unit parents end
gets all properties of a particular org unit, as referenced by the “org_unit_id” argument. A get request is then performed by a preformatted path.
# File lib/d2l_sdk/org_unit.rb, line 53 def get_org_unit_properties(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}" _get(path) # return json of org_unit properties end
TODO: –UNSTABLE– Retrieve rubrics for an object in an org unit. RETURNS: a JSON array of Rubric blocks.
# File lib/d2l_sdk/grades.rb, line 505 def get_org_unit_rubrics(org_unit_id, object_type, object_id) # GET /d2l/api/le/(version)/(orgUnitId)/rubrics # RETURNS: a JSON array of Rubric blocks. end
Retrieve the section property data for an org unit.
# File lib/d2l_sdk/section.rb, line 22 def get_org_unit_section_property_data(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/settings" _get(path) # returns a SectionPropertyData JSON block in the Fetch form. end
Retrieve all the sections for a provided org unit.
# File lib/d2l_sdk/section.rb, line 15 def get_org_unit_sections(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/" _get(path) # returns a JSON array of SectionData blocks in the Fetch form end
Retrieve the table of course content for an org unit.
# File lib/d2l_sdk/course_content.rb, line 525 def get_org_unit_toc(org_unit_id, ignore_module_data_restrictions = false) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/toc" query_string += '?ignoreModuleDateRestrictions=true' if ignore_module_data_restrictions _get(query_string) # Returns: a TableOfContents JSON block. end
Retrieve all the org units associated with an ISBN.
# File lib/d2l_sdk/course_content.rb, line 280 def get_org_units_of_isbn(isbn) # GET query_string = "/d2l/api/le/#{$le_ver}/content/isbn/#{isbn}" _get(query_string) # Returns: JSON array of IsbnAssociation data blocks specifying # all the org units associated with the provided ISBN. end
Retrieves the organization info. Only gets a small amount of information, but may be useful in some instances.
# File lib/d2l_sdk/org_unit.rb, line 10 def get_organization_info path = "/d2l/api/lp/#{$lp_ver}/organization/info" _get(path) # return: Organization JSON block end
This retrieves information about a particular org unit type, referenced via the outype_id argument. This is then returned as a JSON object.
# File lib/d2l_sdk/org_unit.rb, line 352 def get_outype(outype_id) path = "/d2l/api/lp/#{$lp_ver}/outypes/#{outype_id}" _get(path) end
REVIEW: Retrieve all the calendar events for the calling user, within a number of org units. RETURNS: a paged result set containing the resulting EventDataInfo JSON data blocks
# File lib/d2l_sdk/calendar.rb, line 93 def get_paged_calendar_events_by_org_units(org_unit_ids_csv, start_date_time, end_date_time, bookmark = '') path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/orgunits/?" params = [] params << "orgUnitIdsCSV=#{org_unit_ids_csv}" params << "startDateTime=#{start_date_time}" params << "endDateTime=#{end_date_time}" params << "bookmark=#{bookmark}" unless bookmark == '' path = path + params.join('&') _get(path) end
Gets all children of the org unit, but in a paged result. These are first referenced via the org_unit_id argument, and then a bookmark is appended if there is one specified. This is then returned as a json array.
return: JSON array of org unit children.
# File lib/d2l_sdk/org_unit.rb, line 120 def get_paged_org_unit_children(org_unit_id, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/children/paged/" path += "?bookmark=#{bookmark}" if bookmark != '' _get(path) # return json of org_unit children end
gets a paged result of the org unit's descendants. The descendants are first referenced by a preformatted path; then if there is a defined bookmark, the bookmark parameter is appended to the path.
return: JSON array of org unit descendants (paged)
# File lib/d2l_sdk/org_unit.rb, line 142 def get_paged_org_unit_descendants(org_unit_id, ou_type_id = 0, bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/descendants/paged/?" params = [] params << "ouTypeId=#{ou_type_id}" if ou_type_id != 0 params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # return paged json of org_unit descendants end
retrieve the list of parent org unit type constraints for course offerings
# File lib/d2l_sdk/course.rb, line 20 def get_parent_outypes_courses_schema_constraints path = "/d2l/api/lp/#{$lp_ver}/courses/schema" _get(path) # returns a JSON array of SchemaElement blocks end
Retrieve the collection of versions supported by a specific product component
# File lib/d2l_sdk/requests.rb, line 415 def get_product_supported_versions(product_code) path = "/d2l/api/#{product_code}/versions/" _get(path) end
Retrieve a particular profile image, by Profile ID. RETURNS: This action returns a file stream containing the current user’s
profile image. Note that the back-end service may return a profile image larger than your provided size.
# File lib/d2l_sdk/user.rb, line 455 def get_profile_image(profile_id, size = 0) path = "/d2l/api/lp/#{$lp_ver}/profile/#{profile_id}/image" path += "?size=#{size}" if size != 0 _get(path) # RETURNS: This action returns a file stream containing the current user’s # profile image. Note that the back-end service may return a # profile image larger than your provided size. end
TODO: –UNSTABLE– Retrieve the user progress items in an org unit, for specific users or content topics. _get “/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/userprogress/”
# File lib/d2l_sdk/course_content.rb, line 549 def get_progress_of_users; end
# File lib/d2l_sdk/org_unit.rb, line 36 def get_properties_of_all_org_units(org_unit_type = '', org_unit_code = '', org_unit_name = '', bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/orgstructure/?" params = [] params << "orgUnitType=#{org_unit_type}" if org_unit_type != '' params << "orgUnitCode=#{org_unit_code}" if org_unit_code != '' params << "orgUnitName=#{org_unit_name}" if org_unit_name != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # ONLY RETRIEVES FIRST 100 after bookmark # returns: paged result of OrgUnitProperties blocks end
Retrieves a paged result of all recycled org units. Thus, only the first 100 are retrieved since the first referenced org unit. As such, if the bookmark is not defined, then it only retrieves the first 100.
return: JSON array of recycled org units.
# File lib/d2l_sdk/org_unit.rb, line 310 def get_recycled_org_units(bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/" path += "?bookmark=#{bookmark}" if bookmark != '' _get(path) # GETS ONLY FIRST 100 end
Retrieve the root module(s) for an org unit. Returns JSON array of ContentObject data blocks of type Module
# File lib/d2l_sdk/course_content.rb, line 34 def get_root_modules(org_unit_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/root/" _get(query_string) end
retrieves all sections with the same code. NOTE: As the code SHOULD be unique, this function assumes that the returned item is the requested item.
# File lib/d2l_sdk/section.rb, line 176 def get_section_by_section_code(code) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/?orgUnitCode=#{code}" _get(path)["Items"][0] # RETURNS: SectionData block end
Retrieve a section from a particular org unit.
# File lib/d2l_sdk/section.rb, line 29 def get_section_data(org_unit_id, section_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/#{section_id}" _get(path) # returns a SectionData JSON block in the Fetch form. end
Simple bridge function allowing for retrieval of section data by using the section's code. As D2L does not allow for accessing the SectionData block without using a parent's id, this retrieves the parents id and allows for such functionality.
# File lib/d2l_sdk/section.rb, line 195 def get_section_data_by_code(code) sect_id = get_section_by_section_code(code)["Identifier"] parent_id = get_org_unit_parents(sect_id)[0]["Identifier"] get_section_data(parent_id, sect_id) end
Simple bridge function that allows for the retrieval of a section's ID based on its section code. NOTE: Again, As the code SHOULD be unique, this function assumes that the returned item is the requested item.
# File lib/d2l_sdk/section.rb, line 186 def get_section_id_by_section_code(code) get_section_by_section_code(code)["Identifier"] # RETURNS: D2LID of the section identified by its section code end
Retrieves a semester by a particular id. This is done by referencing it by its org unit id in the organization and then performing a get request on it.
return: JSON of org unit properties.
# File lib/d2l_sdk/semester.rb, line 50 def get_semester_by_id(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/" + org_unit_id.to_s _get(path) # return json of org_unit properties end
Rather than retrieving all semesters, this retrieves all semesters by a particular string. First, a boolean is created where it is assumed the semester is not found. Then an array is created with all the 'found' semesters assuming none are found, but providing the structure to still return uniform data that can be iterated. Then, by iterating through all semesters and only storing ones that conform to the search string, all matched semesters are then returned.
Returns: Array of all semester JSON formatted data (with search string in name)
# File lib/d2l_sdk/semester.rb, line 79 def get_semester_by_name(search_string) semester_not_found = true semester_results = [] puts "[+] Searching for semesters using search string: \'#{search_string}\'".yellow results = get_all_semesters results.each do |x| if x['Name'].downcase.include? search_string.downcase semester_not_found = false semester_results.push(x) end end if semester_not_found puts '[-] No semesters could be found based upon the search string.'.yellow end semester_results end
retrieve org unit type of semester org units
# File lib/d2l_sdk/org_unit.rb, line 365 def get_semester_outype path = "/d2l/api/lp/#{$lp_ver}/outypes/semester" _get(path) # returns OrgUnitType JSON data block end
Retrieve a specific topic for an org unit. Returns a ContentObject JSON data block of type Topic
# File lib/d2l_sdk/course_content.rb, line 41 def get_topic(org_unit_id, topic_id) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/topics/#{topic_id}" _get(query_string) end
Retrieve the content topic file for a content topic. Returns underlying file for a file content topic
# File lib/d2l_sdk/course_content.rb, line 48 def get_topic_file(org_unit_id, topic_id, stream = false) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/topics/#{topic_id}/file" query_string += "?stream=true" if stream == true _get(query_string) end
ACTIVATION:###########
REVIEW: Retrieve a particular user’s activation settings. RETURNS: a UserActivationData JSON block with the current activation status.
# File lib/d2l_sdk/user.rb, line 276 def get_user_activation_settings(user_id) path = "/d2l/api/lp/#{$lp_ver}/users/#{user_id}/activation" _get(path) # RETURNS: a UserActivationData JSON block with the current activation status of the user. end
Retrieves a user based upon an explicitly pre-defined user_id. This is also known as the Identifier of this user object. Upon retrieving the user, it is then returned.
RETURNS: JSON user object.
# File lib/d2l_sdk/user.rb, line 197 def get_user_by_user_id(user_id) # Retrieve data for a particular user path = "/d2l/api/lp/#{$lp_ver}/users/#{user_id}" _get(path) # RETURNS: a UserData JSON block end
Retrieves a user based upon an explicitly defined username. Returns: JSON response of this user.
# File lib/d2l_sdk/user.rb, line 92 def get_user_by_username(username) get_users('', username) end
REVIEW: Retrieve all the calendar events for a specified user’s explicit
enrollments within the organization containing the specified org unit.
RETURNS: a paged result set containing the resulting EventDataInfo JSON data blocks
# File lib/d2l_sdk/calendar.rb, line 108 def get_user_calendar_events(org_unit_id, user_id, start_date_time, end_date_time, bookmark = '') path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/user/?" params = [] params << "userId=#{user_id}" params << "startDateTime=#{start_date_time}" params << "endDateTime=#{end_date_time}" params << "bookmark=#{bookmark}" unless bookmark == '' path = path + params.join('&') _get(path) # RETURNS: a paged result set containing the resulting EventDataInfo JSON data blocks end
TODO: Retrieve all the course completion records for a user. RETURNS: This action returns a paged result set containing the resulting CourseCompletion data blocks for the segment following your bookmark parameter (or the first segment if the parameter is empty or missing).
# File lib/d2l_sdk/grades.rb, line 366 def get_user_completion_records(user_id, start_expiry = '', end_expiry = '', bookmark = '') path = "/d2l/api/le/#{$le_ver}/grades/courseCompletion/#{user_id}/?" params = [] params << "startExpiry=#{start_expiry}&" if startExpiry != '' params << "endExpiry=#{end_expiry}&" if endExpiry != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # RETURNS: This action returns a paged result set containing the resulting # CourseCompletion data blocks for the segment following your bookmark # parameter (or the first segment if the parameter is empty or missing). end
Retrieve all the demographics entries for a single user.
# File lib/d2l_sdk/demographics.rb, line 59 def get_user_demographics(user_id, field_ids = '', bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/demographics/users/#{user_id}?" params = [] params << "fieldIds=#{field_ids}" if field_ids != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) end
Retrieve enrollment details in an org unit for the provided user. Same as get_org_unit_enrollment_data_by_user
# File lib/d2l_sdk/enroll.rb, line 107 def get_user_enrollment_data_by_org_unit(user_id, org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/enrollments/users/#{user_id}/orgUnits/#{org_unit_id}" _get(path) # Returns: EnrollmentData JSON block. end
REVIEW: Retrieve the final grade value for a particular user. INPUT: grade_type is an optional parameter. Forces grade to be returned as a certain grade type, such as calculated or adjusted. Return: This action returns a GradeValue JSON block containing the final calculated grade value for the provided user.
# File lib/d2l_sdk/grades.rb, line 282 def get_user_final_grade(org_unit_id, user_id, grade_type = '') path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/final/values/#{user_id}" path += "?gradeType=#{grade_type}" if grade_type != '' _get(path) # Return: This action returns a GradeValue JSON block containing the final # calculated grade value for the provided user. end
REVIEW: Retrieve all the grade objects for a provided user in a provided org unit with exemption status included. RETURNS: BulkGradeObjectExemptionResult JSON block.
# File lib/d2l_sdk/grades.rb, line 477 def get_user_grade_exemptions(org_unit_id, user_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/exemptions/#{user_id}" _get(path) # RETURNS: BulkGradeObjectExemptionResult JSON block. end
REVIEW: Retrieve a specific grade value for the current user context assigned in a particular org unit. RETURN: This action returns a GradeValue JSON block.
# File lib/d2l_sdk/grades.rb, line 311 def get_user_grade_object_grade(org_unit_id, grade_object_id, user_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}/values/#{user_id}" _get(path) # RETURN: This action returns a GradeValue JSON block. end
REVIEW: Retrieve all the grade objects for a particular user assigned in an org unit.
# File lib/d2l_sdk/grades.rb, line 326 def get_user_org_unit_grades(org_unit_id, user_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/values/#{user_id}/" _get(path) # RETURN: This action returns a JSON array of GradeValue blocks. end
Retrieve the overdue items for a particular user in a particular org unit. org_unit_ids_CSV
is a CSV of D2LIDs or rather Org unit IDs (optional) Viewing user overdue items depends upon the current calling user's permissions. Returns: An ObjectListPage JSON block containing a list of OverdueItem.
# File lib/d2l_sdk/course_content.rb, line 485 def get_user_overdue_items(user_id, org_unit_ids_CSV = nil) # GET query_string = "/d2l/api/le/#{$le_ver}/overdueItems/" query_string += "?userId=#{user_id}" query_string += "&orgUnitIdsCSV=#{org_unit_ids_CSV}" unless org_unit_ids_CSV.nil? _get(query_string) # Returns: An ObjectListPage JSON block containing a list of OverdueItem. end
retrieve a particular personal profile, by Profile ID
# File lib/d2l_sdk/user.rb, line 445 def get_user_profile_by_profile_id(profile_id) path = "/d2l/api/lp/#{$lp_ver}/profile/#{profile_id}" _get(path) # Returns UserProfile JSON data block end
Retrieve a particular personal profile, by User ID.
# File lib/d2l_sdk/user.rb, line 465 def get_user_profile_by_user_id(user_id) path = "/d2l/api/lp/#{$lp_ver}/profile/user/#{user_id}" _get(path) # Returns UserProfile JSON data block end
Retrieve a particular profile image, by User ID. RETURNS: This action returns a file stream containing the current user’s
profile image. Note that the back-end service may return a profile image larger than your provided size.
# File lib/d2l_sdk/user.rb, line 475 def get_user_profile_image(user_id) path = "/d2l/api/lp/#{$lp_ver}/profile/user/#{user_id}" path += "?size=#{size}" if size != 0 _get(path) # RETURNS: This action returns a file stream containing the current user’s # profile image. Note that the back-end service may return a # profile image larger than your provided size. end
TODO: –UNSTABLE– Retrieve one user’s progress within an org unit for a particular content topic. _get “/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/userprogress/#{topic_id}”
# File lib/d2l_sdk/course_content.rb, line 553 def get_user_progress; end
Retrieve a particular user role
# File lib/d2l_sdk/user.rb, line 377 def get_user_role(role_id) path = "/d2l/api/lp/#{$lp_ver}/roles/#{role_id}" _get(path) # returns a Role JSON data block end
NOTE: UNSTABLE REVIEW: retrieve mapping between a user role and a LIS role
# File lib/d2l_sdk/user.rb, line 598 def get_user_role_lis_mappings_by_role(role_id, d2lid = 0) path = "/d2l/api/lp/#{$lp_ver}/imsconfig/map/roles/#{role_id}" path += d2lid.to_s if d2lid != 0 _get(path) # returns JSON array of LIS role mapping data blocks end
NOTE: UNSTABLE REVIEW: retrieve mappings between user roles and LIS roles
# File lib/d2l_sdk/user.rb, line 588 def get_user_role_lis_mappings_by_urn(lis_urn = "", d2lid = 0) path = "/d2l/api/lp/#{$lp_ver}/imsconfig/map/roles/" path += lis_urn.to_s if lis_urn != "" path += d2lid.to_s if d2lid != 0 _get(path) # returns JSON array of LIS role mapping data blocks end
Simple get users function that assists in retrieving users by particular paramerters. These parameters are then appended to the query string if they are defined by the user.
Returns: JSON of all users matching the parameters given.
# File lib/d2l_sdk/user.rb, line 76 def get_users(org_defined_id = '', username = '', bookmark = '') path = "/d2l/api/lp/#{$lp_ver}/users/?" params = [] params << "orgDefinedId=#{org_defined_id}" if org_defined_id != '' params << "userName=#{username}" if username != '' params << "bookmark=#{bookmark}" if bookmark != '' path = path + params.join('&') _get(path) # If- username is defined, this RETURNS a single UserData JSON block # else if- org_defined_id is defined, this returns a UserData JSON array # else- if neither is defined, this RETURNS a paged result set of users after # the bookmark end
Helper function that retrieves the first 100 users after the specified bookmark.
Returns: JSON array of user objects.
# File lib/d2l_sdk/user.rb, line 100 def get_users_by_bookmark(bookmark = '') get_users('', '', bookmark) # Returns: JSON array of user objects. end
retrieve all supported versions for all product components
# File lib/d2l_sdk/requests.rb, line 433 def get_versions path = "/d2l/api/versions/" _get(path) # returns: SupportedVersion JSON block end
Retrieves the whoami of the user authenticated through the config file. RETURNS: JSON whoami response
# File lib/d2l_sdk/user.rb, line 65 def get_whoami path = "/d2l/api/lp/#{$lp_ver}/users/whoami" _get(path) # RETURNS: a WhoAmIUser JSON block for the current user context end
# File lib/d2l_sdk/group.rb, line 229 def group_category_locker_set_up?(org_unit_id, group_category_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}/locker" _get(path)["HasLocker"] # returns true if the group cat. locker has been setup already end
REVIEW: Dismiss (hide) a news item for an org unit.
# File lib/d2l_sdk/news.rb, line 108 def hide_news_item(org_unit_id, news_item_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/dismiss" _post(path, {}) end
Initialize one or more sections for a particular org unit.
# File lib/d2l_sdk/section.rb, line 111 def initialize_org_unit_sections(org_unit_id, section_property_data) payload = { 'EnrollmentStyle' => 0, 'EnrollmentQuantity' => 0, 'AutoEnroll' => false, 'RandomizeEnrollments' => false }.merge!(section_property_data) # Check the validity of the SectionPropertyData that is passed as a payload check_section_property_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/" # JSON param: SectionPropertyData _put(path, payload) # returns a JSON array of SectionData data blocks, in the Fetch # form, for the org unit’s initial section(s) end
TODO: Initiate a resumable file upload request for a particular entity’s feedback for a specific dropbox folder.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}/upload¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 253 def initiate_feedback_entry_file_upload; end
NOTE: UNSTABLE! TODO: UNSTABLE!–Link a user to a Google Apps user account. RETURNS: ?
# File lib/d2l_sdk/user.rb, line 303 def link_user_google_apps_account(google_apps_linking_item) # POST /d2l/api/gae/(version)/linkuser end
NOTE: UNSTABLE TODO: –UNSTABLE– Map a user role to a set of LIS Roles. input: Mappings = String array
# File lib/d2l_sdk/user.rb, line 608 def map_user_role_to_lis_roles(role_id, mappings) # PUT /d2l/api/lp/(version)/imsconfig/map/roles/(roleId) end
REVIEW: Mark a submitted file as read.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/submissions/#{submission_id}/files/#{file_id}/markAsRead¶ ↑
INPUT: “Provide an empty post body.”
# File lib/d2l_sdk/dropbox.rb, line 159 def mark_file_as_read(org_unit_id, folder_id, submission_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/submissions/#{submission_id}/files/#{file_id}/markAsRead" _post(path, {}) end
Initiates a multithreaded search to streamline the search of a user based upon a part of their search str. This calls get_user_by_string
, which is actually using a bookmarked search. This brings the search time down from 15+ minutes to only ~10-13 seconds, depending upon the computer. This can be sped up MUCH more by using a computer with more cores. Anyways, based upon the number of threads used, iterations are performed, specifying certain ranges for each thread to search by using get_user_by_string
. Upon all of the threads joining, the thread_results are returned (as they are all the matching names)
returns: Array::param_values_with_string_included example— multithreaded_user_search
(“UserName”, “api”, 17) example 2— multithreaded_user_search
(“UserName”, /pap/, 17, true)
# File lib/d2l_sdk/user.rb, line 130 def multithreaded_user_search(parameter, search_string, num_of_threads, regex = false) # Assumed: there is only up to 60,000 users. # Start from 1, go up to max number of users for this search... max_users = 60_000 range_min = 1 # range max = the upper limit for the search for a thread range_max = max_users / num_of_threads + 1 threads = [] thread_results = [] # ap "creating #{num_of_threads} threads..." # from 0 up until max number of threads.. (0...num_of_threads - 1).each do |iteration| # setup range limits for the specific thread min = range_min + range_max * iteration max = range_max + (range_max - 1) * iteration range = create_range(min, max) # push thread to threads arr and start thread search of specified range. threads[iteration] = Thread.new do _get_user_by_string(parameter, search_string, range, regex).each do |match| thread_results.push(match) end end end # Join all of the threads threads.each(&:join) puts "returning search results for #{parameter}::#{search_string}" # Return an array of users that exist with the search_string in the param. thread_results end
REVIEW: Pin an org unit to the top of the list of a user’s enrollments.
# File lib/d2l_sdk/enroll.rb, line 154 def pin_org_unit_for_current_context(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/enrollments/myenrollments/#{org_unit_id}/pin" _post(path, {}) # RETURNS: MyOrgUnitInfo JSON block. end
TODO: Post a new submission for the current user context to a particular dropbox folder.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/submissions/mysubmissions/¶ ↑
INPUT: multipart/mixed body should contain a JSON part encoding the submission’s descriptive comments
in RichText, followed by the submission file’s data.
# File lib/d2l_sdk/dropbox.rb, line 154 def post_current_user_new_submission; end
TODO: Post feedback (without attachment) for a particular submission in a specific dropbox folder.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}¶ ↑
INPUT: Dropbox.DropboxFeedback
# File lib/d2l_sdk/dropbox.rb, line 192 def post_feedback_without_attachment(org_unit_id, folder_id, entity_id, entity_type, dropbox_feedback) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}" payload = { "Score" => 1, "Feedback" => { "Text" => "String", "Html" => "String" }, "RubricAssessments" => [ { "RubricId" => 0, "OverallScore" => nil, # or null "OverallFeedback" => { # RICHTEXT "Text" => "String", "Html" => "String" }, "OverallLevel" => { # or null "LevelId" => 0, "Feedback" => { # RICHTEXT "Text" => "String", "Html" => "String" } }, "OverallScoreOverridden" => false, "OverallFeedbackOverridden" => false, "CriteriaOutcome" => [ # Array of CriterionOutcome hashes { # Example CriterionOutcome hash. Set for merging as # it is assumed -at least- one is required. "CriterionId" => 0, "LevelId" => nil, # or a D2LID::Integer "Score" => nil, # or a decimal "ScoreIsOverridden" => false, "Feedback" => { # RICHTEXT "Text" => "String", "Html" => "String" }, "FeedbackIsOverridden" => false }, # more CriterionOutcome hashes here! :D ] } ], "IsGraded" => false }.merge!(dropbox_feedback) # TODO: Create a schema to validate this payload against... :/ _post(path, payload) end
TODO: Post a new group submission to a particular dropbox folder.
> POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/submissions/group/(groupId)¶ ↑
INPUT: multipart/mixed body should contain a JSON part encoding the submission’s descriptive comments
in RichText, followed by the submission file’s data.
# File lib/d2l_sdk/dropbox.rb, line 148 def post_new_group_submission; end
requests input from the user, cuts off any new line and downcases it.
returns: String::downcased_user_input
# File lib/d2l_sdk/auth.rb, line 16 def prompt(*args) print(*args) gets.chomp.downcase # returns: String::downcased_user_input end
REVIEW: Publish a draft news item for an org unit.
# File lib/d2l_sdk/news.rb, line 114 def publish_draft_news_item(org_unit_id, news_item_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/publish" _post(path, {}) end
An org unit is recycled by executing a POST http method and recycling it. The path for the recycling is created using the org_unit_id argument and then the post method is executed afterwards.
# File lib/d2l_sdk/org_unit.rb, line 320 def recycle_org_unit(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}/recycle" _post(path, {}) end
Rather than recycling a semester by a specific id, this function can recycle all semesters that match a particular name. The names must be exactly the same as the “name” argument. Each name that is the exact same as this argument is then recycled, iteratively.
# File lib/d2l_sdk/semester.rb, line 156 def recycle_semester_by_name(name) results = get_semester_by_name(name) results.each do |semester_match| if semester_match['Name'] == name recycle_semester_data(semester_match['Identifier']) end end end
This function provides the means to put the semester data into the recycling bin. A path is then created using the org_unit_id argument. Once this is done the post http method is then completed in order to officially recycle the data
# File lib/d2l_sdk/semester.rb, line 144 def recycle_semester_data(org_unit_id) # Define a path referencing the user data using the user_id puts '[!] Attempting to recycle Semester data referenced by id: ' + org_unit_id.to_s path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/" + org_unit_id.to_s + '/recycle' # setup user path _post(path, {}) puts '[+] Semester data recycled successfully'.green end
REVIEW: Register a new LTI link for an org unit.
> POST /d2l/api/le/(version)/lti/link/(orgUnitId)¶ ↑
# File lib/d2l_sdk/lti.rb, line 80 def register_lti_link(org_unit_id, create_lti_link_data) path = "/d2l/api/le/#{$le_ver}/lti/link/#{org_unit_id}" payload = { 'Title' => '', 'Url' => '', 'Description' => '', 'Key' => '', 'PlainSecret' => '', 'IsVisible' => false, 'SignMessage' => false, 'SignWithTc' => false, 'SendTcInfo' => false, 'SendContextInfo' => false, 'SendUserId' => false, 'SendUserName' => false, 'SendUserEmail' => false, 'SendLinkTitle' => false, 'SendLinkDescription' => false, 'SendD2LUserName' => false, 'SendD2LOrgDefinedId' => false, 'SendD2LOrgRoleId' => false, 'UseToolProviderSecuritySettings' => false, 'CustomParameters' => nil # or Array of CustomParameter # e.g. [{"Name" => "", "Value" => ""},{"Name" => "", "Value" => ""}] }.merge!(create_lti_link_data) check_create_lti_link_data_validity(payload) _post(path, payload) end
REVIEW: Register a new LTI tool provider for an org unit.
> POST /d2l/api/le/(version)/lti/tp/(orgUnitId)¶ ↑
INPUT: LTI.CreateLtiProviderData
# File lib/d2l_sdk/lti.rb, line 210 def register_lti_tool_provider(org_unit_id, create_lti_provider_data) path = "/d2l/api/le/#{$le_ver}/lti/tp/#{org_unit_id}" payload = { 'LaunchPoint' => '', 'Secret' => '', 'UseDefaultTcInfo' => '', 'Key' => '', 'Name' => '', 'Description' => '', 'ContactEmail' => '', 'IsVisible' => false, 'SendTcInfo' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendContextInfo' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendUserId' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendUserName' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendUserEmail' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendLinkTitle' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendLinkDescription' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendD2LUserName' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendD2LOrgDefinedId' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendD2LOrgRoleId' => false # Appears in LE's 1.12+ contract as of LE v10.6.0 }.merge!(create_lti_provider_data) check_create_lti_provider_data_validity(payload) _post(path, payload) # RETURNS: a LtiToolProviderData JSON block end
REVIEW: Remove an auditee from the list of users that an auditor is auditing. Input: auditee_id (D2LID as single JSON number) - Auditee to be removed
# File lib/d2l_sdk/enroll.rb, line 177 def remove_auditee(auditor_id, auditee_id) path = "/d2l/api/le/#{$le_ver}/auditing/auditors/#{auditor_id}/auditees/" _delete(path, true, { AuditeeId: auditee_id }) end
Same as adding a course to a semester, in regards to being a bridge function. Obviously, this is used to delete the relationship between this course and this particular semester.
# File lib/d2l_sdk/semester.rb, line 66 def remove_course_from_semester(course_id, semester_id) delete_relationship_of_child_with_parent(semester_id, course_id) end
REVIEW: Remove the current user’s profile image.
# File lib/d2l_sdk/user.rb, line 405 def remove_current_user_profile_image path = "/d2l/api/lp/#{$lp_ver}/profile/myProfile/image" _delete(path) end
REVIEW: Remove a particular file attachment from an entity’s feedback entry within a specified dropbox folder.
> DELETE /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}/attachments/#{file_id}¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 170 def remove_feedback_entry_file_attachment(org_unit_id, folder_id, entity_type, entity_id, file_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}/feedback/#{entity_type}/#{entity_id}/attachments/#{file_id}" _delete(path) end
REVIEW: Remove the profile image from a particular personal profile, by Profile ID.
# File lib/d2l_sdk/user.rb, line 411 def remove_profile_image_by_profile_id(profile_id) path = "/d2l/api/lp/#{$lp_ver}/profile/#{profile_id}/image" _delete(path) end
REVIEW: Remove the profile image from a particular personal profile, by User ID.
# File lib/d2l_sdk/user.rb, line 417 def remove_profile_image_by_user_id(user_id) path = "/d2l/api/lp/#{$lp_ver}/profile/user/#{user_id}/image" _delete(path) end
Remove a particular user from a group.
# File lib/d2l_sdk/group.rb, line 20 def remove_user_from_group(org_unit_id, group_category_id, group_id, user_id) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}/groups/#{group_id}/enrollments/#{user_id}" _delete(path) end
REVIEW: Remove a user’s exemption from a grade. RETURNS: nil
# File lib/d2l_sdk/grades.rb, line 465 def remove_user_grade_exemption(org_unit_id, grade_object_id, user_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/grades/#{grade_object_id}/exemptions/#{user_id}" _delete(path) # RETURNS: nil end
REVIEW: Reset a particular user’s password. INPUT: nil (no payload necessary) NOTE: Prompts the service to send a password-reset email to the provided user.
# File lib/d2l_sdk/user.rb, line 351 def reset_user_password(user_id) path = "/d2l/api/lp/#{$lp_ver}/users/#{user_id}/password" _post(path, {}) end
NOTE: UNSTABLE!!! TODO: UNSTABLE!!! –Restore the default resolution strategy for an org unit configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 132 def restore_default_org_unit_config_var_resolution(variable_id); end
NOTE: UNSTABLE!!! REVIEW: Restore a particular news item by its news_item_id
# File lib/d2l_sdk/news.rb, line 94 def restore_news_item(org_unit_id, news_item_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/deleted/#{news_item_id}/restore" _post(path, {}) end
Restores a recycled org unit. This is done by referencing the org unit by its id in the recycling bin and then appending '/restore'. This is then used in a post method that performs the restoring process.
# File lib/d2l_sdk/org_unit.rb, line 328 def restore_recycled_org_unit(org_unit_id) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}/restore" _post(path, {}) end
REVIEW: Set a new org value for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 93 def set_config_var_org_value(variable_id, org_value) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/org" raise(ArgumentError, "Argument 'org_value' is not a String or nil") unless org_value.is_a?(String) || org_value.nil? payload = { 'OrgValue' => org_value } _put(path, payload) end
REVIEW: Set a new org unit override value for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 101 def set_config_var_override_value(variable_id, org_unit_id, org_unit_value) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/orgUnits/#{org_unit_id}" raise(ArgumentError, "Argument 'org_unit_value' is not a String or nil") unless org_unit_value.is_a?(String) || org_unit_value.nil? payload = { 'OrgUnitValue' => org_unit_value } _put(path, payload) end
REVIEW: Set a new role override value for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 109 def set_config_var_role_value(variable_id, role_id, role_value) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/roles/#{role_id}" raise(ArgumentError, "Argument 'role_value' is not a String or nil") unless role_value.is_a? String || role_value.nil? payload = { 'RoleValue' => role_value } _put(path, payload) end
REVIEW: Set a new system value for a configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 117 def set_config_var_system_value(variable_id, system_value) path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/system" raise(ArgumentError, "Argument 'system_value' is not a String or nil") unless system_value.is_a?(String) || system_value.nil? payload = { 'SystemValue' => system_value } _put(path, payload) end
Subscribe to notification messages of a particular type, delivered by a particular carrier.
# File lib/d2l_sdk/user.rb, line 333 def subscribe_to_carrier_notification(carrier_id, message_type_id) path = "/d2l/api/lp/#{$lp_ver}/notifications/instant/carriers/#{carrier_id}/subscriptions/#{message_type_id}" _put(path, {}) end
REVIEW: Restore (unhide) a news item for an org unit.
# File lib/d2l_sdk/news.rb, line 120 def unhide_news_item(org_unit_id, news_item_id) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/restore" _post(path, {}) end
Unzip the file, applying a regex filter to the CSV if the file is Enrollments data.
# File lib/d2l_sdk/datahub.rb, line 139 def unzip(file_path, csv_filter = //) puts "Unzipping file: #{file_path}" # Unzip the file Zip::File.open(file_path) do |zip_file| # for each file in the zip file zip_file.each do |f| # create file path of export_jobs/#{f.name} f_path = File.join("export_jobs", f.name) # make the directory if not already made FileUtils.mkdir_p(File.dirname(f_path)) # extract the file unless the file already exists zip_file.extract(f, f_path) unless File.exist?(f_path) # if the file is CSV and Enrollments, apply filters and proper # CSV formatting to the file, writing it as base f.name + filtered.csv if (f.name.include? ".csv") && (f.name.include? "Enrollments") filter_formatted_enrollments("export_jobs/#{f.name}", csv_filter, "export_jobs/instr.csv") end end end end
REVIEW: Update a tool’s current status for all org units.
> PUT /d2l/api/lp/(version)/tools/org/(toolId)/OUDefault/override¶ ↑
# File lib/d2l_sdk/config_variables.rb, line 210 def update_all_org_unit_tool_status(tool_id, update_status) path = "/d2l/api/lp/#{$lp_ver}/tools/org/#{tool_id}/OUDefault/override" payload = check_and_create_update_status_payload(update_status) _put(path, payload) end
TODO: Update an existing course completion. RETURNS: a CourseCompletion JSON block with the newly created course completion record.
# File lib/d2l_sdk/grades.rb, line 392 def update_course_completion(org_unit_id, completion_id, course_completion_data) # CourseCompletionUpdateData JSON data block example: # {"CompletedDate" => "UTCDateTime", # "ExpiryDate" => "UTCDateTime" || nil} # PUT /d2l/api/le/(version)/(orgUnitId)/grades/courseCompletion/(completionId) end
Update the course based upon the first argument. This course object is first referenced via the first argument and its data formatted via merging it with a predefined payload. Then, a PUT http method is executed using the new payload. Utilize the second argument and perform a PUT action to replace the old data
# File lib/d2l_sdk/course.rb, line 128 def update_course_data(course_id, new_data) # Define a valid, empty payload and merge! with the new data. payload = { 'Name' => '', # String 'Code' => 'off_SEMESTERCODE_STARNUM', # String 'StartDate' => nil, # String: UTCDateTime | nil 'EndDate' => nil, # String: UTCDateTime | nil 'IsActive' => false # bool }.merge!(new_data) check_updated_course_data_validity(payload) # ap payload # Define a path referencing the courses path path = "/d2l/api/lp/#{$lp_ver}/courses/" + course_id.to_s _put(path, payload) # requires: CourseOfferingInfo JSON block puts '[+] Course update completed successfully'.green # Define a path referencing the course data using the course_id # Perform the put action that replaces the old data # Provide feedback that the update was successful end
REVIEW: Update the course image for a course offering.
# File lib/d2l_sdk/course.rb, line 150 def update_course_image(org_unit_id, image_file_path) path = "/d2l/api/lp/#{$lp_ver}/courses/#{org_unit_id}/image" # (SCHEMA) Make sure file isnt > 2MB raise ArgumentError, "File referrenced by 'image_file_path' must be less than 1000KB." if File.size(image_file_path) > 2_000_000 raise ArgumentError, "File referrenced by 'image_file_path' is not a valid image." if MIME::Types.type_for(image_file_path).first.media_type.downcase.casecmp("image").zero? _image_upload(path, image_file_path, "PUT") # PUT /d2l/api/lp/(version)/courses/(orgUnitId)/image end
This is the primary method utilized to update course templates. As only the Name and the Code can be changed in an update, they are pre-defined to conform to the required update data. The update is then performed via a PUT http method that is executed using a path referencing the course template. /d2l/api/lp/(version)/coursetemplates/(orgUnitId) [PUT]
# File lib/d2l_sdk/course_template.rb, line 114 def update_course_template(org_unit_id, new_data) # Define a valid, empty payload and merge! with the new data. payload = { 'Name' => '', # String 'Code' => 'off_SEMESTERCODE_STARNUM', # String }.merge!(new_data) puts "Updating course template #{org_unit_id}" check_course_template_updated_data_validity(payload) # ap payload # requires: CourseTemplateInfo JSON block # Define a path referencing the courses path path = "/d2l/api/lp/#{$lp_ver}/coursetemplates/" + org_unit_id.to_s _put(path, payload) puts '[+] Course template update completed successfully'.green end
REVIEW: Update the current user’s locale account settings. update_locale = { “LocaleId” : <D2LID>}
# File lib/d2l_sdk/user.rb, line 641 def update_current_user_locale_account_settings(locale_id) unless valid_locale_id?(locale_id) raise ArgumentError, "Variable 'update_locale' is not a " end payload = { 'LocaleId' => locale_id } path = "/d2l/api/lp/#{$lp_ver}/accountSettings/mysettings/locale/" # requires UpdateSettings JSON data block # update_locale = { "LocaleId" : <D2LID>} _put(path, payload) end
TODO: Update the personal profile data for the current user context. NOTE: block's data will replace all user profile data RETURNS: a UserProfile JSON data block for the updated current user profile.
# File lib/d2l_sdk/user.rb, line 520 def update_current_user_profile_data(user_profile_data) # PUT /d2l/api/lp/(version)/profile/myProfile end
TODO: Update the personal profile image for the current user context. INPUT: Provide an uploaded image file using the simple file upload process;
the content-disposition part header for the file part should have the name profileImage http://docs.valence.desire2learn.com/basic/fileupload.html#simple-uploads
RETURNS: ?
# File lib/d2l_sdk/user.rb, line 490 def update_current_user_profile_image() # POST /d2l/api/lp/(version)/profile/myProfile/image # RETURNS: ? end
REVIEW: Update a single demographic field. Input: DemographicsField (Demographics.Demographicsfield) RETURNS: fetch form of a DemographicsField JSON block
# File lib/d2l_sdk/demographics.rb, line 198 def update_demographics_field(field_id, demographics_field) # PUT /d2l/api/lp/(version)/demographics/fields/(fieldId) path = "/d2l/api/lp/#{$lp_ver}/demographics/fields/#{field_id}" payload = { "Name" => "String", "Description" => "String", "DataTypeId" => "String:GUID" }.merge!(demographics_field) check_update_demographics_field(payload) _put(path, payload) # RETURNS: fetch form of a DemographicsField JSON block end
REVIEW: Update a particular dropbox folder in an org unit.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}¶ ↑
# File lib/d2l_sdk/dropbox.rb, line 93 def update_dropbox_folder(org_unit_id, dropbox_folder_update_data) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}" payload = { "CategoryId" => nil, # or a number "Name" => "string", "CustomInstructions" => { "Content" => "string", "Text" => "Text|HTML" }, "Availability" => { "StartDate" => "string or nil", # or nil "EndDate" => "string or nil" # or nil }, "GroupTypeId" => nil, # or a number "DueDate" => nil, "DisplayInCalendar" => false, "NotificationEmail" => nil # or a string --- Added in LE v1.21 }.merge!(dropbox_folder_update_data) check_dropbox_folder_update_data_validity(payload) _put(path, payload) # RETURNS: DropboxFolder JSON block end
REVIEW: Update the information for a specific dropbox folder category.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/categories/#{category_id}¶ ↑
INPUT: DropboxCategory JSON data block. RETURNS: a single DropboxCategory block.
# File lib/d2l_sdk/dropbox.rb, line 299 def update_dropbox_folder_category(org_unit_id, category_id, dropbox_category_id, dropbox_category_name) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/categories/#{category_id}" # Check that the values conform to the JSON schema. if !dropbox_category_id.is_a? Numeric raise ArgumentError, "Argument 'dropbox_category_id' with value #{dropbox_category_id} is not an integer value." elsif !dropbox_category_name.is_a? String raise ArgumentError, "Argument 'dropbox_category_name' with value #{dropbox_category_name} is not a String value." end payload = { 'Id' => dropbox_category_id, 'Name' => dropbox_category_name } _put(path, payload) end
REVIEW: Create Schema checker; Check that this payload conforms to it. Update the properties for a calendar event from a particular org unit. INPUT: Calendar.EventData RETURNS:a EventDataInfo data block for the newly updated event.
# File lib/d2l_sdk/calendar.rb, line 235 def update_event(org_unit_id, event_id, event_data) # PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id} path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}" payload = { # Calendar.EventDataInfo "Title" => "", "Description" => "", "StartDateTime" => nil, # UTCDateTime || nil "EndDateTime" => nil, # UTCDateTime || nil "StartDay" => nil, # LocalDateTime || nil "EndDay" => nil, # LocalDateTime || nil "GroupId" => nil, # D2LID || nil "RecurrenceInfo" => # Calendar.RecurrenceInfo { "RepeatType" => 0, # number -- repeat type "RepeatEvery" => 0, # number "RepeatOnInfo" => # Calendar.RepeatOnInfo { "Monday" => false, # boolean "Tuesday" => false, # boolean "Wednesday" => false, # boolean "Thursday" => false, # boolean "Friday" => false, # boolean "Saturday" => false, # boolean "Sunday" => false, # boolean }, "RepeatUntilDate" => "" # UTCDATETIME }, "HasVisibilityRestrictions" => false, "VisibilityRestrictions" => # Calendar.VisibilityInfo { "Type" => 0, # <number:VISIBILITY_T>, "Range" => nil, # <number>|null, "HiddenRangeUnitType" => nil, # <number:HIDDENUNIT_T>|null, "StartDate" => nil, # <string:UTCDateTime>|null, "EndDate" => nil # <string:UTCDateTime>|null, }, "CalendarEventViewUrl" => "" # String:URL }.merge!(event_data) check_calendar_event_data_validity(payload) # NOTE: Test later _put(path, payload) end
REVIEW: Update a forum for an org unit.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}¶ ↑
NOTE: < LE v 1.10 ignores date filed of the forum_data NOTE: >= LE v 1.11 applies date fields that are sent, otherwise they're
assumed null.
# File lib/d2l_sdk/discussions.rb, line 97 def update_forum(org_unit_id, forum_id, forum_data) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/" payload = { 'Name' => '', #: <string>, 'Description' => #: { <composite:RichText> }, { "Text" => "", # <string:plaintext_version_of_text>, "Html" => nil # <string:HTML_formatted_version_of_text>|null }, 'ShowDescriptionInTopics' => nil, #: <boolean>|null, // Added with LE API v1.14 'StartDate' => nil, #: <string:UTCDateTime>|null, 'EndDate' => nil, #: <string:UTCDateTime>|null, 'PostStartDate' => nil, #: <string:UTCDateTime>|null, 'PostEndDate' => nil, # <string:UTCDateTime>|null, 'AllowAnonymous' => false, # <boolean>, 'IsLocked' => false, #: <boolean>, 'IsHidden' => false, #: <boolean>, 'RequiresApproval' => '', #: <boolean>, 'MustPostToParticipate' => nil, #: <boolean>|null, 'DisplayInCalendar' => nil, #: <boolean>|null, // Added with LE API v1.11 'DisplayPostDatesInCalendar' => nil, #: <boolean>|null // Added with LE API v1.11 }.merge!(forum_data) # REVIEW: Validate payload check_forum_data_validity(payload) _put(path, payload) # RETURNS: Forum JSON block end
REVIEW: Update an existing topic for the provided discussion forum in an org unit.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}¶ ↑
# File lib/d2l_sdk/discussions.rb, line 242 def update_forum_topic(org_unit_id, forum_id, topic_id, create_topic_data) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}" payload = { "Name" => "", # : <string>, "Description" => { "Text" => "", # <string:plaintext_version_of_text>, "Html" => nil # <string:HTML_formatted_version_of_text>|null }, # { <composite:RichTextInput> }, "AllowAnonymousPosts" => false, # <boolean>, "StartDate" => nil, # <string:UTCDateTime>|null, "EndDate" => nil, # : <string:UTCDateTime>|null, "IsHidden" => false, # : <boolean>, "UnlockStartDate" => nil, # : <string:UTCDateTime>|null, "UnlockEndDate" => nil, # : <string:UTCDateTime>|null, "RequiresApproval" => false, # : <boolean>, "ScoreOutOf" => nil, # : <number>|null, "IsAutoScore" => false, # : <boolean>, "IncludeNonScoredValues" => "", # : <boolean>, "ScoringType" => nil, # : <string:SCORING_T>|null, "IsLocked" => false, # : <boolean>, "MustPostToParticipate" => false, # : <boolean>, "RatingType" => nil, # : <string:RATING_T>|null, "DisplayInCalendar" => nil, # : <boolean>|null, // Added with LE API v1.12 "DisplayUnlockDatesInCalendar" => nil, # : <boolean>|null // Added with LE API v1.12 }.merge!(create_topic_data) check_create_topic_data_validity(payload) # REVIEW: Validity check of topic data _post(path, payload) # RETURNS: Topic JSON data block end
REVIEW: Update the information associated with a registered LTI link.
> PUT /d2l/api/le/(version)/lti/link/(ltiLinkId)¶ ↑
# File lib/d2l_sdk/lti.rb, line 119 def update_lti_link(lti_link_id, create_lti_link_data) path = "/d2l/api/le/#{$le_ver}/lti/link/#{lti_link_id}" payload = { 'Title' => '', 'Url' => '', 'Description' => '', 'Key' => '', 'PlainSecret' => '', 'IsVisible' => false, 'SignMessage' => false, 'SignWithTc' => false, 'SendTcInfo' => false, 'SendContextInfo' => false, 'SendUserId' => false, 'SendUserName' => false, 'SendUserEmail' => false, 'SendLinkTitle' => false, 'SendLinkDescription' => false, 'SendD2LUserName' => false, 'SendD2LOrgDefinedId' => false, 'SendD2LOrgRoleId' => false, 'UseToolProviderSecuritySettings' => false, 'CustomParameters' => nil # or Array of CustomParameter # e.g. [{"Name" => "", "Value" => ""},{"Name" => "", "Value" => ""}] }.merge!(create_lti_link_data) check_create_lti_link_data_validity(payload) _put(path, payload) end
REVIEW: Update the information associated with a registered LTI tool provider.
> PUT /d2l/api/le/(version)/lti/tp/(tpId)¶ ↑
INPUT: LTI.CreateLtiProviderData
# File lib/d2l_sdk/lti.rb, line 241 def update_lti_tool_provider(tp_id, create_lti_provider_data) path = "/d2l/api/le/#{$le_ver}/lti/tp/#{tp_id}" # tp_id = tool provider id payload = { 'LaunchPoint' => '', 'Secret' => '', 'UseDefaultTcInfo' => '', 'Key' => '', 'Name' => '', 'Description' => '', 'ContactEmail' => '', 'IsVisible' => false, 'SendTcInfo' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendContextInfo' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendUserId' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendUserName' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendUserEmail' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendLinkTitle' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendLinkDescription' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendD2LUserName' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendD2LOrgDefinedId' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0 'SendD2LOrgRoleId' => false # Appears in LE's 1.12+ contract as of LE v10.6.0 }.merge!(create_lti_provider_data) check_create_lti_provider_data_validity(payload) _put(path, payload) # RETURNS: a LtiToolProviderData JSON block end
Update a particular module for an org unit. INPUT: ContentObjectData of type Module NOTE: Cannot use this action to affect a module’s existing Structure property.
# File lib/d2l_sdk/course_content.rb, line 206 def update_module(org_unit_id, module_id, content_module) # PUT query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/modules/#{module_id}" payload = { "Title" => "", "ShortTitle" => "", "Type" => 0, "ModuleStartDate" => nil, # <string:UTCDateTime>|null "ModuleEndDate" => nil, # <string:UTCDateTime>|null "ModuleDueDate" => nil, # <string:UTCDateTime>|null "IsHidden" => false, "IsLocked" => false, "Description" => nil, # { <composite:RichTextInput> }|null --Added with LE v1.10 API "Duration" => nil # <number>|null --Added in LE's +unstable+ contract as of LE v10.6.8 }.merge!(content_module) check_content_module_validity(payload) _put(query_string, payload) end
TODO: Update a news item for an org unit. INPUT: JSON Parameter of type NewsItemData (News.NewsItemData)
# File lib/d2l_sdk/news.rb, line 127 def update_news_item(org_unit_id, news_item_id, news_item_data) # Example of News.NewsItemData JSON Data Block: # {"Title" => "string", # "Body" => {'Content' => "content", "Type" => "type"} # RichTextInput -- e.g. {'Content'=>'x', 'Type'=>'y'} # "StartDate": "<string:UTCDateTime>", # "EndDate": "<string:UTCDateTime>", # or nil # "IsGlobal": false, # "IsPublished": false, # "ShowOnlyInCourseOfferings": false} # PUT /d2l/api/le/(version)/(orgUnitId)/news/(newsItemId) end
REVIEW: Update the organization-level status for a tool.
> PUT /d2l/api/lp/(version)/tools/org/(toolId)¶ ↑
# File lib/d2l_sdk/config_variables.rb, line 194 def update_org_tool_status(tool_id, update_status) path = "/d2l/api/lp/#{$lp_ver}/tools/org/#{tool_id}" payload = check_and_create_update_status_payload(update_status) _put(path, payload) end
# File lib/d2l_sdk/org_unit.rb, line 248 def update_org_unit(org_unit_id, org_unit_data) previous_data = get_org_unit_properties(org_unit_id) payload = { # Can only update NAME, CODE, and PATH variables 'Identifier' => org_unit_id.to_s, # String: D2LID // DO NOT CHANGE 'Name' => previous_data['Name'], # String # String #YearNUM where NUM{sp:01,su:06,fl:08} | nil 'Code' => previous_data['Code'], # String: /content/enforced/IDENTIFIER-CODE/ 'Path' => "/content/enforced/#{org_unit_id}-#{previous_data['Code']}/", 'Type' => previous_data['Type'] # example: # { # DO NOT CHANGE THESE # 'Id' => 5, # <number:D2LID> # 'Code' => 'Semester', # <string> # 'Name' => 'Semester', # <string> # } }.merge!(org_unit_data) check_org_unit_updated_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}" puts '[-] Attempting put request (updating orgunit)...' # requires: OrgUnitProperties JSON block _put(path, payload) puts '[+] Semester update completed successfully'.green # returns: OrgUnitProperties JSON data block end
TODO: –UNSTABLE– Update an assessment in an org unit. RETURNS: value of the assessment in a RubricAssessment JSON structure.
# File lib/d2l_sdk/grades.rb, line 519 def update_org_unit_assessment(org_unit_id, assessment_type, object_type, object_id, user_id) # PUT /d2l/api/le/(version)/(orgUnitId)/assessment # RETURNS: value of the assessment in a RubricAssessment JSON structure. end
NOTE: UNSTABLE!!! TODO: UNSTABLE!!! –Update the resolution strategy for an org unit configuration variable.
# File lib/d2l_sdk/config_variables.rb, line 145 def update_org_unit_config_var_resolution(resolver_value); end
TODO: Update the grades configuration for the org unit. INPUT: a GradeSetupInfo JSON block. (grade_setup_info) RETURNS: a GradeSetupInfo JSON block.
# File lib/d2l_sdk/grades.rb, line 426 def update_org_unit_grade_config(org_unit_id, grade_setup_info) # Grade.GradeSetupInfo JSON data block example: # {"GradingSystem" => "Points", # Other types: "Weighted", "Formula" # "IsNullGradeZero" => false, # "DefaultGradeSchemeId" => 0} # PUT /d2l/api/le/(version)/(orgUnitId)/grades/setup/ # RETURNS: a GradeSetupInfo JSON block. end
Update a particular group for an org unit
# File lib/d2l_sdk/group.rb, line 159 def update_org_unit_group(org_unit_id, group_category_id, group_id, group_data) payload = { "Name" => "string", "Code" => "string", "Description" => {} }.merge!(group_data) # Requires: JSON block of GroupData validate_group_data(payload) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}/groups/#{group_id}" # returns a GroupData JSON block, in the Fetch form, of the updated group. _put(path, payload) end
update a particular group category for an org unit
# File lib/d2l_sdk/group.rb, line 215 def update_org_unit_group_category(org_unit_id, group_category_id, group_category_data) payload = { 'Name' => '', # String 'Description' => {}, # RichTextInput 'AutoEnroll' => false, # bool 'RandomizeEnrollments' => false, # bool }.merge!(group_category_data) # Requires: JSON block of GroupCategoryData validate_update_group_category_data(payload) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}" _put(path, payload) # Returns a GroupCategoryData JSON block, in the Fetch form, of updated grp. cat. end
REVIEW: Update the org unit-level information for a tool. INPUT: OrgUnitInformation JSON block
> PUT /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)/(toolId)¶ ↑
# File lib/d2l_sdk/config_variables.rb, line 253 def update_org_unit_level_tool_info(org_unit_id, tool_id, org_unit_information) path = "/d2l/api/lp/#{$lp_ver}/tools/orgUnits/#{org_unit_id}/#{tool_id}" payload = { 'ToolId' => '', # <string:D2LID> 'DisplayName' => '', # <string> ## added with LP v1.6 API 'OrgUnitId' => 0, # D2LID:number 'Status' => false, # boolean 'CustomNavbarName' => '' # <string> }.merge!(org_unit_information) check_org_unit_information_validity(payload) # NOTE: Check this later. _put(path, payload) end
Update information for a section in a particular org unit.
# File lib/d2l_sdk/section.rb, line 145 def update_org_unit_section_info(org_unit_id, section_id, section_data) payload = { 'Name' => '', # String 'Code' => '', # String 'Description' => {}, # RichTextInput -- e.g. {'Content'=>'x', 'Type'=>'y'} }.merge!(section_data) # Check the validity of the SectionData that is passed as a payload check_section_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/#{section_id}" # JSON param: SectionData _put(path, payload) # returns the SectionData JSON block, in its Fetch form end
Update the section properties for an org unit.
# File lib/d2l_sdk/section.rb, line 128 def update_org_unit_section_properties(org_unit_id, section_property_data) payload = { 'EnrollmentStyle' => 0, 'EnrollmentQuantity' => 0, 'AutoEnroll' => false, 'RandomizeEnrollments' => false }.merge!(section_property_data) # Check the validity of the SectionPropertyData that is passed as a payload check_section_property_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/sections/settings" # JSON param: SectionPropertyData _put(path, payload) # returns the SectionPropertyData JSON block, in its Fetch form, # for the org unit’s updated section properties. end
NOTE: You cannot update the org unit codes if they are default ouTypes update a particular org unit type (with POST for some reason)
# File lib/d2l_sdk/org_unit.rb, line 402 def update_outype(outype_id, create_org_unit_type_data) payload = { 'Code' => '', 'Name' => '', 'Description' => '', 'SortOrder' => 0 }.merge!(create_org_unit_type_data) # validate schema check_create_org_unit_type_data_validity(payload) path = "/d2l/api/lp/#{$lp_ver}/outypes/#{outype_id}" _post(path, payload) # returns OrgUnitType JSON data block end
TODO: Update a particular personal profile, by Profile ID. NOTE: block's data will replace all user profile data RETURNS: a UserProfile JSON data block for the updated personal profile.
# File lib/d2l_sdk/user.rb, line 527 def update_profile_by_profile_id(profile_id, user_profile_data) # PUT /d2l/api/lp/(version)/profile/(profileId) # NOTE: Example of User.UserProfile JSON Data Block # { "Nickname": <string>, # "Birthday": { # "Month": <number>, # "Day": <number> # }, # "HomeTown": <string>, # "Email": <string>, # "HomePage": <string>, # "HomePhone": <string>, # "BusinessPhone": <string>, # "MobilePhone": <string>, # "FaxNumber": <string>, # "Address1": <string>, # "Address2": <string>, # "City": <string>, # "Province": <string>, # "PostalCode": <string>, # "Country": <string>, # "Company": <string>, # "JobTitle": <string>, # "HighSchool": <string>, # "University": <string>, # "Hobbies": <string>, # "FavMusic": <string>, # "FavTVShows": <string>, # "FavMovies": <string>, # "FavBooks": <string>, # "FavQuotations": <string>, # "FavWebSites": <string>, # "FutureGoals": <string>, # "FavMemory": <string>, # "SocialMediaUrls": [ // Array of SocialMediaUrl blocks # { # "Name": <string>, # "Url": <string:URL> # }, # { <composite:SocialMediaUrl> }, ... # ] # } # NOTE: The back-end service also expects a file names "profileImage" # RETURNS: a UserProfile JSON data block for the updated personal profile. end
TODO: Update the profile image for the identified personal profile, by Profile ID. INPUT: Provide an uploaded image file using the simple file upload process;
the content-disposition part header for the file part should have the name profileImage http://docs.valence.desire2learn.com/basic/fileupload.html#simple-uploads
RETURNS: ?
# File lib/d2l_sdk/user.rb, line 501 def update_profile_image_by_profile_id # POST /d2l/api/lp/(version)/profile/(profileId)/image # RETURNS: ? end
TODO: Update the profile image for the identified personal profile, by User ID. INPUT: Provide an uploaded image file using the simple file upload process;
the content-disposition part header for the file part should have the name profileImage http://docs.valence.desire2learn.com/basic/fileupload.html#simple-uploads
RETURNS: ?
# File lib/d2l_sdk/user.rb, line 512 def update_profile_image_by_user_id # POST /d2l/api/lp/(version)/profile/user/(userId)/image # RETURNS: ? end
Updates a semester's data via merging a preformatted payload with the new semester data. The 'path' is then initialized using a defined org_unit_id and the semester is then updated via the newly defined payload and the path.
# File lib/d2l_sdk/semester.rb, line 115 def update_semester_data(org_unit_id, semester_data) # Define a valid, empty payload and merge! with the semester_data. Print it. payload = { # Can only update NAME, CODE, and PATH variables 'Identifier' => org_unit_id.to_s, # String: D2LID // DO NOT CHANGE 'Name' => 'NAME', # String # String #YearNUM where NUM{sp:01,su:06,fl:08} | nil 'Code' => 'REQUIRED', # String: /content/enforced/IDENTIFIER-CODE/ 'Path' => create_semester_formatted_path(org_unit_id.to_s, 'YEAR01'), 'Type' => { # DO NOT CHANGE THESE 'Id' => 5, # <number:D2LID> 'Code' => 'Semester', # <string> 'Name' => 'Semester', # <string> } }.merge!(semester_data) check_semester_updated_data_validity(payload) # print out the projected new data # puts '[-] New Semester Data:'.yellow # ap payload # Define a path referencing the course data using the course_id path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}" puts '[-] Attempting put request (updating orgunit)...' _put(path, payload) puts '[+] Semester update completed successfully'.green end
REVIEW: Update a tool’s default status for new org units.
> PUT /d2l/api/lp/(version)/tools/org/(toolId)/OUDefault¶ ↑
# File lib/d2l_sdk/config_variables.rb, line 202 def update_tool_default_status(tool_id, update_status) path = "/d2l/api/lp/#{$lp_ver}/tools/org/#{tool_id}/OUDefault" payload = check_and_create_update_status_payload(update_status) _put(path, payload) end
Update a particular topic for an org unit. INPUT: ContentObjectData of type Topic Returns underlying file for a file content topic
# File lib/d2l_sdk/course_content.rb, line 227 def update_topic(org_unit_id, topic_id, content_topic) # GET query_string = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/topics/#{topic_id}" payload = { 'Title' => "", 'ShortTitle' => "", 'Type' => 0, 'TopicType' => 0, 'StartDate' => nil, 'EndDate' => nil, 'DueDate' => nil, 'IsHidden' => nil, 'IsLocked' => false, 'OpenAsExternalResource' => nil, # Added with LE v1.6 API 'Description' => nil, 'MajorUpdate' => nil, # Added with LE v1.12 API 'MajorUpdateText' => "", # Added with LE v1.12 API 'ResetCompletionTracking' => nil # Added with LE v1.12 API }.merge!(content_topic) check_content_topic_validity(content_topic) _put(query_string, payload) end
REVIEW: Update a particular post in a discussion forum topic.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}¶ ↑
RETURNS: Post JSON data block
# File lib/d2l_sdk/discussions.rb, line 437 def update_topic_post(org_unit_id, forum_id, topic_id, post_id, create_post_data) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}" payload = { "ParentPostId" => nil, # integer or nil "Subject" => "", "Message" => { "Content" => "", "Type" => "Text|Html" }, "IsAnonymous" => false }.merge!(create_post_data) check_create_post_data_validity(payload) _put(path, payload) end
REVIEW: Update the approval status of a particular post in a discussion forum topic.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Approval¶ ↑
RETURNS: ApprovalData JSON data block
# File lib/d2l_sdk/discussions.rb, line 455 def update_topic_post_approval_status(org_unit_id, forum_id, topic_id, post_id, is_approved) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Approval" raise ArgumentError, "Argument 'is_approved' is not a boolean value." unless is_approved == true || is_approved == false payload = { "IsApproved" => is_approved } _put(path, payload) end
REVIEW: Update the current user context’s rating for a particular post in a discussion forum topic.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Rating/MyRating¶ ↑
RETURNS: UserRatingData JSON data block
# File lib/d2l_sdk/discussions.rb, line 476 def update_topic_post_current_user_rating(org_unit_id, forum_id, topic_id, post_id, rating) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Rating/MyRating" raise ArgumentError, "Argument 'rating' is not a number or null value." unless rating.is_a?(Numeric) || rating.nil? payload = { "Rating" => rating } _put(path, payload) end
REVIEW: Update a discussion forum topic post’s vote data for the current user.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Votes/MyVote¶ ↑
RETURNS: ??
# File lib/d2l_sdk/discussions.rb, line 496 def update_topic_post_current_user_vote_data(org_unit_id, forum_id, topic_id, post_id, vote) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Votes/MyVote" unless vote.is_a? String raise ArgumentError, "Argument 'vote' is not a string value." else payload = { "Vote" => vote } _put(path, payload) end end
REVIEW: Update the flagged status of a particular post in a discussion forum topic.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Flag¶ ↑
RETURNS: FlagData JSON data block
# File lib/d2l_sdk/discussions.rb, line 466 def update_topic_post_flagged_status(org_unit_id, forum_id, topic_id, post_id, is_flagged) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/Flag" raise ArgumentError, "Argument 'is_flagged' is not a boolean value." unless is_flagged == true || is_flagged == false payload = { "IsFlagged" => is_flagged } _put(path, payload) end
REVIEW: Update the read status of a particular post in a discussion forum topic.
> PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/ReadStatus¶ ↑
RETURNS: ReadStatusData JSON data block
# File lib/d2l_sdk/discussions.rb, line 486 def update_topic_post_read_status(org_unit_id, forum_id, topic_id, post_id, is_read) path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}/posts/#{post_id}/ReadStatus" raise ArgumentError, "Argument 'is_read' is not a boolean value." unless is_read == true || is_read == false payload = { "IsRead" => is_read } _put(path, payload) end
REVIEW: Update a particular user’s activation settings. RETURNS: ?
# File lib/d2l_sdk/user.rb, line 284 def update_user_activation_settings(user_id, is_active) # PUT /d2l/api/lp/(version)/users/(userId)/activation raise ArgumentError, 'is_active is not a boolean' if is_active != true && is_active != false path = "/d2l/api/lp/#{$lp_ver}/users/#{user_id}/activation" payload = { "IsActive" => is_active } _put(path, payload) # RETURNS: ? end
Updates the user's data (identified by user_id) By merging input, named new_data, with a payload, the user_data is guarenteed to at least be formatted correctly. The data, itself, depends upon the api user. Once this is merged, a put http method is utilized to update the user data.
# File lib/d2l_sdk/user.rb, line 239 def update_user_data(user_id, new_data) # Define a valid, empty payload and merge! with the user_data. Print it. payload = { 'OrgDefinedId' => '', 'FirstName' => '', 'MiddleName' => '', 'LastName' => '', 'ExternalEmail' => nil, # Predefines user data, in the case that 'UserName' => '', # there is are variables left out in the JSON 'Activation' => { 'IsActive' => false } }.merge!(new_data) # Requires: UpdateUserData JSON block check_updated_user_data_validity(payload) # Define a path referencing the user data using the user_id path = "/d2l/api/lp/#{$lp_ver}/users/" + user_id.to_s _put(path, payload) # puts '[+] User data updated successfully'.green # Returns a UserData JSON block of the updated user's data end
REVIEW: Update the demographics entries for a single user. Return: a DemographicsUserEntryData JSON block containing the user’s updated entries.
# File lib/d2l_sdk/demographics.rb, line 108 def update_user_demographics(user_id, demographics_entry_data) payload = { "EntryValues" => [ { "Name" => "placeholder_name", "Values" => %w(value1 value2) } ] }.merge!(demographics_entry_data) # PUT /d2l/api/lp/(version)/demographics/users/(userId) path = "/d2l/api/lp/#{$lp_ver}/demographics/users/#{user_id}" check_demographics_user_entry_data_validity(payload) _put(path, payload) end
REVIEW: Update the locale account settings for a particular user. update_locale = { “LocaleId” : <D2LID>}
# File lib/d2l_sdk/user.rb, line 655 def update_user_locale_account_settings(user_id, locale_id) unless valid_locale_id?(locale_id) raise ArgumentError, "Variable 'update_locale' is not a " end payload = { 'LocaleId' => locale_id } path = "/d2l/api/lp/#{$lp_ver}/accountSettings/#{user_id}/locale/" # requires UpdateSettings JSON data block # update_locale = { "LocaleId" : <D2LID>} _put(path, payload) end
REVIEW: Update a particular user’s password. NOTE: 400 errors are implicitly invalid password
# File lib/d2l_sdk/user.rb, line 358 def update_user_password(user_id, user_password_data) raise ArgumentError, "Argument 'user_password_data' is not a String" unless user_password_data.is_a? String path = "/d2l/api/lp/#{$lp_ver}/users/#{user_id}/password" payload = { "Password" => user_password_data } _put(path, payload) end
TODO: –UNSTABLE– Update a user progress item. _post “/d2l/api/le/#{$le_ver}/#{org_unit_id}/content/userprogress/” payload: UserProgressData
# File lib/d2l_sdk/course_content.rb, line 558 def update_user_progress; end
Add schema check for update_locale conforming to the D2L update_locale JSON data block of form: { “LocaleId” : <D2LID>}.
# File lib/d2l_sdk/user.rb, line 634 def valid_locale_id?(locale_id) # check if its an integer OR if its a string comprised of only numbers. locale_id.is_a?(Numeric) || locale_id.is_a?(String) && !!locale_id.match(/^(\d)+$/) end
assures that the CreateExportJobData JSON block is valid based off of a specified JSON schema. filter names: startDate, endDate, roles, and parentOrgUnitId — startDate and EndDate must be UTC dates — parentOrgUnitId and roles are integers corresponding to an ou_id & role_id
# File lib/d2l_sdk/datahub.rb, line 41 def validate_create_export_job_data(create_export_job_data) schema = { 'type' => 'object', # 'title'=>'the CreateExportJobData JSON block', 'required' => %w(DataSetId Filters), 'properties' => { 'DataSetId' => { 'type' => 'string' }, 'Filters' => { # define the filter array # 'description' => 'The array of filters for CreateExportJobData', 'type' => 'array', 'items' => { 'type' => "object", "properties" => { "Name" => { 'type' => "string" }, "Value" => { 'type' => "string" } } } } } } # ap schema JSON::Validator.validate!(schema, create_export_job_data, validate_schema: true) # returns true if the CreateExportJobData JSON block is valid end
# File lib/d2l_sdk/group.rb, line 52 def validate_create_group_category_data(group_category_data) schema = { 'type' => 'object', 'required' => %w(Name Description EnrollmentStyle EnrollmentQuality AutoEnroll RandomizeEnrollments NumberOfGroups MaxUsersPerGroup AllocateAfterExpiry SelfEnrollmentExpiryDate GroupPrefix), 'properties' => { 'Name' => { 'type' => 'string' }, 'Description' => { 'type' => 'object', 'properties' => { "Content" => "string", "Type" => "string" # "Text|HTML" } }, # RichTextInput # if set to SingleUserMemberSpecificGroup, values set for NumberOfGroups # and MaxUsersPerGroup are IGNORED # ---------------------------------- # GPRENROLL_T integer value meanings # 0 = NumberOfGrupsNoEnrollment ^ # 1 = PeoplePerGroupAutoEnrollment # 2 = NumerOfGroupsAutoEnrollment # 3 = PeoplePerGroupSelfEnrollment # 4 = SelfEnrollmentNumberOfGroups # 5 = PeoplePerNumberOfGroupsSelfEnrollment # ---------------------------------- 'EnrollmentStyle' => { 'type' => 'integer' }, # num GRPENROLL_T # if non-nil, values for NumberOfGroups and MaxUsersPerGroup are IGNORED 'EnrollmentQuantity' => { 'type' => %w(integer null) }, 'AutoEnroll' => { 'type' => 'boolean' }, 'RandomizeEnrollments' => { 'type' => 'boolean' }, 'NumberOfGroups' => { 'type' => %w(integer null) }, # nil, 0, 1, 3, 5 'MaxUsersPerGroup' => { 'type' => %w(integer null) }, # 1, 3, 5 # if MaxUsersPerGroup has a value, then set this to true. 'AllocateAfterExpiry' => { 'type' => 'boolean' }, 'SelfEnrollmentExpiryDate' => { 'type' => %w(string null) }, # UTCDATETIME # Prepends group prefix to GroupName and GroupCode 'GroupPrefix' => { 'type' => %w(string null) } } } JSON::Validator.validate!(schema, group_category_data, validate_schema: true) end
# File lib/d2l_sdk/group.rb, line 121 def validate_group_data(group_data) schema = { 'type' => 'object', 'required' => %w(Name Code Description), 'properties' => { 'Name' => { 'type' => 'string' }, "Code" => { 'type' => 'string' }, 'Description' => { 'type' => 'object', 'properties' => { "Content" => "string", "Type" => "string" # "Text|HTML" } } } } JSON::Validator.validate!(schema, group_data, validate_schema: true) end
# File lib/d2l_sdk/group.rb, line 172 def validate_group_enrollment_data(group_enrollment_data) schema = { 'type' => 'object', 'required' => %w(UserId), 'properties' => { 'UserId' => { 'type' => 'integer' } } }.merge!(group_enrollment_data) JSON::Validator.validate!(schema, course_data, validate_schema: true) end
# File lib/d2l_sdk/course_content.rb, line 303 def validate_isbn_association_data(isbn_association_data) schema = { 'type' => 'object', 'required' => %w(OrgUnitId Isbn), 'properties' => { 'OrgUnitId' => { 'type' => 'integer' }, 'Isbn' => { 'type' => 'string' }, 'IsRequired' => { 'type' => 'boolean' } } } JSON::Validator.validate!(schema, isbn_association_data, validate_schema: true) end
# File lib/d2l_sdk/group.rb, line 194 def validate_update_group_category_data(group_category_data) schema = { 'type' => 'object', 'required' => %w(Name Description AutoEnroll RandomizeEnrollments), 'properties' => { 'Name' => { 'type' => 'string' }, 'Description' => { 'type' => 'object', 'properties' => { "Content" => "string", "Type" => "string" # "Text|HTML" } }, 'AutoEnroll' => { 'type' => 'boolean' }, 'RandomizeEnrollments' => { 'type' => 'boolean' } } } JSON::Validator.validate!(schema, group_category_data, validate_schema: true) end