Top Level Namespace

Defined Under Namespace

Modules: D2lSdk

Instance Method Summary collapse

Instance Method Details

#_course_content_upload(path, json, file, method) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# 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

#_course_package_upload(path, file, method) ⇒ Object

Upload a file to the learning repository.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# 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

#_delete(path, isD2l = true, headers = {}) ⇒ Object

Performs a delete request by creating an authenticated uri and using the RestClient delete method and specifying the content_type as being JSON.



107
108
109
110
111
112
# 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

#_dropbox_upload(path, json, file, method) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# 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

#_ePortfolio_upload(path, file, method, description) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# 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

#_get(path, isD2l = true) ⇒ Object

returns: JSON parsed response.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

#_get_raw(path, isD2l = true) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

#_get_string(path, http_method) ⇒ Object

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



85
86
87
88
89
90
91
92
93
94
95
# 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(parameter, search_string, range, regex = false) ⇒ Object

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



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# 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

#_image_upload(path, file, method) ⇒ Object

REVIEW: image upload process



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# 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

#_learning_repository_upload(path, file, method) ⇒ Object

Upload a file to the learning repository.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# 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

#_news_upload(path, json, files, method) ⇒ Object

function to upload 1+ files to a news event. e.g. uploading 2 attachments to a news event (a text file; a png)



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# 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

#_post(path, payload, isD2l = true) ⇒ Object

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.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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

#_put(path, payload, isD2l = true) ⇒ Object

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.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 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

#_upload_post_data(path, json, files, method) ⇒ Object

bridge function ~~~



370
371
372
# File 'lib/d2l_sdk/requests.rb', line 370

def _upload_post_data(path, json, files, method)
  _news_upload(path, json, files, method)
end

#add_auditor_auditee(auditor_id, auditee_id) ⇒ Object

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?



210
211
212
213
214
# 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

#add_child_org_unit(org_unit_id, child_org_unit_id) ⇒ Object

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.



206
207
208
209
# 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

#add_child_to_module(org_unit_id, module_id, child = {}) ⇒ Object

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# 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

#add_course_to_semester(course_id, semester_id) ⇒ Object

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.



59
60
61
# 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

#add_group_to_group_restriction_list(org_unit_id, forum_id, topic_id, group_id) ⇒ Object

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/

Raises:

  • (ArgumentError)


276
277
278
279
280
281
282
# 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

#add_news_item_attachment(org_unit_id, news_item_id, attachment_data) ⇒ Object

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”.


103
104
105
# 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

#add_parent_to_org_unit(parent_ou_id, child_ou_id) ⇒ Object

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.



214
215
216
217
218
219
220
# 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

#attach_file_to_feedback_entryObject

TODO: Attach an uploaded file to a particular entity’s feedback entry in a specific dropbox folder.

> POST /d2l/api/le/#$le_ver/#org_unit_id/dropbox/folders/#folder_id/feedback/#entity_type/#entity_id/attach



249
# File 'lib/d2l_sdk/dropbox.rb', line 249

def attach_file_to_feedback_entry; end

#build_authenticated_uri_query_string(signature, timestamp) ⇒ Object

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’



49
50
51
52
53
54
55
56
# 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

#bulk_grade_exemption_update(org_unit_id, user_id, bulk_grade_exemption_update_block) ⇒ Object

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.



489
490
491
492
493
494
495
496
497
# 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

#check_and_create_update_status_payload(update_status) ⇒ Object

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.


184
185
186
187
188
189
190
# 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_calendar_event_data_validity(event_data) ⇒ Object

Check the validity of the Calendar.EventData that is passed as a payload



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# 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

#check_content_module_validity(content_module) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# 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

#check_content_topic_validity(content_topic) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# 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

#check_course_data_validity(course_data) ⇒ Object

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.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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

#check_course_template_data_validity(course_template_data) ⇒ Object

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.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

#check_course_template_updated_data_validity(course_template_data) ⇒ Object

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.



97
98
99
100
101
102
103
104
105
106
107
# 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

#check_create_copy_job_request_validity(create_copy_job_request) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# 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

#check_create_demographics_field(demographics_data) ⇒ Object

Additional function added to check that the demographics data (create form) conforms to the JSON schema required by D2L’s backend.



152
153
154
155
156
157
158
159
160
161
162
163
# 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_create_enrollment_data_validity(enrollment_data) ⇒ Object

Check the validity of the CreateEnrollmentData that is passed as a payload



114
115
116
117
118
119
120
121
122
123
124
125
# 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


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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

#check_create_lti_provider_data_validity(create_lti_provider_data) ⇒ Object

Schema to check the CreateLtiProviderData JSON block validity.



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# 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

#check_create_org_unit_type_data_validity(org_unit_type_data) ⇒ Object



371
372
373
374
375
376
377
378
379
380
381
382
383
# 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

#check_create_post_data_validity(create_post_data) ⇒ Object



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# 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

#check_create_topic_data_validity(create_topic_data) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# 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

#check_demographics_entry_data_validity(demographics_entry_data) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 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

#check_dropbox_folder_update_data_validity(dropbox_folder_update_data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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

#check_forum_data_validity(forum_data) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

#check_if_product_supports_api_version(product_code, version) ⇒ Object

determine if a specific product component supports a particular API version



440
441
442
443
# 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

#check_numeric_grade_objectObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

#check_org_unit_data_validity(org_unit_data) ⇒ Object

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.



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# 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

#check_org_unit_information_validity(data_block) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
# 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

#check_org_unit_updated_data_validity(org_unit_data) ⇒ Object

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.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# 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

#check_product_versions(supported_version_request) ⇒ Object

determine versions supported by the back-end Brightspace API requires: JSON SupportedVersionRequest data block



463
464
465
466
467
468
469
470
471
472
473
474
475
476
# 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_section_data_validity(section_data) ⇒ Object

Check the validity of the SectionData that is passed as a payload



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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_section_enrollment_validity(section_enrollment) ⇒ Object

Check the validity of the SectionEnrollment that is passed as a payload



74
75
76
77
78
79
80
81
82
83
# 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_section_property_data_validity(section_property_data) ⇒ Object

Check the validity of the SectionPropertyData that is passed as a payload



96
97
98
99
100
101
102
103
104
105
106
107
108
# 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

#check_semester_data_validity(semester_data) ⇒ Object

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.



15
16
17
# File 'lib/d2l_sdk/semester.rb', line 15

def check_semester_data_validity(semester_data)
    check_org_unit_data_validity(semester_data)
end

#check_semester_updated_data_validity(semester_data) ⇒ Object

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.



108
109
110
# 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

#check_supported_version_request_validity(supported_version_request) ⇒ Object



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# 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

#check_update_demographics_field(demographics_data) ⇒ Object

Additional function added to check that the demographics data (update form) conforms to the JSON schema required by D2L’s backend.



183
184
185
186
187
188
189
190
191
192
193
# 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

#check_updated_course_data_validity(course_data) ⇒ Object

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.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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

#check_updated_user_data_validity(user_data) ⇒ Object

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.



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# 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

#check_user_data_validity(user_data) ⇒ Object

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.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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

#course_component?(key) ⇒ Boolean

simple schema check to assure the course component is an actual course component returns: boolean

Returns:

  • (Boolean)


201
202
203
204
205
206
207
208
209
210
211
# 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

#create_authenticated_uri(path, http_method) ⇒ Object

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



32
33
34
35
36
37
38
39
40
# 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

#create_course_completion(org_unit_id, course_completion_data) ⇒ Object

TODO: Create a new course completion for an org unit. RETURNS: a CourseCompletion JSON block with the newly created course completion record.



382
383
384
385
386
387
388
# 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

#create_course_data(course_data) ⇒ Object

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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

#create_course_import_request(org_unit_id, file_path, callback_url = '') ⇒ Object

REVIEW: Create a new course import job request. INPUT: simple file upload process – using “course package” as the uploaded file



272
273
274
275
276
277
278
# 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

#create_course_template(course_template_data) ⇒ Object

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]



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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

#create_custom_org_unit(org_unit_data) ⇒ Object

Functions considered for basic added functionality to api, not sure if needed.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# 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

#create_custom_outype(create_org_unit_type_data) ⇒ Object



385
386
387
388
389
390
391
392
393
394
395
396
397
398
# 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

#create_demographic_field(demographics_field) ⇒ Object

REVIEW: Create new demographic field Input: DemographicsField (Demographics.Demographicsfield) RETURNS: fetch form of a DemographicsField JSON block



168
169
170
171
172
173
174
175
176
177
178
179
# 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

#create_dropbox_folder(org_unit_id, dropbox_folder_update_data) ⇒ Object

REVIEW: Create a new dropbox folder in an org unit.

> POST /d2l/api/le/#$le_ver/#org_unit_id/dropbox/folders/



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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

#create_dropbox_folder_category(org_unit_id, dropbox_category_id, dropbox_category_name) ⇒ Object

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.


280
281
282
283
284
285
286
287
288
289
290
291
292
293
# 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

#create_event(org_unit_id, event_data) ⇒ Object

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.



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# 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_export_job(create_export_job_data) ⇒ Object

Create an export job for the requested data set



68
69
70
71
72
73
74
75
76
77
78
79
# 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

#create_forum_topic(org_unit_id, forum_id, create_topic_data) ⇒ Object

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/



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# 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_isbn_org_unit_association(org_unit_id, isbn_association_data) ⇒ Object

Create a new association between an ISBN and an org unit.



317
318
319
320
321
322
323
324
325
326
327
# 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)



112
113
114
115
# 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

#create_new_copy_job_request(org_unit_id, create_copy_job_request) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# 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

#create_new_role_from_existing_role(deep_copy_role_id, role_copy_data) ⇒ Object

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.



396
397
398
# 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

#create_news_item(org_unit_id, news_item_data, attachments = []) ⇒ Object

TODO: Create a news item for an org unit. INPUT: multipart/mixed POST body

part 1: news item data JSON
part 2: attachments


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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

#create_org_unit_discussion(org_unit_id, forum_data) ⇒ Object

REVIEW: Create a new forum for an org unit.

> POST /d2l/api/le/#$le_ver/#org_unit_id/discussions/forums/



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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

#create_org_unit_grade_category(org_unit_id, grade_category_data) ⇒ Object

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.



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# 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

#create_org_unit_grade_object(org_unit_id, grade_object, type) ⇒ Object

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# 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_org_unit_group(org_unit_id, group_category_id, group_data) ⇒ Object

Create a new group for an org unit.



145
146
147
148
149
150
151
152
153
154
155
156
# 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

#create_org_unit_group_category(org_unit_id, group_category_data) ⇒ Object

See validate_create_group_category_data for details on schema formal requirements of values Create a new group category for an org unit.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# 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_org_unit_section(org_unit_id, section_data) ⇒ Object

Create a new section in a particular org unit.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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

#create_range(min, max) ⇒ Object

Uses a min and max to create a range. returns: range obj



107
108
109
110
# File 'lib/d2l_sdk/user.rb', line 107

def create_range(min, max)
    (min..max)
    # returns: range obj
end

#create_root_module(org_unit_id, content_module) ⇒ Object

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



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# 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

#create_section_code(star_num, course_date) ⇒ Object

creates a properly formatted section code, based on WIU’s standard section code. RETURNS: formatted section code



169
170
171
# File 'lib/d2l_sdk/section.rb', line 169

def create_section_code(star_num, course_date)
    "sec_#{course_date}_#{star_num}"
end

#create_semester_data(semester_data) ⇒ Object

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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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

#create_semester_formatted_path(org_id, code) ⇒ Object

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



100
101
102
# File 'lib/d2l_sdk/semester.rb', line 100

def create_semester_formatted_path(org_id, code)
    "/content/enforced/#{org_id}-#{code}/"
end

#create_topic_post(org_unit_id, forum_id, topic_id, create_post_data, files = []) ⇒ Object

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



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# 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

#create_user_data(user_data) ⇒ Object

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.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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_user_enrollment(course_enrollment_data) ⇒ Object

Create a new enrollment for a user.



128
129
130
131
132
133
134
135
136
137
138
139
140
# 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

#delete_all_course_templates_with_name(name) ⇒ Object

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.



183
184
185
186
187
188
189
190
# 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

#delete_course_by_id(org_unit_id) ⇒ Object

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.



12
13
14
15
16
17
# 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

#delete_course_completion(org_unit_id, completion_id) ⇒ Object

REVIEW: Delete a course completion. RETURNS: nil



338
339
340
341
# 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

#delete_course_template(org_unit_id) ⇒ Object

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]



11
12
13
14
15
# 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

#delete_course_templates_by_regex(regex) ⇒ Object

TODO: (HOMEBREW) Delete course templates by using regular expressions to filter them.



193
# File 'lib/d2l_sdk/course_template.rb', line 193

def delete_course_templates_by_regex(regex); end

#delete_current_user_context_post_ratingObject

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.



297
298
299
300
301
302
# 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

#delete_current_user_org_unit_pin(org_unit_id) ⇒ Object

REVIEW: Remove the pin from the provided org unit.



147
148
149
150
151
# 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

#delete_demographics_field(field_id) ⇒ Object

REVIEW: Delete a single demographic field, provided it has no associated entries.



130
131
132
133
# 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_group(org_unit_id, group_category_id, group_id) ⇒ Object

Delete a particular group from an org unit.



14
15
16
17
# 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_group_category(org_unit_id, group_category_id) ⇒ Object

Delete a particular group category from an org unit.



8
9
10
11
# 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

#delete_isbn_association(org_unit_id, isbn) ⇒ Object

Remove the association between an ISBN and org unit.



274
275
276
277
# 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

REVIEW: Remove an LTI link.

> DELETE /d2l/api/le/(version)/lti/link/(ltiLinkId)



10
11
12
13
# File 'lib/d2l_sdk/lti.rb', line 10

def delete_lti_link(lti_link_id)
  path = "/d2l/api/le/#{$le_ver}/lti/link/#{lti_link_id}"
  _delete(path)
end

#delete_LTI_tool_provider_registration(tp_id) ⇒ Object

REVIEW: Remove the registration for an LTI tool provider.

> DELETE /d2l/api/le/(version)/lti/tp/(tpId)



154
155
156
157
# File 'lib/d2l_sdk/lti.rb', line 154

def delete_LTI_tool_provider_registration(tp_id)
  path = "/d2l/api/le/#{$le_ver}/lti/tp/#{tp_id}"
  _delete(path)
end

#delete_module(org_unit_id, module_id) ⇒ Object

Delete a specific module from an org unit.



7
8
9
10
# 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

#delete_news_item(org_unit_id, news_item_id) ⇒ Object

REVIEW: Delete a particular news item from an org unit.



8
9
10
11
# 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

#delete_news_item_attachment(org_unit_id, news_item_id, file_id) ⇒ Object

REVIEW: Delete an attachment from an org unit’s news item.



14
15
16
17
# 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

#delete_org_unit_calendar_event(org_unit_id, event_id) ⇒ Object

Calendar ######

REVIEW: Remove a calendar event from a particular org unit. Returns: ?



9
10
11
12
# 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

#delete_org_unit_discussion(org_unit_id, forum_id) ⇒ Object

REVIEW: Delete a particular discussion forum from an org unit.

> DELETE /d2l/api/le/#$le_ver/#org_unit_id/discussions/forums/#forum_id



10
11
12
13
# 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

#delete_org_unit_grade_category(org_unit_id, category_id) ⇒ Object

REVIEW: Delete a specific grade category for a provided org unit.



180
181
182
183
# 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

#delete_org_unit_grade_object(org_unit_id, grade_object_id) ⇒ Object

REVIEW: Delete a specific grade object for a particular org unit. Return: nil



9
10
11
12
# 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_outype(outype_id) ⇒ Object

Delete a particular org unit type



338
339
340
341
# 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

#delete_recycled_org_unit(org_unit_id) ⇒ Object

deletes a particular org unit. This is done via referencing the org unit by its id and performing a delete method.



300
301
302
303
# 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

#delete_relationship_of_child_with_parent(parent_ou_id, child_ou_id) ⇒ Object

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.



23
24
25
26
# 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

#delete_relationship_of_parent_with_child(parent_ou_id, child_ou_id) ⇒ Object

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.



31
32
33
34
# 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_section(org_unit_id, section_id) ⇒ Object

Delete a section from a provided org unit.



9
10
11
12
# 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

#delete_subscription(carrier_id, message_type_id) ⇒ Object

REVIEW: Delete the subscription for messages of a particular type,

delivered by a particular carrier.


313
314
315
316
# 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_topic(org_unit_id, topic_id) ⇒ Object

Delete a specific topic from an org unit.



132
133
134
135
# File 'lib/d2l_sdk/discussions.rb', line 132

def delete_topic(org_unit_id, forum_id, topic_id)
  path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/#{forum_id}/topics/#{topic_id}"
  _delete(path)
end

#delete_topic_group_restriction(org_unit_id, forum_id, topic_id) ⇒ Object

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/



139
140
141
142
# 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

#delete_topic_post(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



290
291
292
293
# 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

#delete_user_data(user_id) ⇒ Object

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.



264
265
266
267
268
269
# 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_user_demographics(user_id, entry_ids = '') ⇒ Object

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



12
13
14
15
16
# 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_user_enrollment(user_id, org_unit_id) ⇒ Object

Delete a user’s enrollment in a provided org unit.



9
10
11
12
13
14
# 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_user_enrollment_alternative(user_id, org_unit_id) ⇒ Object

Delete a user’s enrollment in a provided org unit.



17
18
19
20
21
22
# 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

#delete_user_password(user_id) ⇒ Object

REVIEW: Clear a particular user’s password.



343
344
345
346
# 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

#display_response_code(code) ⇒ Object

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.



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# 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

#does_user_exist(username) ⇒ Object

Checks whether a username already exists returns: true if the the user exists already



114
115
116
# File 'lib/d2l_sdk/user.rb', line 114

def does_user_exist(username)
    !get_user_by_username(username.to_s).nil?
end

#download_job_csv(export_job_id) ⇒ Object

Downloads the identified job and stores the zip within the working directory Extracts zipped job contents in “export_jobs” folder of working directory



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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_user_in_group(org_unit_id, group_category_id, group_id, user_id) ⇒ Object

Enroll a user in a group



184
185
186
187
188
189
190
191
192
# 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_user_in_org_unit_section(org_unit_id, section_id, section_data) ⇒ Object

Enroll a user in a section for a particular org unit.



86
87
88
89
90
91
92
93
# 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

#exempt_user_from_grade(org_unit_id, grade_object_id, user_id) ⇒ Object

REVIEW: Exempt a user from a grade. RETURNS: a User JSON block.



457
458
459
460
461
# 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_formatted_enrollments(csv_fname, instr_fname, regex_filter = //) ⇒ Object

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.



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# 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

#format_signature(path, http_method, timestamp) ⇒ Object

uses the path, http_method, and timestamp arguments to create a properly formatted signature. Then, this is returned.

returns: String::signature



62
63
64
65
# 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

#get_all_childless_org_units(org_unit_type = '', org_unit_code = '', org_unit_name = '', bookmark = '') ⇒ Object

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.



65
66
67
68
69
70
71
72
73
74
75
76
# 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

#get_all_config_var_definitions(search = '', bookmark = '') ⇒ Object

Retrieve the definitions for all the configuration variables the user has access to view.



14
15
16
17
18
19
20
21
22
# 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

#get_all_config_var_org_unit_override_values(variable_id, bookmark = '') ⇒ Object

Retrieve all the org unit override values for a configuration variable.



52
53
54
55
56
57
# 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

#get_all_config_var_org_unit_role_override_values(variable_id, bookmark = '') ⇒ Object

Retrieve all the role override values for a configuration variable.



75
76
77
78
79
80
# 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

#get_all_course_templatesObject

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



146
147
148
149
150
# 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

#get_all_coursesObject



302
303
304
305
# 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

#get_all_data_setsObject

Lists all available data sets



25
26
27
28
# 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

#get_all_demographic_fields(bookmark = '') ⇒ Object

Retrieve list of all demographics fields



136
137
138
139
140
141
# 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

#get_all_demographic_types(bookmark = '') ⇒ Object

Retrieve the list of all demographics data types uses DataTypeId’s as a paging control value



217
218
219
220
221
222
# 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

#get_all_demographics(field_ids = '', role_ids = '', user_ids = '', search = '', bookmark = '') ⇒ Object

Retrieve all demographics entries for all users with specified filters



44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

#get_all_demographics_by_org_unit(org_unit_id, field_ids = '', role_ids = '', user_ids = '', search = '', bookmark = '') ⇒ Object

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


21
22
23
24
25
26
27
28
29
30
31
32
33
# 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

#get_all_demographics_by_org_unit_by_user(org_unit_id, user_id, field_ids = '') ⇒ Object

Retrieve all the demographics entries for a specific user within an OU



36
37
38
39
40
41
# 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

#get_all_enrollments_of_current_user(bookmark = '', sort_by = '', is_active = nil, start_date_time = '', end_date_time = '', can_access = nil) ⇒ Object

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

#get_all_enrollments_of_user(user_id, org_unit_type_id = 0, role_id = 0, bookmark = '') ⇒ Object

Retrieve a list of all enrollments for the provided user. Optional params: –orgUnitTypeId (CSV of D2LIDs) –roleId: D2LIDs –bookmark: string



93
94
95
96
97
98
99
100
101
102
103
# 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

#get_all_export_jobs(bookmark = '') ⇒ Object

List all available export jobs that you have previously submitted



82
83
84
85
86
87
# 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

#get_all_grade_object_grades(org_unit_id, grade_object_id, sort = '', page_size = 0, is_graded = nil, search_text = '') ⇒ Object

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.



294
295
296
297
298
299
300
301
302
303
304
305
306
# 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

#get_all_group_category_groups(org_unit_id, group_category_id) ⇒ Object

Retrieve a list of all the groups in a specific group category for an OrgUnit



38
39
40
41
# 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

#get_all_locales(bookmark = '') ⇒ Object

NOTE: UNSTABLE optional parameter ‘bookmark’ for querying with a paging offset Retrieve the collection of all known locales.



675
676
677
678
679
680
# 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

#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 = '') ⇒ Object

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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

#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 = '') ⇒ Object

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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

#get_all_notification_carrier_channelsObject

Retrieve all the carrier channels for delivering notification messages. RETURNS: a JSON array of CarrierOutput data blocks.



320
321
322
323
# 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

#get_all_org_unit_group_categories(org_unit_id) ⇒ Object

Retrieve a list of all the group categories for the provided org unit.



26
27
28
29
# 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

#get_all_org_units_by_type_id(outype_id) ⇒ Object

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.



426
427
428
429
# 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

#get_all_orphans(org_unit_type = '', org_unit_code = '', org_unit_name = '', bookmark = '') ⇒ Object

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.



84
85
86
87
88
89
90
91
92
# 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

#get_all_outypesObject

retrieves all outypes that are known and visible. This is returned as a JSON array of orgunittype data blocks.



345
346
347
348
# File 'lib/d2l_sdk/org_unit.rb', line 345

def get_all_outypes
    path = "/d2l/api/lp/#{$lp_ver}/outypes/"
    _get(path)
end

#get_all_products_supported_versionsObject

Versions #####



408
409
410
411
412
# 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

#get_all_semestersObject

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



41
42
43
44
# 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

#get_all_subscriptions_by_carrier(carrier_id) ⇒ Object

Retrieve all the current subscriptions for notification messages. RETURNS: a JSON array of SubscriptionOutput data blocks.



327
328
329
330
# 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

#get_all_user_rolesObject

retrieve list of all known user roles



370
371
372
373
374
# 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

#get_auditee(auditee_id) ⇒ Object

REVIEW: Retrieve information for an auditee. RETURNS: a AuditedUser JSON block.



184
185
186
187
188
# 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

#get_auditor(auditor_id) ⇒ Object

REVIEW: Retrieve information for an auditor. RETURNS: a Auditor JSON block.



192
193
194
195
196
# 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

#get_auditor_auditees(auditor_id) ⇒ Object

REVIEW: Retrieve the list of users an auditor is auditing. RETURNS: a JSON array of Auditee blocks.



200
201
202
203
204
# 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

#get_base64_hash_string(key, signature) ⇒ Object

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



73
74
75
76
77
# 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

#get_bookmarked_topics(org_unit_id) ⇒ Object

Retrieve a list of topics that have been bookmarked.



511
512
513
514
515
# 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

#get_calendar_event_count(org_unit_ids_csv, start_date_time, end_date_time, association = nil, event_type = nil) ⇒ Object

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.



63
64
65
66
67
68
69
70
71
72
73
74
# 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

#get_calling_user_due_items_count(org_unit_id, completion = nil, start_date_time = '', end_date_time = '') ⇒ Object

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



469
470
471
472
473
474
475
476
477
478
479
# 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

#get_calling_user_overdue_items_count(org_unit_id, completion = nil, start_date_time = '', end_date_time = '') ⇒ Object

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



455
456
457
458
459
460
461
462
463
464
465
# 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

#get_calling_user_scheduled_items(org_unit_ids_CSV, completion = nil, start_date_time = '', end_date_time = '') ⇒ Object

REVIEW: Retrieve the calling user scheduled items.



334
335
336
337
338
339
340
341
342
343
344
345
# 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

#get_config_var_current_org_value(variable_id) ⇒ Object

Retrieve the current org value for a configuration variable.



45
46
47
48
49
# 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

#get_config_var_definitions(variable_id) ⇒ Object

Retrieve the definitions for a configuration variable.



25
26
27
28
29
# 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

#get_config_var_org_unit_effective_value(variable_id, org_unit_id) ⇒ Object

NOTE: UNSTABLE!!! Retrieve the effective value for a configuration variable within an org unit.



68
69
70
71
72
# 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

#get_config_var_org_unit_override_value(variable_id, org_unit_id) ⇒ Object

Retrieve an org unit override value for a configuration variable.



60
61
62
63
64
# 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

#get_config_var_resolver(variable_id) ⇒ Object

NOTE: UNSTABLE!!! REVIEW: Retrieve the resolution strategy for an org unit configuration variable.



138
139
140
141
# 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

#get_config_var_role_override_value(variable_id, role_id) ⇒ Object



82
83
84
85
# 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

#get_config_var_system_value(variable_id) ⇒ Object



87
88
89
90
# 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

#get_config_var_values(variable_id) ⇒ Object

Retrieve the value summary for a configuration variable.



38
39
40
41
42
# 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

#get_copy_job_request_status(org_unit_id, job_token) ⇒ Object

COPYING COURSES:######



168
169
170
171
172
173
174
175
176
177
178
# 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

#get_copy_jobs_logs(bookmark = '', page_size = 0, source_org_unit_id = 0, destination_org_unit_id = 0, start_date = '', end_date = '') ⇒ Object

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



245
246
247
248
# 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

#get_course_by_id(org_unit_id) ⇒ Object

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



31
32
33
34
35
# 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

#get_course_image(org_unit_id, width = 0, height = 0) ⇒ Object



37
38
39
40
41
42
43
44
# 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

#get_course_import_job_request_logs(org_unit_id, job_token, bookmark = '') ⇒ Object



263
264
265
266
267
268
# 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

#get_course_import_job_request_status(org_unit_id, job_token) ⇒ Object

IMPORTING COURSES:####



254
255
256
257
258
259
260
261
# 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

#get_course_overview(org_unit_id) ⇒ Object

Retrieve the overview for a course offering.



254
255
256
257
258
259
260
# 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

#get_course_overview_file_attachment(org_unit_id) ⇒ Object

Retrieve the overview file attachment for a course offering.



263
264
265
266
267
# 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

#get_course_template(org_unit_id) ⇒ Object

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]



23
24
25
26
27
# 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

#get_course_template_by_name(org_unit_name) ⇒ Object

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



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# 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

#get_course_templates_schemaObject

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]



35
36
37
38
39
# 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

#get_courses_by_code(org_unit_code) ⇒ Object

much slower means of getting courses if less than 100 courses



308
309
310
311
312
313
314
315
# 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

#get_courses_by_name(org_unit_name) ⇒ Object

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



324
325
326
# 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

#get_courses_by_property_by_regex(property, regex) ⇒ Object

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)



355
356
357
358
359
360
361
362
363
364
365
# 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

#get_courses_by_property_by_string(property, search_string) ⇒ Object

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)



336
337
338
339
340
341
342
343
344
345
346
347
348
# 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_current_courses(csv_fname) ⇒ Object

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”



163
164
165
166
167
168
169
170
171
172
# 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

#get_current_user_assessable_folders(type = nil) ⇒ Object

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/



119
120
121
122
123
# 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

#get_current_user_calendar_events_by_org_unit(org_unit_id, associated_events_only = nil) ⇒ Object

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.



24
25
26
27
28
# 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

#get_current_user_calendar_events_by_org_units(org_unit_ids_csv, start_date_time, end_date_time, association = nil, event_type = nil) ⇒ Object

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.



33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

#get_current_user_completed_scheduled_items(org_unit_ids_CSV, completion_from_date_time = '', completed_to_date_time = '') ⇒ Object

REVIEW: Retrieve the calling user completed scheduled items. GET /d2l/api/le/(version)/content/myItems/completions/



395
396
397
398
399
400
401
402
403
404
405
406
# 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

#get_current_user_completed_scheduled_items_with_due_date(org_unit_ids_CSV, completion_from_date_time = '', completed_to_date_time = '') ⇒ Object

REVIEW: Retrieve the calling user’s completed scheduled items that have a due date. GET /d2l/api/le/(version)/content/myItems/completions/due/



410
411
412
413
414
415
416
417
418
419
420
421
# 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

#get_current_user_events_by_org_unit(start_date_time, end_date_time, association = nil, event_type = nil) ⇒ Object

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.



49
50
51
52
53
54
55
56
57
58
59
# 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

#get_current_user_feed(since = "", until_ = "") ⇒ Object

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



25
26
27
28
29
30
31
32
33
# 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

#get_current_user_final_grade(org_unit_id) ⇒ Object

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.



257
258
259
260
261
262
# 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

#get_current_user_final_grades(org_unit_ids_csv) ⇒ Object

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.



271
272
273
274
275
# 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

#get_current_user_forum_topic_post_rating_data(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



355
356
357
358
359
# 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

#get_current_user_forum_topic_post_vote_data(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



379
380
381
382
383
# 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

#get_current_user_locale_settingsObject

REVIEW: Retrieve the current user’s locale account settings.



619
620
621
622
623
# 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

#get_current_user_org_unit_grades(org_unit_id) ⇒ Object

REVIEW: Retrieve all the grade objects for the current user context assigned in a particular org unit.



319
320
321
322
323
# 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

#get_current_user_org_unit_scheduled_items(org_unit_id, completion = nil, start_date_time = '', end_date_time = '') ⇒ Object

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/



440
441
442
443
444
445
446
447
448
449
450
451
# 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

#get_current_user_organized_scheduled_items(org_unit_ids_CSV, completion = nil, start_date_time = '', end_date_time = '') ⇒ Object

REVIEW: Retrieve the quantities of the calling user scheduled items, organized by org unit. GET /d2l/api/le/(version)/content/myItems/itemCounts/



363
364
365
366
367
368
369
370
371
372
373
374
375
376
# 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

#get_current_user_overdue_items(org_unit_ids_CSV = nil) ⇒ Object

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.


499
500
501
502
503
504
# 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

#get_current_user_profileObject

retrieve personal profile info for the current user context Returns: UserProfile JSON data block



424
425
426
427
428
# File 'lib/d2l_sdk/user.rb', line 424

def 
  path = "/d2l/api/lp/#{$lp_ver}/profile/myProfile"
  _get(path)
  # Returns: UserProfile JSON data block
end

#get_current_user_profile_image(size = 0) ⇒ Object

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.


435
436
437
438
439
440
441
442
# File 'lib/d2l_sdk/user.rb', line 435

def (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

#get_current_user_progress(org_unit_id, level) ⇒ Object

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



539
540
541
542
543
544
545
# 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

#get_current_user_scheduled_item_count(org_unit_ids_CSV, completion = nil, start_date_time = '', end_date_time = '') ⇒ Object

REVIEW: Retrieve the quantities of the calling user’s scheduled items still due. GET /d2l/api/le/(version)/content/myItems/due/itemCounts/



380
381
382
383
384
385
386
387
388
389
390
391
# 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

#get_current_user_scheduled_items_by_org_unit(org_unit_id, completion = nil, start_date_time = '', end_date_time = '') ⇒ Object

REVIEW: Retrieve the calling user scheduled items for a particular org unit. GET /d2l/api/le/(version)/#org_unit_id/content/myItems/



425
426
427
428
429
430
431
432
433
434
435
436
# 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

#get_current_user_scheduled_items_still_due(org_unit_ids_CSV, completion = nil, start_date_time = '', end_date_time = '') ⇒ Object

REVIEW: Retrieve the calling user scheduled items still due.



348
349
350
351
352
353
354
355
356
357
358
359
# 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

#get_data_export_job(export_job_id) ⇒ Object

Retrieves information about a data export job that you have previously submitted.



90
91
92
93
# 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

#get_data_set(data_set_id) ⇒ Object

Retrieve a data set



31
32
33
34
# 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

#get_deleted_news(org_unit_id, global = nil) ⇒ Object

NOTE: UNSTABLE!!! REVIEW: Retrieve data blocks containing the properties of deleted news items.



44
45
46
47
48
49
# 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

#get_demographic_field(field_id) ⇒ Object

Retrieve a single demographic field



144
145
146
147
148
# 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

#get_demographic_type(data_type_id) ⇒ Object

retrieve a single demographic data type



225
226
227
228
229
# 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

#get_department_outypeObject

retrieve org unit type of department org units



358
359
360
361
362
# 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

#get_dropbox_file_attachment(org_unit_id, folder_id, file_id) ⇒ Object

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



25
26
27
28
# 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

#get_dropbox_folder(org_unit_id, folder_id) ⇒ Object

REVIEW: Retrieve a specific dropbox folder.

> GET /d2l/api/le/#$le_ver/#org_unit_id/dropbox/folders/#folder_id



18
19
20
21
# File 'lib/d2l_sdk/dropbox.rb', line 18

def get_dropbox_folder(org_unit_id, folder_id)
  path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/dropbox/folders/#{folder_id}"
  _get(path)
end

#get_dropbox_folder_categories(org_unit_id) ⇒ Object

REVIEW: Retrieve all dropbox folder categories for the provided org unit.

> GET /d2l/api/le/#$le_ver/#org_unit_id/dropbox/categories/



261
262
263
264
# 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

#get_dropbox_folder_category_info(org_unit_id, category_id) ⇒ Object

REVIEW: Retrieve the information for a specific dropbox folder category.

> GET /d2l/api/le/#$le_ver/#org_unit_id/dropbox/categories/#category_id



268
269
270
271
# 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

#get_dropbox_folder_entity_feedback_entry(org_unit_id, folder_id, entity_id) ⇒ Object

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



177
178
179
180
# 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

#get_dropbox_folder_submissions(org_unit_id, folder_id, active_only = nil) ⇒ Object

REVIEW: Retrieve all the submissions for a specific dropbox folder.

> GET /d2l/api/le/#$le_ver/#org_unit_id/dropbox/folders/#folder_id/submissions/



131
132
133
134
135
# 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

#get_dropbox_submission_file(org_unit_id, folder_id, submission_id, file_id) ⇒ Object

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



139
140
141
142
# 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

#get_enrolled_roles_in_org_unit(org_unit_id) ⇒ Object

Retrieve a list of all the enrolled user roles the calling user can view in an org unit



385
386
387
388
389
390
391
# 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

#get_enrolled_users_in_classlist(org_unit_id) ⇒ Object

Retrieve the enrolled users in the classlist for an org unit



25
26
27
28
29
# 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

#get_enrollments_details_of_current_user(org_unit_id) ⇒ Object

Retrieve the enrollment details for the current user in the provided org unit.



57
58
59
60
61
# 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

#get_feedback_entry_file_attachment(org_unit_id, folder_id, entity_id, file_id) ⇒ Object

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



184
185
186
187
# 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

#get_forum_topic(org_unit_id, forum_id, topic_id) ⇒ Object

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



153
154
155
156
# 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

#get_forum_topic_group_restrictions(org_unit_id, forum_id, topic_id) ⇒ Object

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/



160
161
162
163
# 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

#get_forum_topic_post(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



323
324
325
326
327
# 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

#get_forum_topic_post_approval_status(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



331
332
333
334
335
# 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

#get_forum_topic_post_flagged_status(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



339
340
341
342
343
# 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

#get_forum_topic_post_rating_data(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



347
348
349
350
351
# 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

#get_forum_topic_post_read_status(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



363
364
365
366
367
# 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

#get_forum_topic_post_vote_data(org_unit_id, forum_id, topic_id, post_id) ⇒ Object

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



371
372
373
374
375
# 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

#get_forum_topic_posts(org_unit_id, forum_id, topic_id, page_size = 0, page_number = 0, threads_only = nil, thread_id = 0, sort = '') ⇒ Object

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



307
308
309
310
311
312
313
314
315
316
317
318
319
# 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

#get_forum_topics(org_unit_id, forum_id) ⇒ Object

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/



146
147
148
149
# 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

#get_grade_exempt_users(org_unit_id, grade_object_id) ⇒ Object

REVIEW: Retrieve all the exempt users for a provided grade. RETURNS: a JSON array of User blocks.



441
442
443
444
445
# 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

#get_grade_item_statistics(org_unit_id, grade_object_id) ⇒ Object

REVIEW: Get statistics for a specified grade item. RETURNS: a GradeStatisticsInfo JSON block.



405
406
407
408
409
# 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

#get_is_user_exempt(org_unit_id, grade_object_id, user_id) ⇒ Object

REVIEW: Determine if a user is exempt from a grade. RETURNS: a User JSON block.



449
450
451
452
453
# 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

#get_isbn_org_unit_association(org_unit_id, isbn) ⇒ Object

Retrieve the association between a ISBN and org unit.



296
297
298
299
300
301
# 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

#get_isbns_of_org_unit(org_unit_id) ⇒ Object

Retrieve all ISBNs associated with an org unit.



288
289
290
291
292
293
# 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

#get_job_status_code(export_job_id) ⇒ Object



95
96
97
# 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

#get_latest_product_version(product_code) ⇒ Object



420
421
422
423
424
425
426
427
428
429
430
# 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

#get_lis_roles(lis_urn = "") ⇒ Object

NOTE: UNSTABLE REVIEW: retrieve list of known LIS roles



579
580
581
582
583
584
# 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

#get_locale_account_settings(user_id) ⇒ Object

REVIEW: retrieve the locale account settings for a particular user.



626
627
628
629
630
# File 'lib/d2l_sdk/user.rb', line 626

def (user_id)
  path = "/d2l/api/lp/#{$lp_ver}/accountSettings/#{user_id}/locale/"
  _get(path)
  # returns Locale JSON block
end

#get_locale_properties(locale_id) ⇒ Object

NOTE: UNSTABLE Retrieve the properties for a particular locale.



684
685
686
687
688
# 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

#get_log_message(log_message_id, include_traces = nil) ⇒ Object

retrieve identified log message



56
57
58
59
60
61
# 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

REVIEW: Retrieve the information for a particular LTI link.

> GET /d2l/api/le/(version)/lti/link/(orgUnitId)/(ltiLinkId)



24
25
26
27
# File 'lib/d2l_sdk/lti.rb', line 24

def get_lti_link_info(org_unit_id, lti_link_id)
  path = "/d2l/api/le/#{$le_ver}/lti/link/#{org_unit_id}/#{lti_link_id}"
  _get(path)
end

#get_lti_tool_provider_information(org_unit_id, tp_id) ⇒ Object

REVIEW: Retrieve the information for a particular LTI tool provider.

> GET /d2l/api/le/(version)/lti/tp/(orgUnitId)/(tpId)



168
169
170
171
# File 'lib/d2l_sdk/lti.rb', line 168

def get_lti_tool_provider_information(org_unit_id, tp_id)
  path = "/d2l/api/le/#{$le_ver}/lti/tp/#{org_unit_id}/#{tp_id}"
  _get(path)
end

#get_module(org_unit_id, module_id) ⇒ Object

Retrieve a specific module for an org unit. Returns ContentObject JSON data block of type Module



20
21
22
23
# 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

#get_module_structure(org_unit_id, module_id) ⇒ Object

Retrieve the structure for a specific module in an org unit. Returns JSON array of ContentObject data blocks (either Module or Topic)



27
28
29
30
# 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

#get_most_recently_visited_topics(org_unit_id) ⇒ Object

Retrieve a list of the most recently visited topics.



518
519
520
521
522
# 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

#get_news_item_attachment(org_unit_id, news_item_id, file_id) ⇒ Object

REVIEW: Retrieve an attachment for an org unit’s news item.



58
59
60
61
# 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

#get_org_department_classes(org_unit_id) ⇒ Object

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.



294
295
296
297
298
# 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

#get_org_enabled_tool_info(org_unit_id, tool_id) ⇒ Object

REVIEW: Retrieve the current information for a tool enabled for the provided org unit.

> GET /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)/(toolId)



230
231
232
233
# 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

#get_org_enabled_tools_info(org_unit_id, bookmark = '') ⇒ Object

REVIEW: Retrieve the current information for all tools enabled for the provided org unit.

> GET /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)



222
223
224
225
226
# 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

#get_org_tool_info(tool_id) ⇒ Object

REVIEW: Retrieve the current organization-level information for a tool.

> GET /d2l/api/lp/(version)/tools/org/(toolId)

RETURNS: an OrgInformation JSON block



176
177
178
179
180
# 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

#get_org_tools_info(include_restricted_tools = nil, bookmark = '') ⇒ Object

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



163
164
165
166
167
168
169
170
171
# 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

#get_org_unit_ancestors(org_unit_id, ou_type_id = 0) ⇒ Object

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.



98
99
100
101
102
103
# 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

#get_org_unit_assessment(org_unit_id, assessment_type, object_type, object_id, user_id) ⇒ Object

TODO: –UNSTABLE– Retrieve an assessment in an org unit. RETURNS: a RubricAssessment JSON structure.



512
513
514
515
# 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

#get_org_unit_calendar_event(org_unit_id, event_id) ⇒ Object

REVIEW: Retrieve a calendar event from a particular org unit. Returns: a EventDataInfo JSON data block



16
17
18
19
# 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

#get_org_unit_calendar_event_count(start_date_time, end_date_time, association = nil, event_type = nil) ⇒ Object

REVIEW: Retrieve a count of calling user’s calendar events, within the

provided org unit context.

RETURNS: An EventCountInfo JSON data block.



79
80
81
82
83
84
85
86
87
88
89
# 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

#get_org_unit_children(org_unit_id, ou_type_id = 0) ⇒ Object

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.



108
109
110
111
112
113
# 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

#get_org_unit_completion_records(org_unit_id, user_id = 0, start_expiry = '', end_expiry = '', bookmark = '') ⇒ Object

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).



347
348
349
350
351
352
353
354
355
356
357
358
359
360
# 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

#get_org_unit_descendants(org_unit_id, ou_type_id = 0) ⇒ Object

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.



130
131
132
133
134
135
# 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

#get_org_unit_discussion(org_unit_id, forum_id) ⇒ Object

REVIEW: Retrieve a particular discussion forum for an org unit.

> GET /d2l/api/le/#$le_ver/#org_unit_id/discussions/forums/#forum_id



24
25
26
27
# 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

#get_org_unit_discussions(org_unit_id) ⇒ Object

REVIEW: Retrieve a list of all discussion forums for an org unit.

> GET /d2l/api/le/#$le_ver/#org_unit_id/discussions/forums/



17
18
19
20
# File 'lib/d2l_sdk/discussions.rb', line 17

def get_org_unit_discussions(org_unit_id)
    path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/discussions/forums/"
    _get(path)
end

#get_org_unit_dropbox_folders(org_unit_id, only_current_students_and_groups = nil) ⇒ Object

REVIEW: Retrieve all dropbox folders for an org unit.

> GET /d2l/api/le/#$le_ver/#org_unit_id/dropbox/folders/



10
11
12
13
14
# 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

#get_org_unit_enrollment_data_by_user(org_unit_id, user_id) ⇒ Object

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.



82
83
84
85
86
# 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

#get_org_unit_enrollments(org_unit_id, role_id = 0, bookmark = '') ⇒ Object

Retrieve the collection of users enrolled in the identified org unit. Optional params: –roleId: D2LID –bookmark: String



67
68
69
70
71
72
73
74
75
# 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

#get_org_unit_grade_categories(org_unit_id) ⇒ Object

REVIEW: Retrieve a list of all grade categories for a provided org unit. Return: This action retrieves a JSON array of GradeObjectCategory blocks.



187
188
189
190
191
# 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

#get_org_unit_grade_category(org_unit_id, category_id) ⇒ Object

REVIEW: Retrieve a specific grade category for a provided org unit. Return: This action retrieves a GradeObjectCategory JSON block.



195
196
197
198
199
# 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

#get_org_unit_grade_config(org_unit_id) ⇒ Object

REVIEW: Retrieve the grades configuration for the org unit. RETURNS: a GradeSetupInfo JSON block.



417
418
419
420
421
# 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

#get_org_unit_grade_object(org_unit_id, grade_object_id) ⇒ Object

REVIEW: Retrieve a specific grade object for a particular org unit. Return: This action returns a GradeObject JSON block.



24
25
26
27
28
# 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

#get_org_unit_grade_scheme(org_unit_id, grade_scheme_id) ⇒ Object

REVIEW: Retrieve a particular grade scheme. Return: This action returns a GradeScheme JSON block.



244
245
246
247
248
# 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

#get_org_unit_grade_schemes(org_unit_id) ⇒ Object

REVIEW: Retrieve all the grade schemes for a provided org unit. Return: This action returns a JSON array of GradeScheme blocks.



236
237
238
239
240
# 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

#get_org_unit_grades(org_unit_id) ⇒ Object

REVIEW: Retrieve all the current grade objects for a particular org unit. Return: This action returns a JSON array of GradeObject blocks.



16
17
18
19
20
# 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

#get_org_unit_group(org_unit_id, group_category_id, group_id) ⇒ Object

Retrieve a particular group in an org unit.



44
45
46
47
# 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

#get_org_unit_group_category(org_unit_id, group_category_id) ⇒ Object

Retrieve a particular group category for an org unit.



32
33
34
35
# 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 the information for all LTI links registered for an org unit.

> GET /d2l/api/le/(version)/lti/link/(orgUnitId)/



17
18
19
20
# File 'lib/d2l_sdk/lti.rb', line 17

def get_org_unit_lti_links(org_unit_id)
  path = "/d2l/api/le/#{$le_ver}/lti/link/#{org_unit_id}/"
  _get(path)
end

#get_org_unit_lti_tool_providers(org_unit_id) ⇒ Object

REVIEW: Retrieve the information for all LTI tool providers registered for an org unit.

> GET /d2l/api/le/(version)/lti/tp/(orgUnitId)/



161
162
163
164
# File 'lib/d2l_sdk/lti.rb', line 161

def get_org_unit_lti_tool_providers(org_unit_id)
  path = "/d2l/api/le/#{$le_ver}/lti/tp/#{org_unit_id}/"
  _get(path)
end

#get_org_unit_news_item(org_unit_id, news_item_id) ⇒ Object

REVIEW: Retrieve a particular news item for an org unit.



52
53
54
55
# 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

#get_org_unit_news_items(org_unit_id, since = "") ⇒ Object

REVIEW: Retrieve a list of news items for an org unit.



36
37
38
39
40
# 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

#get_org_unit_parents(org_unit_id, ou_type_id = 0) ⇒ Object

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.



155
156
157
158
159
160
# 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

#get_org_unit_properties(org_unit_id) ⇒ Object

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.



53
54
55
56
57
# 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

#get_org_unit_rubrics(org_unit_id, object_type, object_id) ⇒ Object

TODO: –UNSTABLE– Retrieve rubrics for an object in an org unit. RETURNS: a JSON array of Rubric blocks.



505
506
507
508
# 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

#get_org_unit_section_property_data(org_unit_id) ⇒ Object

Retrieve the section property data for an org unit.



22
23
24
25
26
# 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

#get_org_unit_sections(org_unit_id) ⇒ Object

Retrieve all the sections for a provided org unit.



15
16
17
18
19
# 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

#get_org_unit_toc(org_unit_id, ignore_module_data_restrictions = false) ⇒ Object

Retrieve the table of course content for an org unit.



525
526
527
528
529
530
# 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

#get_org_units_of_isbn(isbn) ⇒ Object

Retrieve all the org units associated with an ISBN.



280
281
282
283
284
285
# 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

#get_organization_infoObject

Retrieves the organization info. Only gets a small amount of information, but may be useful in some instances.



10
11
12
13
14
# 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

#get_outype(outype_id) ⇒ Object

This retrieves information about a particular org unit type, referenced via the outype_id argument. This is then returned as a JSON object.



352
353
354
355
# 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

#get_paged_calendar_events_by_org_units(org_unit_ids_csv, start_date_time, end_date_time, bookmark = '') ⇒ Object

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



93
94
95
96
97
98
99
100
101
102
103
# 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

#get_paged_org_unit_children(org_unit_id, bookmark = '') ⇒ Object

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.



120
121
122
123
124
125
# 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

#get_paged_org_unit_descendants(org_unit_id, ou_type_id = 0, bookmark = '') ⇒ Object

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)



142
143
144
145
146
147
148
149
150
# 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

#get_parent_outypes_courses_schema_constraintsObject

retrieve the list of parent org unit type constraints for course offerings



20
21
22
23
24
# 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

#get_product_supported_versions(product_code) ⇒ Object

Retrieve the collection of versions supported by a specific product component



415
416
417
418
# File 'lib/d2l_sdk/requests.rb', line 415

def get_product_supported_versions(product_code)
  path = "/d2l/api/#{product_code}/versions/"
  _get(path)
end

#get_profile_image(profile_id, size = 0) ⇒ Object

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.


455
456
457
458
459
460
461
462
# 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

#get_progress_of_usersObject

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/”



549
# File 'lib/d2l_sdk/course_content.rb', line 549

def get_progress_of_users; end

#get_properties_of_all_org_units(org_unit_type = '', org_unit_code = '', org_unit_name = '', bookmark = '') ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

#get_recycled_org_units(bookmark = '') ⇒ Object

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.



310
311
312
313
314
315
# 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

#get_root_modules(org_unit_id) ⇒ Object

Retrieve the root module(s) for an org unit. Returns JSON array of ContentObject data blocks of type Module



34
35
36
37
# 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

#get_section_by_section_code(code) ⇒ Object

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.



176
177
178
179
180
# 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

#get_section_data(org_unit_id, section_id) ⇒ Object

Retrieve a section from a particular org unit.



29
30
31
32
33
# 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

#get_section_data_by_code(code) ⇒ Object

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.



195
196
197
198
199
# 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

#get_section_id_by_section_code(code) ⇒ Object

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.



186
187
188
189
# 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

#get_semester_by_id(org_unit_id) ⇒ Object

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.



50
51
52
53
54
# 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

#get_semester_by_name(search_string) ⇒ Object

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)



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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

#get_semester_outypeObject

retrieve org unit type of semester org units



365
366
367
368
369
# 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

#get_topic(org_unit_id, topic_id) ⇒ Object

Retrieve a specific topic for an org unit. Returns a ContentObject JSON data block of type Topic



41
42
43
44
# 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

#get_topic_file(org_unit_id, topic_id, stream = false) ⇒ Object

Retrieve the content topic file for a content topic. Returns underlying file for a file content topic



48
49
50
51
52
# 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

#get_user_activation_settings(user_id) ⇒ Object

ACTIVATION:###########

REVIEW: Retrieve a particular user’s activation settings. RETURNS: a UserActivationData JSON block with the current activation status.



276
277
278
279
280
# 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

#get_user_by_user_id(user_id) ⇒ Object

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.



197
198
199
200
201
202
# 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

#get_user_by_username(username) ⇒ Object

Retrieves a user based upon an explicitly defined username. Returns: JSON response of this user.



92
93
94
# File 'lib/d2l_sdk/user.rb', line 92

def get_user_by_username(username)
    get_users('', username)
end

#get_user_calendar_events(org_unit_id, user_id, start_date_time, end_date_time, bookmark = '') ⇒ Object

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



108
109
110
111
112
113
114
115
116
117
118
119
# 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

#get_user_completion_records(user_id, start_expiry = '', end_expiry = '', bookmark = '') ⇒ Object

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).



366
367
368
369
370
371
372
373
374
375
376
377
378
# 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

#get_user_demographics(user_id, field_ids = '', bookmark = '') ⇒ Object

Retrieve all the demographics entries for a single user.



59
60
61
62
63
64
65
66
# 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

#get_user_enrollment_data_by_org_unit(user_id, org_unit_id) ⇒ Object

Retrieve enrollment details in an org unit for the provided user. Same as get_org_unit_enrollment_data_by_user



107
108
109
110
111
# 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

#get_user_final_grade(org_unit_id, user_id, grade_type = '') ⇒ Object

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.



282
283
284
285
286
287
288
# 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

#get_user_grade_exemptions(org_unit_id, user_id) ⇒ Object

REVIEW: Retrieve all the grade objects for a provided user in a provided org unit with exemption status included. RETURNS: BulkGradeObjectExemptionResult JSON block.



477
478
479
480
481
# 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

#get_user_grade_object_grade(org_unit_id, grade_object_id, user_id) ⇒ Object

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.



311
312
313
314
315
# 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

#get_user_org_unit_grades(org_unit_id, user_id) ⇒ Object

REVIEW: Retrieve all the grade objects for a particular user assigned in an org unit.



326
327
328
329
330
# 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

#get_user_overdue_items(user_id, org_unit_ids_CSV = nil) ⇒ Object

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.



485
486
487
488
489
490
491
# 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

#get_user_profile_by_profile_id(profile_id) ⇒ Object

retrieve a particular personal profile, by Profile ID



445
446
447
448
449
# File 'lib/d2l_sdk/user.rb', line 445

def (profile_id)
  path = "/d2l/api/lp/#{$lp_ver}/profile/#{profile_id}"
  _get(path)
  # Returns UserProfile JSON data block
end

#get_user_profile_by_user_id(user_id) ⇒ Object

Retrieve a particular personal profile, by User ID.



465
466
467
468
469
# File 'lib/d2l_sdk/user.rb', line 465

def (user_id)
  path = "/d2l/api/lp/#{$lp_ver}/profile/user/#{user_id}"
  _get(path)
  # Returns UserProfile JSON data block
end

#get_user_profile_image(user_id) ⇒ Object

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.


475
476
477
478
479
480
481
482
# File 'lib/d2l_sdk/user.rb', line 475

def (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

#get_user_progressObject

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”



553
# File 'lib/d2l_sdk/course_content.rb', line 553

def get_user_progress; end

#get_user_role(role_id) ⇒ Object

Retrieve a particular user role



377
378
379
380
381
# 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

#get_user_role_lis_mappings_by_role(role_id, d2lid = 0) ⇒ Object

NOTE: UNSTABLE REVIEW: retrieve mapping between a user role and a LIS role



598
599
600
601
602
603
# 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

#get_user_role_lis_mappings_by_urn(lis_urn = "", d2lid = 0) ⇒ Object

NOTE: UNSTABLE REVIEW: retrieve mappings between user roles and LIS roles



588
589
590
591
592
593
594
# 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

#get_users(org_defined_id = '', username = '', bookmark = '') ⇒ Object

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.



76
77
78
79
80
81
82
83
84
85
86
87
88
# 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

#get_users_by_bookmark(bookmark = '') ⇒ Object

Helper function that retrieves the first 100 users after the specified bookmark.

Returns: JSON array of user objects.



100
101
102
103
# File 'lib/d2l_sdk/user.rb', line 100

def get_users_by_bookmark(bookmark = '')
    get_users('', '', bookmark)
    # Returns: JSON array of user objects.
end

#get_versionsObject

retrieve all supported versions for all product components



433
434
435
436
437
# File 'lib/d2l_sdk/requests.rb', line 433

def get_versions
  path = "/d2l/api/versions/"
  _get(path)
  # returns: SupportedVersion JSON block
end

#get_whoamiObject

Retrieves the whoami of the user authenticated through the config file. RETURNS: JSON whoami response



65
66
67
68
69
# 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

#group_category_locker_set_up?(org_unit_id, group_category_id) ⇒ Boolean

Returns:

  • (Boolean)


229
230
231
232
233
# 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

#hide_news_item(org_unit_id, news_item_id) ⇒ Object

REVIEW: Dismiss (hide) a news item for an org unit.



108
109
110
111
# 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_org_unit_sections(org_unit_id, section_property_data) ⇒ Object

Initialize one or more sections for a particular org unit.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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

#initiate_feedback_entry_file_uploadObject

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



253
# 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: ?



303
304
305
# File 'lib/d2l_sdk/user.rb', line 303

def (google_apps_linking_item)
  # POST /d2l/api/gae/(version)/linkuser
end

#map_user_role_to_lis_roles(role_id, mappings) ⇒ Object

NOTE: UNSTABLE TODO: –UNSTABLE– Map a user role to a set of LIS Roles. input: Mappings = String array



608
609
610
# 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

#mark_file_as_read(org_unit_id, folder_id, submission_id) ⇒ Object

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.”



159
160
161
162
# 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

#multithreaded_user_search(parameter, search_string, num_of_threads, regex = false) ⇒ Object

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)



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# 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

#pin_org_unit_for_current_context(org_unit_id) ⇒ Object

REVIEW: Pin an org unit to the top of the list of a user’s enrollments.



154
155
156
157
158
# 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

#post_current_user_new_submissionObject

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.


154
# File 'lib/d2l_sdk/dropbox.rb', line 154

def post_current_user_new_submission; end

#post_feedback_without_attachment(org_unit_id, folder_id, entity_id, entity_type, dropbox_feedback) ⇒ Object

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



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# 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

#post_new_group_submissionObject

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.


148
# File 'lib/d2l_sdk/dropbox.rb', line 148

def post_new_group_submission; end

#prompt(*args) ⇒ Object

requests input from the user, cuts off any new line and downcases it.

returns: String::downcased_user_input



16
17
18
19
20
# File 'lib/d2l_sdk/auth.rb', line 16

def prompt(*args)
    print(*args)
    gets.chomp.downcase
    # returns: String::downcased_user_input
end

#publish_draft_news_item(org_unit_id, news_item_id) ⇒ Object

REVIEW: Publish a draft news item for an org unit.



114
115
116
117
# 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

#recycle_org_unit(org_unit_id) ⇒ Object

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.



320
321
322
323
# 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

#recycle_semester_by_name(name) ⇒ Object

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.



156
157
158
159
160
161
162
163
# 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

#recycle_semester_data(org_unit_id) ⇒ Object

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



144
145
146
147
148
149
150
# 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)



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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

#register_lti_tool_provider(org_unit_id, create_lti_provider_data) ⇒ Object

REVIEW: Register a new LTI tool provider for an org unit.

> POST /d2l/api/le/(version)/lti/tp/(orgUnitId)

INPUT: LTI.CreateLtiProviderData



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# 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

#remove_auditee(auditor_id, auditee_id) ⇒ Object

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



177
178
179
180
# 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

#remove_course_from_semester(course_id, semester_id) ⇒ Object

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.



66
67
68
# 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

#remove_current_user_profile_imageObject

REVIEW: Remove the current user’s profile image.



405
406
407
408
# File 'lib/d2l_sdk/user.rb', line 405

def 
  path = "/d2l/api/lp/#{$lp_ver}/profile/myProfile/image"
  _delete(path)
end

#remove_feedback_entry_file_attachment(org_unit_id, folder_id, entity_type, entity_id, file_id) ⇒ Object

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



170
171
172
173
# 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

#remove_profile_image_by_profile_id(profile_id) ⇒ Object

REVIEW: Remove the profile image from a particular personal profile, by Profile ID.



411
412
413
414
# 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

#remove_profile_image_by_user_id(user_id) ⇒ Object

REVIEW: Remove the profile image from a particular personal profile, by User ID.



417
418
419
420
# 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_user_from_group(org_unit_id, group_category_id, group_id, user_id) ⇒ Object

Remove a particular user from a group.



20
21
22
23
# 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

#remove_user_grade_exemption(org_unit_id, grade_object_id, user_id) ⇒ Object

REVIEW: Remove a user’s exemption from a grade. RETURNS: nil



465
466
467
468
469
# 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

#reset_user_password(user_id) ⇒ Object

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.



351
352
353
354
# 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

#restore_default_org_unit_config_var_resolution(variable_id) ⇒ Object

NOTE: UNSTABLE!!! TODO: UNSTABLE!!! –Restore the default resolution strategy for an org unit configuration variable.



132
# File 'lib/d2l_sdk/config_variables.rb', line 132

def restore_default_org_unit_config_var_resolution(variable_id); end

#restore_news_item(org_unit_id, news_item_id) ⇒ Object

NOTE: UNSTABLE!!! REVIEW: Restore a particular news item by its news_item_id



94
95
96
97
# 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

#restore_recycled_org_unit(org_unit_id) ⇒ Object

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.



328
329
330
331
# 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

#set_config_var_org_value(variable_id, org_value) ⇒ Object

REVIEW: Set a new org value for a configuration variable.

Raises:

  • (ArgumentError)


93
94
95
96
97
98
# 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

#set_config_var_override_value(variable_id, org_unit_id, org_unit_value) ⇒ Object

REVIEW: Set a new org unit override value for a configuration variable.

Raises:

  • (ArgumentError)


101
102
103
104
105
106
# 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

#set_config_var_role_value(variable_id, role_id, role_value) ⇒ Object

REVIEW: Set a new role override value for a configuration variable.

Raises:

  • (ArgumentError)


109
110
111
112
113
114
# 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

#set_config_var_system_value(variable_id, system_value) ⇒ Object

REVIEW: Set a new system value for a configuration variable.

Raises:

  • (ArgumentError)


117
118
119
120
121
122
# 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_carrier_notification(carrier_id, message_type_id) ⇒ Object

Subscribe to notification messages of a particular type, delivered by a particular carrier.



333
334
335
336
# 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

#unhide_news_item(org_unit_id, news_item_id) ⇒ Object

REVIEW: Restore (unhide) a news item for an org unit.



120
121
122
123
# 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(file_path, csv_filter = //) ⇒ Object

Unzip the file, applying a regex filter to the CSV if the file is Enrollments data.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# 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

#update_all_org_unit_tool_status(tool_id, update_status) ⇒ Object

REVIEW: Update a tool’s current status for all org units.

> PUT /d2l/api/lp/(version)/tools/org/(toolId)/OUDefault/override



210
211
212
213
214
# 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

#update_course_completion(org_unit_id, completion_id, course_completion_data) ⇒ Object

TODO: Update an existing course completion. RETURNS: a CourseCompletion JSON block with the newly created course completion record.



392
393
394
395
396
397
# 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_course_data(course_id, new_data) ⇒ Object

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



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# 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

#update_course_image(org_unit_id, image_file_path) ⇒ Object

REVIEW: Update the course image for a course offering.

Raises:

  • (ArgumentError)


150
151
152
153
154
155
156
157
# 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

#update_course_template(org_unit_id, new_data) ⇒ Object

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]



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# 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

#update_current_user_locale_account_settings(locale_id) ⇒ Object

REVIEW: Update the current user’s locale account settings. update_locale = { “LocaleId” : <D2LID>}



641
642
643
644
645
646
647
648
649
650
651
# File 'lib/d2l_sdk/user.rb', line 641

def (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

#update_current_user_profile_data(user_profile_data) ⇒ Object

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.



520
521
522
# File 'lib/d2l_sdk/user.rb', line 520

def ()
  # PUT /d2l/api/lp/(version)/profile/myProfile
end

#update_current_user_profile_imageObject

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: ?



490
491
492
493
# File 'lib/d2l_sdk/user.rb', line 490

def ()
  # POST /d2l/api/lp/(version)/profile/myProfile/image
  # RETURNS: ?
end

#update_demographics_field(field_id, demographics_field) ⇒ Object

REVIEW: Update a single demographic field. Input: DemographicsField (Demographics.Demographicsfield) RETURNS: fetch form of a DemographicsField JSON block



198
199
200
201
202
203
204
205
206
207
208
209
# 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

#update_dropbox_folder(org_unit_id, dropbox_folder_update_data) ⇒ Object

REVIEW: Update a particular dropbox folder in an org unit.

> PUT /d2l/api/le/#$le_ver/#org_unit_id/dropbox/folders/#folder_id



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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

#update_dropbox_folder_category(org_unit_id, category_id, dropbox_category_id, dropbox_category_name) ⇒ Object

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.



299
300
301
302
303
304
305
306
307
308
309
310
311
312
# 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

#update_event(org_unit_id, event_id, event_data) ⇒ Object

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.



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# 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

#update_forum(org_unit_id, forum_id, forum_data) ⇒ Object

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.


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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

#update_forum_topic(org_unit_id, forum_id, topic_id, create_topic_data) ⇒ Object

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



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# 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)



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# 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

#update_lti_tool_provider(tp_id, create_lti_provider_data) ⇒ Object

REVIEW: Update the information associated with a registered LTI tool provider.

> PUT /d2l/api/le/(version)/lti/tp/(tpId)

INPUT: LTI.CreateLtiProviderData



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# 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_module(org_unit_id, module_id, content_module) ⇒ Object

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.



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# 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

#update_news_item(org_unit_id, news_item_id, news_item_data, ) ⇒ Object

TODO: Update a news item for an org unit. INPUT: JSON Parameter of type NewsItemData (News.NewsItemData)



127
128
129
130
131
132
133
134
135
136
137
# 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

#update_org_tool_status(tool_id, update_status) ⇒ Object

REVIEW: Update the organization-level status for a tool.

> PUT /d2l/api/lp/(version)/tools/org/(toolId)



194
195
196
197
198
# 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

#update_org_unit(org_unit_id, org_unit_data) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# 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

#update_org_unit_assessment(org_unit_id, assessment_type, object_type, object_id, user_id, ) ⇒ Object

TODO: –UNSTABLE– Update an assessment in an org unit. RETURNS: value of the assessment in a RubricAssessment JSON structure.



519
520
521
522
# 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

#update_org_unit_config_var_resolution(resolver_value) ⇒ Object

NOTE: UNSTABLE!!! TODO: UNSTABLE!!! –Update the resolution strategy for an org unit configuration variable.



145
# File 'lib/d2l_sdk/config_variables.rb', line 145

def update_org_unit_config_var_resolution(resolver_value); end

#update_org_unit_grade_config(org_unit_id, grade_setup_info) ⇒ Object

TODO: Update the grades configuration for the org unit. INPUT: a GradeSetupInfo JSON block. (grade_setup_info) RETURNS: a GradeSetupInfo JSON block.



426
427
428
429
430
431
432
433
# 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_org_unit_group(org_unit_id, group_category_id, group_id, group_data) ⇒ Object

Update a particular group for an org unit



159
160
161
162
163
164
165
166
167
168
169
170
# 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_org_unit_group_category(org_unit_id, group_category_id, group_category_data) ⇒ Object

update a particular group category for an org unit



215
216
217
218
219
220
221
222
223
224
225
226
227
# 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

#update_org_unit_level_tool_info(org_unit_id, tool_id, org_unit_information) ⇒ Object

REVIEW: Update the org unit-level information for a tool. INPUT: OrgUnitInformation JSON block

> PUT /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)/(toolId)



253
254
255
256
257
258
259
260
261
262
263
264
265
# 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_org_unit_section_info(org_unit_id, section_id, section_data) ⇒ Object

Update information for a section in a particular org unit.



145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/d2l_sdk/section.rb', line 145

def (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_org_unit_section_properties(org_unit_id, section_property_data) ⇒ Object

Update the section properties for an org unit.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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

#update_outype(outype_id, create_org_unit_type_data) ⇒ Object

NOTE: You cannot update the org unit codes if they are default ouTypes update a particular org unit type (with POST for some reason)



402
403
404
405
406
407
408
409
410
411
412
413
414
415
# 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

#update_profile_by_profile_id(profile_id, user_profile_data) ⇒ Object

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.



527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/d2l_sdk/user.rb', line 527

def update_profile_by_profile_id(profile_id, )
  # 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

#update_profile_image_by_profile_idObject

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: ?



501
502
503
504
# 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

#update_profile_image_by_user_idObject

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: ?



512
513
514
515
# 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

#update_semester_data(org_unit_id, semester_data) ⇒ Object

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.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# 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

#update_tool_default_status(tool_id, update_status) ⇒ Object

REVIEW: Update a tool’s default status for new org units.

> PUT /d2l/api/lp/(version)/tools/org/(toolId)/OUDefault



202
203
204
205
206
# 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_topic(org_unit_id, topic_id, content_topic) ⇒ Object

Update a particular topic for an org unit. INPUT: ContentObjectData of type Topic Returns underlying file for a file content topic



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# 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

#update_topic_post(org_unit_id, forum_id, topic_id, post_id, create_post_data) ⇒ Object

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



437
438
439
440
441
442
443
444
445
446
447
448
449
450
# 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

#update_topic_post_approval_status(org_unit_id, forum_id, topic_id, post_id, is_approved) ⇒ Object

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

Raises:

  • (ArgumentError)


455
456
457
458
459
460
# 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

#update_topic_post_current_user_rating(org_unit_id, forum_id, topic_id, post_id, rating) ⇒ Object

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

Raises:

  • (ArgumentError)


476
477
478
479
480
481
# 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

#update_topic_post_current_user_vote_data(org_unit_id, forum_id, topic_id, post_id, vote) ⇒ Object

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: ??



496
497
498
499
500
501
502
503
504
505
506
# 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

#update_topic_post_flagged_status(org_unit_id, forum_id, topic_id, post_id, is_flagged) ⇒ Object

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

Raises:

  • (ArgumentError)


466
467
468
469
470
471
# 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

#update_topic_post_read_status(org_unit_id, forum_id, topic_id, post_id, is_read) ⇒ Object

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

Raises:

  • (ArgumentError)


486
487
488
489
490
491
# 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

#update_user_activation_settings(user_id, is_active) ⇒ Object

REVIEW: Update a particular user’s activation settings. RETURNS: ?

Raises:

  • (ArgumentError)


284
285
286
287
288
289
290
291
292
293
294
# 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

#update_user_data(user_id, new_data) ⇒ Object

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.



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# 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

#update_user_demographics(user_id, demographics_entry_data) ⇒ Object

REVIEW: Update the demographics entries for a single user. Return: a DemographicsUserEntryData JSON block containing the user’s updated entries.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 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

#update_user_locale_account_settings(user_id, locale_id) ⇒ Object

REVIEW: Update the locale account settings for a particular user. update_locale = { “LocaleId” : <D2LID>}



655
656
657
658
659
660
661
662
663
664
# File 'lib/d2l_sdk/user.rb', line 655

def (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

#update_user_password(user_id, user_password_data) ⇒ Object

REVIEW: Update a particular user’s password. NOTE: 400 errors are implicitly invalid password

Raises:

  • (ArgumentError)


358
359
360
361
362
363
# 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

#update_user_progressObject

TODO: –UNSTABLE– Update a user progress item. _post “/d2l/api/le/#$le_ver/#org_unit_id/content/userprogress/” payload: UserProgressData



558
# File 'lib/d2l_sdk/course_content.rb', line 558

def update_user_progress; end

#valid_locale_id?(locale_id) ⇒ Boolean

Add schema check for update_locale conforming to the D2L update_locale JSON data block of form: { “LocaleId” : <D2LID>}.

Returns:

  • (Boolean)


634
635
636
637
# 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

#validate_create_export_job_data(create_export_job_data) ⇒ Object

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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

#validate_create_group_category_data(group_category_data) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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

#validate_group_data(group_data) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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

#validate_group_enrollment_data(group_enrollment_data) ⇒ Object



172
173
174
175
176
177
178
179
180
181
# 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

#validate_isbn_association_data(isbn_association_data) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
314
# 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

#validate_update_group_category_data(group_category_data) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# 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