d2l_sdk 0.1.8 → 0.1.9

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.
@@ -3,6 +3,7 @@ require 'json-schema'
3
3
  ####################################
4
4
  # Groups/Group Categories:##########
5
5
  ####################################
6
+
6
7
  # Delete a particular group category from an org unit.
7
8
  def delete_group_category(org_unit_id, group_category_id)
8
9
  path = "/d2l/api/lp/#{$lp_ver}/#{org_unit_id}/groupcategories/#{group_category_id}"
@@ -4,6 +4,19 @@ require 'json-schema'
4
4
  # News:##########
5
5
  #################
6
6
 
7
+ # REVIEW: Delete a particular news item from an org unit.
8
+ def delete_news_item(org_unit_id, news_item_id)
9
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}"
10
+ _delete(path)
11
+ end
12
+
13
+ # REVIEW: Delete an attachment from an org unit’s news item.
14
+ def delete_news_item_attachment(org_unit_id, news_item_id, file_id)
15
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/attachments/#{file_id}"
16
+ _delete(path)
17
+ end
18
+
19
+ # REVIEW: Fetch the feed for the current user context.
7
20
  # if since not specified, only includes most 'recent' feed items
8
21
  # if since specified but until is not, all items since 'since' are fetched
9
22
  # if since and until are specified, all items between these two dates are fetched
@@ -18,3 +31,87 @@ def get_current_user_feed(since = "", _until = "")
18
31
  end
19
32
  _get(path)
20
33
  end
34
+
35
+ # REVIEW: Retrieve a list of news items for an org unit.
36
+ def get_org_unit_news_items(org_unit_id, since = "")
37
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/"
38
+ path += "?since=#{since}" if since != ""
39
+ _get(path)
40
+ end
41
+
42
+ # NOTE: UNSTABLE!!!
43
+ # REVIEW: Retrieve data blocks containing the properties of deleted news items.
44
+ def get_deleted_news(org_unit_id, global = nil)
45
+ # GET /d2l/api/le/(version)/(orgUnitId)/news/deleted/
46
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/deleted/"
47
+ path += "?global=#{global}" unless global.nil?
48
+ _get(path)
49
+ end
50
+
51
+ # REVIEW: Retrieve a particular news item for an org unit.
52
+ def get_org_unit_news_item(org_unit_id, news_item_id)
53
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}"
54
+ _get(path)
55
+ end
56
+
57
+ # REVIEW: Retrieve an attachment for an org unit’s news item.
58
+ def get_news_item_attachment(org_unit_id, news_item_id, file_id)
59
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/attachments/#{file_id}"
60
+ _get(path)
61
+ end
62
+
63
+
64
+ # TODO: Create a news item for an org unit.
65
+ # INPUT: multipart/mixed POST body
66
+ # part 1: news item data JSON
67
+ # part 2: attachments
68
+ def create_news_item(org_unit_id, news_item_data, attachments = [])
69
+ # POST /d2l/api/le/(version)/(orgUnitId)/news/
70
+ end
71
+
72
+ # NOTE: UNSTABLE!!!
73
+ # REVIEW: Restore a particular news item by its news_item_id
74
+ def restore_news_item(org_unit_id, news_item_id)
75
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/deleted/#{news_item_id}/restore"
76
+ _post(path, {})
77
+ end
78
+
79
+ # TODO: Add an attachment to a news item for an org unit.
80
+ # INPUT: Use a multipart/form-data POST body to provide the attachment data to
81
+ # add to the news item, with the part’s Content-Disposition header’s
82
+ # name field set to “file”.
83
+ def add_news_item_attachment(org_unit_id, news_item_id, attachment_data)
84
+ # POST /d2l/api/le/(version)/(orgUnitId)/news/(newsItemId)/attachments/
85
+ end
86
+
87
+ # REVIEW: Dismiss (hide) a news item for an org unit.
88
+ def hide_news_item(org_unit_id, news_item_id)
89
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/dismiss"
90
+ _post(path, {})
91
+ end
92
+
93
+ # REVIEW: Publish a draft news item for an org unit.
94
+ def publish_draft_news_item(org_unit_id, news_item_id)
95
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/publish"
96
+ _post(path, {})
97
+ end
98
+
99
+ # REVIEW: Restore (unhide) a news item for an org unit.
100
+ def unhide_news_item(org_unit_id, news_item_id)
101
+ path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/news/#{news_item_id}/restore"
102
+ _post(path, {})
103
+ end
104
+
105
+ # TODO: Update a news item for an org unit.
106
+ # INPUT: JSON Parameter of type NewsItemData (News.NewsItemData)
107
+ def update_news_item(org_unit_id, news_item_id, news_item_data)
108
+ # Example of News.NewsItemData JSON Data Block:
109
+ # {"Title" => "string",
110
+ # "Body" => {'Content' => "content", "Type" => "type"} # RichTextInput -- e.g. {'Content'=>'x', 'Type'=>'y'}
111
+ # "StartDate": "<string:UTCDateTime>",
112
+ # "EndDate": "<string:UTCDateTime>", # or nil
113
+ # "IsGlobal": false,
114
+ # "IsPublished": false,
115
+ # "ShowOnlyInCourseOfferings": false}
116
+ # PUT /d2l/api/le/(version)/(orgUnitId)/news/(newsItemId)
117
+ end
@@ -1,85 +1,48 @@
1
1
  require_relative 'requests'
2
2
  require 'json-schema'
3
+
3
4
  ########################
4
- # Org Units:############
5
+ # ACTIONS:##############
5
6
  ########################
6
7
 
7
-
8
- # gets all descendents of a particular org unit, as referenced by the
9
- # "org_unit_id" argument. A get request is then performed by a preformatted
10
- # path.
11
- def get_org_unit_descendants(org_unit_id, ou_type_id = 0)
12
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/descendants/"
13
- path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
14
- _get(path)
15
- # return JSON array of OrgUnit data blocks
16
- end
17
-
18
- # gets a paged result of the org unit's descendants. The descendants are
19
- # first referenced by a preformatted path; then if there is a defined bookmark,
20
- # the bookmark parameter is appended to the path.
21
- #
22
- # return: JSON array of org unit descendants (paged)
23
- def get_paged_org_unit_descendants(org_unit_id, ou_type_id = 0, bookmark = '')
24
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/descendants/paged/"
25
- path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
26
- path += "?bookmark=#{bookmark}" if bookmark != ''
27
- _get(path)
28
- # return paged json of org_unit descendants
29
- end
30
-
31
- # gets all parents of a particular org unit, as referenced by the
32
- # "org_unit_id" argument. A get request is then performed by a preformatted
33
- # path.
34
- def get_org_unit_parents(org_unit_id, ou_type_id = 0)
35
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/parents/"
36
- path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
8
+ # Retrieves the organization info. Only gets a small amount of information,
9
+ # but may be useful in some instances.
10
+ def get_organization_info
11
+ path = "/d2l/api/lp/#{$lp_ver}/organization/info"
37
12
  _get(path)
38
- # return json of org_unit parents
13
+ # return: Organization JSON block
39
14
  end
40
15
 
41
- # performs a post method to assign a parent to a particular child org unit.
42
- # This is done by first referencing all the parents of the +child_ou+ and then
43
- # POSTing the id of another org unit that is to be added to the parents.
44
- def add_parent_to_org_unit(parent_ou_id, child_ou_id)
45
- # Must follow structure of data
46
- # (course <-- semester <== org -->custom dept--> dept -->templates--> courses)
47
- # Refer to valence documentation for further structural understanding..
48
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{child_ou_id}/parents/"
49
- _post(path, parent_ou_id)
50
- end
16
+ ########################
17
+ # STRUCTURE:############
18
+ ########################
51
19
 
52
- # Gets all org unit ancestors. Simply, this method references all of the
53
- # ancestors of the particular org unit and then returns them in a JSON array.
54
- #
55
- # return: JSON array of org_unit ancestors.
56
- def get_org_unit_ancestors(org_unit_id, ou_type_id = 0)
57
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/ancestors/"
58
- path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
59
- _get(path)
60
- # return json of org_unit ancestors
20
+ # This deletes the relationship between a parent ou and a child ou by
21
+ # performing a delete method from the parent's children and specifying this
22
+ # child through its id.
23
+ def delete_relationship_of_child_with_parent(parent_ou_id, child_ou_id)
24
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{parent_ou_id}/children/#{child_ou_id}"
25
+ _delete(path)
61
26
  end
62
27
 
63
- # gets all children of a particular org unit, as referenced by the
64
- # "org_unit_id" argument. A get request is then performed by a preformatted
65
- # path.
66
- def get_org_unit_children(org_unit_id, ou_type_id = 0)
67
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/children/"
68
- path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
69
- _get(path)
70
- # return json of org_unit children
28
+ # This deletes the relationship between a child ou and a parent ou by
29
+ # performing a delete method from the child's parents and specifying this
30
+ # parent through its id.
31
+ def delete_relationship_of_parent_with_child(parent_ou_id, child_ou_id)
32
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{child_ou_id}/parents/#{parent_ou_id}"
33
+ _delete(path)
71
34
  end
72
35
 
73
- # Gets all children of the org unit, but in a paged result. These are first
74
- # referenced via the org_unit_id argument, and then a bookmark is appended
75
- # if there is one specified. This is then returned as a json array.
76
- #
77
- # return: JSON array of org unit children.
78
- def get_paged_org_unit_children(org_unit_id, bookmark = '')
79
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/children/paged/"
36
+ def get_properties_of_all_org_units(org_unit_type = '', org_unit_code = '', org_unit_name = '',
37
+ bookmark = '')
38
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/"
39
+ path += "?orgUnitType=#{org_unit_type}" if org_unit_type != ''
40
+ path += "?orgUnitCode=#{org_unit_code}" if org_unit_code != ''
41
+ path += "?orgUnitName=#{org_unit_name}" if org_unit_name != ''
80
42
  path += "?bookmark=#{bookmark}" if bookmark != ''
81
43
  _get(path)
82
- # return json of org_unit children
44
+ # ONLY RETRIEVES FIRST 100 after bookmark
45
+ # returns: paged result of OrgUnitProperties blocks
83
46
  end
84
47
 
85
48
  # gets all properties of a particular org unit, as referenced by the
@@ -91,22 +54,6 @@ def get_org_unit_properties(org_unit_id)
91
54
  # return json of org_unit properties
92
55
  end
93
56
 
94
- # This deletes the relationship between a parent ou and a child ou by
95
- # performing a delete method from the parent's children and specifying this
96
- # child through its id.
97
- def delete_relationship_of_child_with_parent(parent_ou_id, child_ou_id)
98
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{parent_ou_id}/children/#{child_ou_id}"
99
- _delete(path)
100
- end
101
-
102
- # This deletes the relationship between a child ou and a parent ou by
103
- # performing a delete method from the child's parents and specifying this
104
- # parent through its id.
105
- def delete_relationship_of_parent_with_child(parent_ou_id, child_ou_id)
106
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{child_ou_id}/parents/#{parent_ou_id}"
107
- _delete(path)
108
- end
109
-
110
57
  # This retrieves a paged result of all the childless org units within the
111
58
  # organization. As this is paged, it only retrieves the first 100 from the
112
59
  # beginning of the request. If bookmark is not specified, then it only retrieves
@@ -124,18 +71,6 @@ def get_all_childless_org_units(org_unit_type = '', org_unit_code = '', org_unit
124
71
  # ONLY RETRIEVES FIRST 100
125
72
  end
126
73
 
127
- def get_properties_of_all_org_units(org_unit_type = '', org_unit_code = '', org_unit_name = '',
128
- bookmark = '')
129
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/"
130
- path += "?orgUnitType=#{org_unit_type}" if org_unit_type != ''
131
- path += "?orgUnitCode=#{org_unit_code}" if org_unit_code != ''
132
- path += "?orgUnitName=#{org_unit_name}" if org_unit_name != ''
133
- path += "?bookmark=#{bookmark}" if bookmark != ''
134
- _get(path)
135
- # ONLY RETRIEVES FIRST 100 after bookmark
136
- # returns: paged result of OrgUnitProperties blocks
137
- end
138
-
139
74
  # Retrieves a paged result of all orphaned org units within the organization.
140
75
  # This is a paged result, so only for the first 100 from the beginning bookmark
141
76
  # are retrieved. Simply put, if the bookmark is not defined, it only gets the
@@ -152,50 +87,70 @@ def get_all_orphans(org_unit_type = '', org_unit_code = '', org_unit_name = '',
152
87
  _get(path)
153
88
  end
154
89
 
155
- # Adds a child to the org unit by using org_unit_id to reference the soon-to-be
156
- # parent of the child_org_unit and referencing the soon-to-be child through the
157
- # child_org_unit_id argument. Then, a path is created to reference the children
158
- # of the soon-to-be parent and executing a post http method that adds the child.
90
+ # Gets all org unit ancestors. Simply, this method references all of the
91
+ # ancestors of the particular org unit and then returns them in a JSON array.
159
92
  #
160
- # TL;DR, this adds a child org_unit to the children of an org_unit.
161
- def add_child_org_unit(org_unit_id, child_org_unit_id)
93
+ # return: JSON array of org_unit ancestors.
94
+ def get_org_unit_ancestors(org_unit_id, ou_type_id = 0)
95
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/ancestors/"
96
+ path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
97
+ _get(path)
98
+ # return json of org_unit ancestors
99
+ end
100
+
101
+ # gets all children of a particular org unit, as referenced by the
102
+ # "org_unit_id" argument. A get request is then performed by a preformatted
103
+ # path.
104
+ def get_org_unit_children(org_unit_id, ou_type_id = 0)
162
105
  path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/children/"
163
- _post(path, child_org_unit_id)
106
+ path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
107
+ _get(path)
108
+ # return json of org_unit children
164
109
  end
165
110
 
166
- # Retrieves a paged result of all recycled org units. Thus, only the first 100
167
- # are retrieved since the first referenced org unit. As such, if the bookmark is
168
- # not defined, then it only retrieves the first 100.
111
+ # Gets all children of the org unit, but in a paged result. These are first
112
+ # referenced via the org_unit_id argument, and then a bookmark is appended
113
+ # if there is one specified. This is then returned as a json array.
169
114
  #
170
- # return: JSON array of recycled org units.
171
- def get_recycled_org_units(bookmark = '')
172
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/"
115
+ # return: JSON array of org unit children.
116
+ def get_paged_org_unit_children(org_unit_id, bookmark = '')
117
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/children/paged/"
173
118
  path += "?bookmark=#{bookmark}" if bookmark != ''
174
119
  _get(path)
175
- # GETS ONLY FIRST 100
120
+ # return json of org_unit children
176
121
  end
177
122
 
178
- # An org unit is recycled by executing a POST http method and recycling it. The
179
- # path for the recycling is created using the org_unit_id argument and then the
180
- # post method is executed afterwards.
181
- def recycle_org_unit(org_unit_id)
182
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}/recycle"
183
- _post(path, {})
123
+ # gets all descendents of a particular org unit, as referenced by the
124
+ # "org_unit_id" argument. A get request is then performed by a preformatted
125
+ # path.
126
+ def get_org_unit_descendants(org_unit_id, ou_type_id = 0)
127
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/descendants/"
128
+ path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
129
+ _get(path)
130
+ # return JSON array of OrgUnit data blocks
184
131
  end
185
132
 
186
- # deletes a particular org unit. This is done via referencing the org unit by
187
- # its id and performing a delete method.
188
- def delete_recycled_org_unit(org_unit_id)
189
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}"
190
- _delete(path)
133
+ # gets a paged result of the org unit's descendants. The descendants are
134
+ # first referenced by a preformatted path; then if there is a defined bookmark,
135
+ # the bookmark parameter is appended to the path.
136
+ #
137
+ # return: JSON array of org unit descendants (paged)
138
+ def get_paged_org_unit_descendants(org_unit_id, ou_type_id = 0, bookmark = '')
139
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/descendants/paged/"
140
+ path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
141
+ path += "?bookmark=#{bookmark}" if bookmark != ''
142
+ _get(path)
143
+ # return paged json of org_unit descendants
191
144
  end
192
145
 
193
- # Restores a recycled org unit. This is done by referencing the org unit by its
194
- # id in the recycling bin and then appending '/restore'. This is then used in a
195
- # post method that performs the restoring process.
196
- def restore_recycled_org_unit(org_unit_id)
197
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}/restore"
198
- _post(path, {})
146
+ # gets all parents of a particular org unit, as referenced by the
147
+ # "org_unit_id" argument. A get request is then performed by a preformatted
148
+ # path.
149
+ def get_org_unit_parents(org_unit_id, ou_type_id = 0)
150
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/parents/"
151
+ path += "?ouTypeId=#{ou_type_id}" if ou_type_id != 0
152
+ _get(path)
153
+ # return json of org_unit parents
199
154
  end
200
155
 
201
156
  # Checks whether the created org unit data conforms to the valence api for the
@@ -234,6 +189,28 @@ def create_custom_org_unit(org_unit_data)
234
189
  # returns: OrgUnit JSON data block
235
190
  end
236
191
 
192
+ # Adds a child to the org unit by using org_unit_id to reference the soon-to-be
193
+ # parent of the child_org_unit and referencing the soon-to-be child through the
194
+ # child_org_unit_id argument. Then, a path is created to reference the children
195
+ # of the soon-to-be parent and executing a post http method that adds the child.
196
+ #
197
+ # TL;DR, this adds a child org_unit to the children of an org_unit.
198
+ def add_child_org_unit(org_unit_id, child_org_unit_id)
199
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/children/"
200
+ _post(path, child_org_unit_id)
201
+ end
202
+
203
+ # performs a post method to assign a parent to a particular child org unit.
204
+ # This is done by first referencing all the parents of the +child_ou+ and then
205
+ # POSTing the id of another org unit that is to be added to the parents.
206
+ def add_parent_to_org_unit(parent_ou_id, child_ou_id)
207
+ # Must follow structure of data
208
+ # (course <-- semester <== org -->custom dept--> dept -->templates--> courses)
209
+ # Refer to valence documentation for further structural understanding..
210
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{child_ou_id}/parents/"
211
+ _post(path, parent_ou_id)
212
+ end
213
+
237
214
  # Checks whether the updated org unit data conforms to the valence api for the
238
215
  # org unit data JSON object. If it does conform, then nothing happens and it
239
216
  # simply returns true. If it does not conform, then the JSON validator raises
@@ -286,23 +263,103 @@ def update_org_unit(org_unit_id, org_unit_data)
286
263
  # returns: OrgUnitProperties JSON data block
287
264
  end
288
265
 
289
- # Retrieves the organization info. Only gets a small amount of information,
290
- # but may be useful in some instances.
291
- def get_organization_info
292
- path = "/d2l/api/lp/#{$lp_ver}/organization/info"
293
- _get(path)
294
- # return: Organization JSON block
266
+
267
+ ########################
268
+ # COLOUR SCHEMES:#######
269
+ ########################
270
+
271
+ # REVIEW: Retrieve the colour scheme for an org unit.
272
+ # RETURNS: ColourScheme JSON data block containing the org unit’s current colour scheme.
273
+ def get_org_unit_color_scheme(org_unit_id)
274
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/colours"
275
+ # RETURNS: ColourScheme JSON data block containing the org unit’s current colour scheme.
295
276
  end
296
277
 
297
- # Retrieves the org units that are a particular id. This is done by obtaining
298
- # all of the children of the organization and then filtering by this id.
278
+ # TODO: Set a new colour scheme for an org unit.
279
+ # INPUT: JSON PARAM of type +colourScheme+ (OrgUnitEditor.ColourScheme)
280
+ # RETURNS: ColourScheme JSON data block containing the org unit’s new colour scheme.
281
+ def set_new_org_unit_color_scheme(org_unit_id, colour_scheme)
282
+ # PUT /d2l/api/lp/(version)/orgstructure/(orgUnitId)/colours
283
+ # RETURNS: ColourScheme JSON data block containing the org unit’s new colour scheme.
284
+ end
285
+
286
+ ########################
287
+ # RECYCLE BIN:##########
288
+ ########################
289
+
290
+ # deletes a particular org unit. This is done via referencing the org unit by
291
+ # its id and performing a delete method.
292
+ def delete_recycled_org_unit(org_unit_id)
293
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}"
294
+ _delete(path)
295
+ end
296
+
297
+ # Retrieves a paged result of all recycled org units. Thus, only the first 100
298
+ # are retrieved since the first referenced org unit. As such, if the bookmark is
299
+ # not defined, then it only retrieves the first 100.
299
300
  #
300
- # return: JSON array of all org units of an outype.
301
- def get_all_org_units_by_type_id(outype_id)
302
- path = "/d2l/api/lp/#{$lp_ver}/orgstructure/6606/children/?ouTypeId=#{outype_id}"
301
+ # return: JSON array of recycled org units.
302
+ def get_recycled_org_units(bookmark = '')
303
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/"
304
+ path += "?bookmark=#{bookmark}" if bookmark != ''
305
+ _get(path)
306
+ # GETS ONLY FIRST 100
307
+ end
308
+
309
+ # An org unit is recycled by executing a POST http method and recycling it. The
310
+ # path for the recycling is created using the org_unit_id argument and then the
311
+ # post method is executed afterwards.
312
+ def recycle_org_unit(org_unit_id)
313
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}/recycle"
314
+ _post(path, {})
315
+ end
316
+
317
+ # Restores a recycled org unit. This is done by referencing the org unit by its
318
+ # id in the recycling bin and then appending '/restore'. This is then used in a
319
+ # post method that performs the restoring process.
320
+ def restore_recycled_org_unit(org_unit_id)
321
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/recyclebin/#{org_unit_id}/restore"
322
+ _post(path, {})
323
+ end
324
+
325
+ ########################
326
+ # TYPES:################
327
+ ########################
328
+
329
+ # Delete a particular org unit type
330
+ def delete_outype(outype_id)
331
+ path = "/d2l/api/lp/#{$lp_ver}/outypes/#{outype_id}"
332
+ _delete(path)
333
+ end
334
+
335
+ # retrieves all outypes that are known and visible. This is returned as a JSON
336
+ # array of orgunittype data blocks.
337
+ def get_all_outypes
338
+ path = "/d2l/api/lp/#{$lp_ver}/outypes/"
339
+ _get(path)
340
+ end
341
+
342
+ # This retrieves information about a particular org unit type, referenced via
343
+ # the outype_id argument. This is then returned as a JSON object.
344
+ def get_outype(outype_id)
345
+ path = "/d2l/api/lp/#{$lp_ver}/outypes/#{outype_id}"
303
346
  _get(path)
304
347
  end
305
348
 
349
+ # retrieve org unit type of department org units
350
+ def get_department_outype
351
+ path = "/d2l/api/lp/#{$lp_ver}/outypes/department"
352
+ _get(path)
353
+ # returns OrgUnitType JSON data block
354
+ end
355
+
356
+ # retrieve org unit type of semester org units
357
+ def get_semester_outype
358
+ path = "/d2l/api/lp/#{$lp_ver}/outypes/semester"
359
+ _get(path)
360
+ # returns OrgUnitType JSON data block
361
+ end
362
+
306
363
  def check_create_org_unit_type_data_validity(org_unit_type_data)
307
364
  schema = {
308
365
  'type' => 'object',
@@ -332,20 +389,7 @@ def create_custom_outype(create_org_unit_type_data)
332
389
  # returns OrgUnitType JSON data block
333
390
  end
334
391
 
335
- # This retrieves information about a partituclar org unit type, referenced via
336
- # the outype_id argument. This is then returned as a JSON object.
337
- def get_outype(outype_id)
338
- path = "/d2l/api/lp/#{$lp_ver}/outypes/#{outype_id}"
339
- _get(path)
340
- end
341
-
342
- # retrieves all outypes that are known and visible. This is returned as a JSON
343
- # array of orgunittype data blocks.
344
- def get_all_outypes
345
- path = "/d2l/api/lp/#{$lp_ver}/outypes/"
346
- _get(path)
347
- end
348
-
392
+ # NOTE: You cannot update the org unit codes if they are default ouTypes
349
393
  # update a particular org unit type (with POST for some reason)
350
394
  def update_outype(outype_id, create_org_unit_type_data)
351
395
  payload =
@@ -362,22 +406,16 @@ def update_outype(outype_id, create_org_unit_type_data)
362
406
  # returns OrgUnitType JSON data block
363
407
  end
364
408
 
365
- # Delete a particular org unit type
366
- def delete_outype(outype_id)
367
- path = "/d2l/api/lp/#{$lp_ver}/outypes/#{outype_id}"
368
- _delete(path)
369
- end
409
+ ###########################
410
+ # Additional Functions:####
411
+ ###########################
370
412
 
371
- # retrieve org unit type of department org units
372
- def get_department_outype
373
- path = "/d2l/api/lp/#{$lp_ver}/outypes/department"
374
- _get(path)
375
- # returns OrgUnitType JSON data block
376
- end
377
413
 
378
- # retrieve org unit type of semester org units
379
- def get_semester_outype
380
- path = "/d2l/api/lp/#{$lp_ver}/outypes/semester"
381
- _get(path)
382
- # returns OrgUnitType JSON data block
414
+ # Retrieves the org units that are a particular id. This is done by obtaining
415
+ # all of the children of the organization and then filtering by this id.
416
+ #
417
+ # return: JSON array of all org units of an outype.
418
+ def get_all_org_units_by_type_id(outype_id)
419
+ path = "/d2l/api/lp/#{$lp_ver}/orgstructure/6606/children/?ouTypeId=#{outype_id}"
420
+ _get(path)
383
421
  end