d2l_sdk 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/change_lastname.rb +65 -0
- data/lib/d2l_sdk/calendar.rb +264 -0
- data/lib/d2l_sdk/config_variables.rb +117 -1
- data/lib/d2l_sdk/course_content.rb +47 -2
- data/lib/d2l_sdk/demographics.rb +85 -3
- data/lib/d2l_sdk/discussions.rb +199 -0
- data/lib/d2l_sdk/dropbox.rb +120 -0
- data/lib/d2l_sdk/grades.rb +303 -136
- data/lib/d2l_sdk/lockers.rb +40 -0
- data/lib/d2l_sdk/lti.rb +34 -0
- data/lib/d2l_sdk/news.rb +20 -0
- data/lib/d2l_sdk/permissions.rb +27 -0
- data/lib/d2l_sdk/requests.rb +228 -18
- data/lib/d2l_sdk/setup_versions.rb +14 -6
- data/lib/d2l_sdk/user.rb +15 -5
- data/lib/d2l_sdk/version.rb +1 -1
- data/lol.txt +1 -0
- data/test.rb +19 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f7d151a275583e45a75dadc1282f5c9d2c8dc09
|
4
|
+
data.tar.gz: e74a5359b1aa0393f3c3d39a9078e6d5b1a52887
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ce26d16bfdb64942f20473b6cdf86a1769dbd69ada54f6f7db1f385becefa2921db44ed3c3b96eb05301977a5fe8ad8c645dbcfca5a938b486a0af5f8ba3bdf
|
7
|
+
data.tar.gz: a5be1c83743cbac6b44676e629323a327dced170235ec86926e3bceaedf84ef927bfdfb0ca985183698d09dfca5858da1e6425c51740f01d85411f7c076ebbf7
|
data/change_lastname.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'd2l_sdk'
|
2
|
+
|
3
|
+
# Setup vars for username and last name
|
4
|
+
# retrieved via rundeck args passed to this script.
|
5
|
+
@username = ARGV[0]
|
6
|
+
@new_lastname = ARGV[1]
|
7
|
+
@debug = false
|
8
|
+
|
9
|
+
# Check that the user exists.
|
10
|
+
# If the username doesn't exist, then raise.
|
11
|
+
# Why: You can't change a user's profile that you can't reference.
|
12
|
+
if !does_user_exist(@username)
|
13
|
+
raise ArgumentError, "ARGV[0], '#{@username}', is not a username that exists."
|
14
|
+
end
|
15
|
+
|
16
|
+
# Already asserted that the user exists. Retrieve Hash of the user's profile.
|
17
|
+
user_profile = get_user_by_username(@username)
|
18
|
+
|
19
|
+
# debug code
|
20
|
+
puts "Old User Data: \n" if @debug
|
21
|
+
ap user_profile if @debug
|
22
|
+
|
23
|
+
# Change the previous d2l user data and create a new json-formatted
|
24
|
+
# payload. The payload is merged! with a skeleton payload, but it as
|
25
|
+
# each parameter is defined, this will not affect its usage.
|
26
|
+
old_lastname = user_profile["LastName"]
|
27
|
+
user_profile["LastName"] = @new_lastname # update the user's lastname
|
28
|
+
user_profile["UserName"].sub! old_lastname, @new_lastname # update the user's username
|
29
|
+
unless user_profile["ExternalEmail"].nil?
|
30
|
+
user_profile["ExternalEmail"].sub! old_lastname, @new_lastname # update the user's email
|
31
|
+
end
|
32
|
+
|
33
|
+
# Check if there already is a user created with the +new username+
|
34
|
+
if does_user_exist(user_profile["UserName"])
|
35
|
+
raise RuntimeError, "A user already exists with the new username, '#{user_profile["UserName"]}'."
|
36
|
+
end
|
37
|
+
|
38
|
+
# Pull in data only necessary for user_data in +update+ form.
|
39
|
+
new_user_data =
|
40
|
+
{
|
41
|
+
'OrgDefinedId' => user_profile["OrgDefinedId"],
|
42
|
+
'FirstName' => user_profile["FirstName"],
|
43
|
+
'MiddleName' => user_profile["MiddleName"],
|
44
|
+
'LastName' => user_profile["LastName"], # Changed previously
|
45
|
+
'ExternalEmail' => user_profile["ExternalEmail"],
|
46
|
+
'UserName' => user_profile["UserName"],
|
47
|
+
'Activation' =>
|
48
|
+
{
|
49
|
+
'IsActive' => user_profile["Activation"]["IsActive"]
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
# Debug code
|
54
|
+
puts "New User Data: \n" if @debug
|
55
|
+
ap new_user_data if @debug
|
56
|
+
|
57
|
+
# Finally update the user's UserData
|
58
|
+
update_user_data(user_profile["UserId"], new_user_data)
|
59
|
+
|
60
|
+
# Check if the user was properly created.
|
61
|
+
if !does_user_exist(user_profile["UserName"])
|
62
|
+
raise "The user's last name was unsuccessfully updated."
|
63
|
+
else
|
64
|
+
puts "The username was successfully updated to: '#{user_profile["UserName"]}'."
|
65
|
+
end
|
@@ -0,0 +1,264 @@
|
|
1
|
+
require_relative 'requests'
|
2
|
+
require 'json-schema'
|
3
|
+
|
4
|
+
##################
|
5
|
+
## Calendar ######
|
6
|
+
##################
|
7
|
+
# REVIEW: Remove a calendar event from a particular org unit.
|
8
|
+
# Returns: ?
|
9
|
+
def delete_org_unit_calendar_event(org_unit_id, event_id)
|
10
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}"
|
11
|
+
_delete(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
# REVIEW: Retrieve a calendar event from a particular org unit.
|
15
|
+
# Returns: a EventDataInfo JSON data block
|
16
|
+
def get_org_unit_calendar_event(org_unit_id, event_id)
|
17
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}"
|
18
|
+
_get(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
# REVIEW: Retrieve all the calendar events for the calling user,
|
22
|
+
# within the provided org unit context.
|
23
|
+
# RETURNS: This action returns a JSON array of EventDataInfo data blocks.
|
24
|
+
def get_current_user_calendar_events_by_org_unit(org_unit_id, associated_events_only = nil)
|
25
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/"
|
26
|
+
path += "?associatedEventsOnly=#{associated_events_only}" unless associated_events_only.nil?
|
27
|
+
_get(path)
|
28
|
+
end
|
29
|
+
|
30
|
+
# REVIEW: Retrieve the calling user’s calendar events, within a
|
31
|
+
# number of org units (see query parameter)
|
32
|
+
# RETURNS: An ObjectListPage JSON block containing a list of EventDataInfo JSON data blocks.
|
33
|
+
def get_current_user_calendar_events_by_org_units(association = nil, event_type = nil,
|
34
|
+
org_unit_ids_csv, start_date_time,
|
35
|
+
end_date_time)
|
36
|
+
path = "/d2l/api/le/#{$le_ver}/calendar/events/myEvents/"
|
37
|
+
path += "?orgUnitIdsCSV=#{org_unit_ids_csv}"
|
38
|
+
path += "&startDateTime=#{start_date_time}"
|
39
|
+
path += "&endDateTime=#{end_date_time}"
|
40
|
+
path += "&association=#{association}" unless association.nil?
|
41
|
+
path += "&eventType=#{event_type}" unless event_type.nil?
|
42
|
+
_get(path)
|
43
|
+
end
|
44
|
+
|
45
|
+
# REVIEW: Retrieve the calling user’s events for a particular org unit.
|
46
|
+
# RETURNS: An ObjectListPage JSON block containing a list of EventDataInfo JSON data blocks.
|
47
|
+
def get_current_user_events_by_org_unit(association = nil, event_type = nil,
|
48
|
+
start_date_time, end_date_time)
|
49
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/myEvents/"
|
50
|
+
path += "&startDateTime=#{start_date_time}"
|
51
|
+
path += "&endDateTime=#{end_date_time}"
|
52
|
+
path += "&association=#{association}" unless association.nil?
|
53
|
+
path += "&eventType=#{event_type}" unless event_type.nil?
|
54
|
+
_get(path)
|
55
|
+
end
|
56
|
+
|
57
|
+
# REVIEW: Retrieve a count of calling user’s calendar events, within a number of org units
|
58
|
+
# RETURNS: An ObjectListPage JSON block containing a list of EventCountInfo JSON data blocks.
|
59
|
+
def get_calendar_event_count(association = nil, event_type = nil, org_unit_ids_csv,
|
60
|
+
start_date_time, end_date_time)
|
61
|
+
path = "/d2l/api/le/#{$le_ver}/calendar/events/myEvents/itemCounts/"
|
62
|
+
path += "?orgUnitIdsCSV=#{org_unit_ids_csv}"
|
63
|
+
path += "&startDateTime=#{start_date_time}"
|
64
|
+
path += "&endDateTime=#{end_date_time}"
|
65
|
+
path += "&association=#{association}" unless association.nil?
|
66
|
+
path += "&eventType=#{event_type}" unless event_type.nil?
|
67
|
+
_get(path)
|
68
|
+
end
|
69
|
+
|
70
|
+
# REVIEW: Retrieve a count of calling user’s calendar events, within the
|
71
|
+
# provided org unit context.
|
72
|
+
# RETURNS: An EventCountInfo JSON data block.
|
73
|
+
def get_org_unit_calendar_event_count(association = nil, event_type = nil,
|
74
|
+
start_date_time, end_date_time)
|
75
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/myEvents/itemCounts/"
|
76
|
+
path += "?startDateTime=#{start_date_time}"
|
77
|
+
path += "&endDateTime=#{end_date_time}"
|
78
|
+
path += "&association=#{association}" unless association.nil?
|
79
|
+
path += "&eventType=#{event_type}" unless event_type.nil?
|
80
|
+
_get(path)
|
81
|
+
end
|
82
|
+
|
83
|
+
# REVIEW: Retrieve all the calendar events for the calling user, within a number of org units.
|
84
|
+
# RETURNS: a paged result set containing the resulting EventDataInfo JSON data blocks
|
85
|
+
def get_paged_calendar_events_by_org_units(org_unit_ids_csv, start_date_time,
|
86
|
+
end_date_time, bookmark = '')
|
87
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/orgunits/"
|
88
|
+
path += "?orgUnitIdsCSV=#{org_unit_ids_csv}"
|
89
|
+
path += "&startDateTime=#{start_date_time}"
|
90
|
+
path += "&endDateTime=#{end_date_time}"
|
91
|
+
path += "&bookmark=#{bookmark}" unless bookmark == ''
|
92
|
+
_get(path)
|
93
|
+
end
|
94
|
+
|
95
|
+
# REVIEW: Retrieve all the calendar events for a specified user’s explicit
|
96
|
+
# enrollments within the organization containing the specified org unit.
|
97
|
+
# RETURNS: a paged result set containing the resulting EventDataInfo JSON data blocks
|
98
|
+
def get_user_calendar_events(org_unit_id, user_id, start_date_time, end_date_time,
|
99
|
+
bookmark = '')
|
100
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/user/"
|
101
|
+
path += "?userId=#{user_id}"
|
102
|
+
path += "&startDateTime=#{start_date_time}"
|
103
|
+
path += "&endDateTime=#{end_date_time}"
|
104
|
+
path += "&bookmark=#{bookmark}" unless bookmark == ''
|
105
|
+
_get(path)
|
106
|
+
# RETURNS: a paged result set containing the resulting EventDataInfo JSON data blocks
|
107
|
+
end
|
108
|
+
|
109
|
+
# Check the validity of the Calendar.EventData that is passed as a payload
|
110
|
+
def check_calendar_event_data_validity(event_data)
|
111
|
+
schema =
|
112
|
+
{
|
113
|
+
'type' => 'object',
|
114
|
+
'required' => %w(Title Description StartDateTime EndDateTime StartDay
|
115
|
+
EndDay GroupId RecurrenceInfo HasVisibilityRestrictions
|
116
|
+
VisibilityRestrictions CalendarEventViewUrl),
|
117
|
+
'properties' =>
|
118
|
+
{
|
119
|
+
'Title' => { 'type' => 'integer' },
|
120
|
+
"Description" => { 'type' => 'integer' },
|
121
|
+
"StartDateTime" => { 'type' => %w(string nil) }, # UTCDateTime || nil
|
122
|
+
"EndDateTime" => { 'type' => %w(string nil) }, # UTCDateTime || nil
|
123
|
+
"StartDay" => { 'type' => %w(string nil) }, # LocalDateTime || nil
|
124
|
+
"EndDay" => { 'type' => %w(string nil) }, # LocalDateTime || nil
|
125
|
+
"GroupId" => { 'type' => %w(integer nil) }, # D2LID || nil
|
126
|
+
"RecurrenceInfo" =>
|
127
|
+
{
|
128
|
+
'type' => 'object',
|
129
|
+
'required' => %w(RepeatType RepeatEvery RepeatOnInfo RepeatUntilDate),
|
130
|
+
'properties' =>
|
131
|
+
{
|
132
|
+
"RepeatType" => { 'type' => 'integer' }, # number -- repeat type
|
133
|
+
"RepeatEvery" => { 'type' => 'integer' }, # number
|
134
|
+
"RepeatOnInfo" => # Calendar.RepeatOnInfo
|
135
|
+
{
|
136
|
+
'type' => 'object',
|
137
|
+
'required' => %w(Monday Tuesday Wednesday Thursday Friday
|
138
|
+
Saturday Sunday),
|
139
|
+
'properties' =>
|
140
|
+
{
|
141
|
+
"Monday" => { 'type' => 'boolean' }, # boolean
|
142
|
+
"Tuesday" => { 'type' => 'boolean' }, # boolean
|
143
|
+
"Wednesday" => { 'type' => 'boolean' }, # boolean
|
144
|
+
"Thursday" => { 'type' => 'boolean' }, # boolean
|
145
|
+
"Friday" => { 'type' => 'boolean' }, # boolean
|
146
|
+
"Saturday" => { 'type' => 'boolean' }, # boolean
|
147
|
+
"Sunday" => { 'type' => 'boolean' }, # boolean
|
148
|
+
}
|
149
|
+
},
|
150
|
+
"RepeatUntilDate" => { 'type' => 'string' } # UTCDATETIME
|
151
|
+
}
|
152
|
+
}, # Calendar.RecurrenceInfo
|
153
|
+
"HasVisibilityRestrictions" => { 'type' => 'boolean' },
|
154
|
+
"VisibilityRestrictions" =>
|
155
|
+
{
|
156
|
+
'type' => 'object',
|
157
|
+
'required' => %w(Type Range HiddenRangeUnitType StartDate EndDate),
|
158
|
+
'properties' =>
|
159
|
+
{
|
160
|
+
"Type" => { 'type' => 'integer' }, # <number:VISIBILITY_T>,
|
161
|
+
"Range" => { 'type' => %w(integer nil) }, # <number>|null,
|
162
|
+
"HiddenRangeUnitType" => { 'type' => %w(integer nil) }, # <number:HIDDENUNIT_T>|null,
|
163
|
+
"StartDate" => { 'type' => %w(string nil) }, # <string:UTCDateTime>|null,
|
164
|
+
"EndDate" => { 'type' => %w(string nil) } # <string:UTCDateTime>|null,
|
165
|
+
}
|
166
|
+
}, # Calendar.VisibilityInfo
|
167
|
+
"CalendarEventViewUrl" => { 'type' => 'string' } # url
|
168
|
+
}
|
169
|
+
}
|
170
|
+
JSON::Validator.validate!(schema, event_data, validate_schema: true)
|
171
|
+
end
|
172
|
+
|
173
|
+
# REVIEW: Create Schema checker; Check that this payload conforms to it.
|
174
|
+
# Create a new event.
|
175
|
+
# INPUT: Calendar.EventData
|
176
|
+
# RETURNS:a EventDataInfo data block for the newly created event.
|
177
|
+
def create_event(org_unit_id, event_data)
|
178
|
+
# POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/
|
179
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/"
|
180
|
+
payload = { #Calendar.EventDataInfo
|
181
|
+
"Title" => "",
|
182
|
+
"Description" => "",
|
183
|
+
"StartDateTime" => nil, # UTCDateTime || nil
|
184
|
+
"EndDateTime" => nil, # UTCDateTime || nil
|
185
|
+
"StartDay" => nil, # LocalDateTime || nil
|
186
|
+
"EndDay" => nil, # LocalDateTime || nil
|
187
|
+
"GroupId" => nil, # D2LID || nil
|
188
|
+
"RecurrenceInfo" => # Calendar.RecurrenceInfo
|
189
|
+
{
|
190
|
+
"RepeatType" => 0, # number -- repeat type
|
191
|
+
"RepeatEvery" => 0, # number
|
192
|
+
"RepeatOnInfo" => # Calendar.RepeatOnInfo
|
193
|
+
{
|
194
|
+
"Monday" => false, # boolean
|
195
|
+
"Tuesday" => false, # boolean
|
196
|
+
"Wednesday" => false, # boolean
|
197
|
+
"Thursday" => false, # boolean
|
198
|
+
"Friday" => false, # boolean
|
199
|
+
"Saturday" => false, # boolean
|
200
|
+
"Sunday" => false, # boolean
|
201
|
+
},
|
202
|
+
"RepeatUntilDate" => "" # UTCDATETIME
|
203
|
+
},
|
204
|
+
"HasVisibilityRestrictions" => false,
|
205
|
+
"VisibilityRestrictions" => # Calendar.VisibilityInfo
|
206
|
+
{
|
207
|
+
"Type" => 0, # <number:VISIBILITY_T>,
|
208
|
+
"Range" => nil, # <number>|null,
|
209
|
+
"HiddenRangeUnitType" => nil, # <number:HIDDENUNIT_T>|null,
|
210
|
+
"StartDate" => nil, # <string:UTCDateTime>|null,
|
211
|
+
"EndDate" => nil # <string:UTCDateTime>|null,
|
212
|
+
},
|
213
|
+
"CalendarEventViewUrl" => "" # String:URL
|
214
|
+
}.merge!(event_data)
|
215
|
+
check_calendar_event_data_validity(payload) # NOTE: Test later
|
216
|
+
_post(path, payload)
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
# REVIEW: Create Schema checker; Check that this payload conforms to it.
|
221
|
+
# Update the properties for a calendar event from a particular org unit.
|
222
|
+
# INPUT: Calendar.EventData
|
223
|
+
# RETURNS:a EventDataInfo data block for the newly updated event.
|
224
|
+
def update_event(org_unit_id, event_id, event_data)
|
225
|
+
# PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}
|
226
|
+
path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}"
|
227
|
+
payload = { #Calendar.EventDataInfo
|
228
|
+
"Title" => "",
|
229
|
+
"Description" => "",
|
230
|
+
"StartDateTime" => nil, # UTCDateTime || nil
|
231
|
+
"EndDateTime" => nil, # UTCDateTime || nil
|
232
|
+
"StartDay" => nil, # LocalDateTime || nil
|
233
|
+
"EndDay" => nil, # LocalDateTime || nil
|
234
|
+
"GroupId" => nil, # D2LID || nil
|
235
|
+
"RecurrenceInfo" => # Calendar.RecurrenceInfo
|
236
|
+
{
|
237
|
+
"RepeatType" => 0, # number -- repeat type
|
238
|
+
"RepeatEvery" => 0, # number
|
239
|
+
"RepeatOnInfo" => # Calendar.RepeatOnInfo
|
240
|
+
{
|
241
|
+
"Monday" => false, # boolean
|
242
|
+
"Tuesday" => false, # boolean
|
243
|
+
"Wednesday" => false, # boolean
|
244
|
+
"Thursday" => false, # boolean
|
245
|
+
"Friday" => false, # boolean
|
246
|
+
"Saturday" => false, # boolean
|
247
|
+
"Sunday" => false, # boolean
|
248
|
+
},
|
249
|
+
"RepeatUntilDate" => "" # UTCDATETIME
|
250
|
+
},
|
251
|
+
"HasVisibilityRestrictions" => false,
|
252
|
+
"VisibilityRestrictions" => # Calendar.VisibilityInfo
|
253
|
+
{
|
254
|
+
"Type" => 0, # <number:VISIBILITY_T>,
|
255
|
+
"Range" => nil, # <number>|null,
|
256
|
+
"HiddenRangeUnitType" => nil, # <number:HIDDENUNIT_T>|null,
|
257
|
+
"StartDate" => nil, # <string:UTCDateTime>|null,
|
258
|
+
"EndDate" => nil # <string:UTCDateTime>|null,
|
259
|
+
},
|
260
|
+
"CalendarEventViewUrl" => "" # String:URL
|
261
|
+
}.merge!(event_data)
|
262
|
+
check_calendar_event_data_validity(payload) # NOTE: Test later
|
263
|
+
_put(path, payload)
|
264
|
+
end
|
@@ -151,7 +151,123 @@ def get_config_var_resolver(variable_id)
|
|
151
151
|
end
|
152
152
|
|
153
153
|
# NOTE: UNSTABLE!!!
|
154
|
-
# TODO: Update the resolution strategy for an org unit configuration variable.
|
154
|
+
# TODO: UNSTABLE!!! --Update the resolution strategy for an org unit configuration variable.
|
155
155
|
def update_org_unit_config_var_resolution(resolver_value)
|
156
156
|
# PUT /d2l/api/lp/(version)/configVariables/(variableId)/resolver
|
157
157
|
end
|
158
|
+
|
159
|
+
################################################################################
|
160
|
+
############################### TOOLS ###################################
|
161
|
+
################################################################################
|
162
|
+
# NOTE: This section has been appended to config variables due to its similar
|
163
|
+
# placement in the GUI and the fact that tools functions are rather small
|
164
|
+
# in number.
|
165
|
+
|
166
|
+
########################
|
167
|
+
# ORGANIZATION:#########
|
168
|
+
########################
|
169
|
+
|
170
|
+
# REVIEW: Retrieve the current organization-level information for all tools.
|
171
|
+
# => GET /d2l/api/lp/(version)/tools/org/
|
172
|
+
# RETURNS: paged result set containing the resulting OrgInformation data blocks
|
173
|
+
def get_org_tools_info(include_restricted_tools = nil, bookmark = '')
|
174
|
+
path = "/d2l/api/lp/#{$lp_ver}/tools/org/?"
|
175
|
+
path += "includeRestrictedTools=#{includeRestrictedTools}&" unless include_restricted_tools.nil?
|
176
|
+
path += "bookmark=#{bookmark}" unless bookmark == ''
|
177
|
+
_get(path)
|
178
|
+
# RETURNS: paged result set containing the resulting OrgInformation data blocks
|
179
|
+
end
|
180
|
+
|
181
|
+
# REVIEW: Retrieve the current organization-level information for a tool.
|
182
|
+
# => GET /d2l/api/lp/(version)/tools/org/(toolId)
|
183
|
+
# RETURNS: an OrgInformation JSON block
|
184
|
+
def get_org_tool_info(tool_id)
|
185
|
+
path = "GET /d2l/api/lp/#{$lp_ver}/tools/org/#{tool_id}"
|
186
|
+
_get(path)
|
187
|
+
# RETURNS: an OrgInformation JSON block
|
188
|
+
end
|
189
|
+
|
190
|
+
# NOTE: Not inherent d2l_api function. This is to check that the update_status
|
191
|
+
# is actually a boolean and return a formatted UpdateStatus JSON block.
|
192
|
+
def check_and_create_update_status_payload(update_status)
|
193
|
+
if update_status != true && update_status != false
|
194
|
+
raise ArgumentError, 'update_status is not a boolean'
|
195
|
+
end
|
196
|
+
payload = {"Status" => update_status} # Tools.UpdateStatus JSON data block
|
197
|
+
payload
|
198
|
+
end
|
199
|
+
|
200
|
+
# REVIEW: Update the organization-level status for a tool.
|
201
|
+
# => PUT /d2l/api/lp/(version)/tools/org/(toolId)
|
202
|
+
def update_org_tool_status(tool_id, update_status)
|
203
|
+
path = "/d2l/api/lp/#{$lp_ver}/tools/org/#{tool_id}"
|
204
|
+
payload = check_and_create_update_status_payload(update_status)
|
205
|
+
_put(path, payload)
|
206
|
+
end
|
207
|
+
|
208
|
+
# REVIEW: Update a tool’s default status for new org units.
|
209
|
+
# => PUT /d2l/api/lp/(version)/tools/org/(toolId)/OUDefault
|
210
|
+
def update_tool_default_status(tool_id, update_status)
|
211
|
+
path = "/d2l/api/lp/#{$lp_ver}/tools/org/#{tool_id}/OUDefault"
|
212
|
+
payload = check_and_create_update_status_payload(update_status)
|
213
|
+
_put(path, payload)
|
214
|
+
end
|
215
|
+
|
216
|
+
# REVIEW: Update a tool’s current status for all org units.
|
217
|
+
# => PUT /d2l/api/lp/(version)/tools/org/(toolId)/OUDefault/override
|
218
|
+
def update_all_org_unit_tool_status(tool_id, update_status)
|
219
|
+
path = "/d2l/api/lp/#{$lp_ver}/tools/org/#{tool_id}/OUDefault/override"
|
220
|
+
payload = check_and_create_update_status_payload(update_status)
|
221
|
+
_put(path, payload)
|
222
|
+
end
|
223
|
+
|
224
|
+
########################
|
225
|
+
# ORG UNITS:############
|
226
|
+
########################
|
227
|
+
|
228
|
+
# REVIEW: Retrieve the current information for all tools enabled for the provided org unit.
|
229
|
+
# => GET /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)
|
230
|
+
def get_org_enabled_tools_info(org_unit_id, bookmark = '')
|
231
|
+
path = "/d2l/api/lp/#{$lp_ver}/tools/orgUnits/#{org_unit_id}?"
|
232
|
+
path += "bookmark=#{bookmark}" unless bookmark == ''
|
233
|
+
_get(path)
|
234
|
+
end
|
235
|
+
|
236
|
+
# REVIEW: Retrieve the current information for a tool enabled for the provided org unit.
|
237
|
+
# => GET /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)/(toolId)
|
238
|
+
def get_org_enabled_tool_info(org_unit_id, tool_id)
|
239
|
+
path = "/d2l/api/lp/#{$lp_ver}/tools/orgUnits/#{org_unit_id}/#{tool_id}"
|
240
|
+
_get(path)
|
241
|
+
end
|
242
|
+
|
243
|
+
def check_org_unit_information_validity(data_block)
|
244
|
+
schema = {
|
245
|
+
'type' => 'object',
|
246
|
+
'required' => %w(ToolId DisplayName OrgUnitId Status CustomNavbarName),
|
247
|
+
'properties' => {
|
248
|
+
'ToolId' => { 'type' => 'string' },
|
249
|
+
'DisplayName' => { 'type' => 'string' },
|
250
|
+
'CallbackUrl' => { 'type' => 'integer' },
|
251
|
+
'Status' => { 'type' => 'boolean' },
|
252
|
+
'CustomNavbarName' => { 'type' => 'string' }
|
253
|
+
}
|
254
|
+
}
|
255
|
+
JSON::Validator.validate!(schema, data_block, validate_schema: true)
|
256
|
+
end
|
257
|
+
|
258
|
+
# REVIEW: Update the org unit-level information for a tool.
|
259
|
+
# INPUT: OrgUnitInformation JSON block
|
260
|
+
# => PUT /d2l/api/lp/(version)/tools/orgUnits/(orgUnitId)/(toolId)
|
261
|
+
def update_org_unit_level_tool_info(org_unit_id, tool_id, org_unit_information)
|
262
|
+
path = "/d2l/api/lp/#{$lp_ver}/tools/orgUnits/#{org_unit_id}/#{tool_id}"
|
263
|
+
payload =
|
264
|
+
{
|
265
|
+
"ToolId" => "", # <string:D2LID>
|
266
|
+
"DisplayName" => "", # <string> ## added with LP v1.6 API
|
267
|
+
"OrgUnitId" => 0, # D2LID:number
|
268
|
+
"Status" => false, # boolean
|
269
|
+
"CustomNavbarName" => "" # <string>
|
270
|
+
}.merge!(org_unit_information)
|
271
|
+
check_org_unit_information_validity(payload) # NOTE: Check this later.
|
272
|
+
_put(path, payload)
|
273
|
+
end
|