d2l_sdk 0.1.10 → 0.1.11

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.
@@ -19,7 +19,7 @@ def get_all_logs(date_range_start, date_range_end, search = '', log_level = '',
19
19
  path += "&loggerAssembly=#{logger_assembly}" if logger_assembly != ''
20
20
  path += "&userId=#{user_id}" if user_id != 0
21
21
  path += "&messageGroupId=#{message_group_id}" if message_group_id != 0
22
- path += "&includeTraces=#{include_traces}" if include_traces != nil
22
+ path += "&includeTraces=#{include_traces}" unless include_traces.nil?
23
23
  path += "&orgUnitId=#{org_unit_id}" if org_unit_id != 0
24
24
  path += "&bookmark=#{bookmark}" if bookmark != ''
25
25
  ap path
@@ -51,7 +51,7 @@ end
51
51
  # retrieve identified log message
52
52
  def get_log_message(log_message_id, include_traces = nil)
53
53
  path = "/d2l/api/lp/#{$lp_ver}/logging/#{log_message_id}/"
54
- path += "?includeTraces=#{include_traces}" if include_traces != nil
54
+ path += "?includeTraces=#{include_traces}" unless include_traces.nil?
55
55
  _get(path)
56
56
  # returns Message JSON block
57
57
  end
@@ -5,30 +5,262 @@ require 'json-schema'
5
5
  ## ACTIONS: ######
6
6
  ##################
7
7
 
8
- # TODO: Remove an LTI link.
8
+ # REVIEW: Remove an LTI link.
9
9
  # => DELETE /d2l/api/le/(version)/lti/link/(ltiLinkId)
10
- # TODO: Retrieve the information for all LTI links registered for an org unit.
10
+ def delete_lti_link(lti_link_id)
11
+ path = "/d2l/api/le/#{$le_ver}/lti/link/#{lti_link_id}"
12
+ _delete(path)
13
+ end
14
+
15
+ # REVIEW: Retrieve the information for all LTI links registered for an org unit.
11
16
  # => GET /d2l/api/le/(version)/lti/link/(orgUnitId)/
12
- # TODO: Retrieve the information for a particular LTI link.
17
+ def get_org_unit_lti_links(org_unit_id)
18
+ path = "/d2l/api/le/#{$le_ver}/lti/link/#{org_unit_id}/"
19
+ _get(path)
20
+ end
21
+
22
+ # REVIEW: Retrieve the information for a particular LTI link.
13
23
  # => GET /d2l/api/le/(version)/lti/link/(orgUnitId)/(ltiLinkId)
14
- # TODO: Register a new LTI link for an org unit.
24
+ def get_lti_link_info(org_unit_id, lti_link_id)
25
+ path = "/d2l/api/le/#{$le_ver}/lti/link/#{org_unit_id}/#{lti_link_id}"
26
+ _get(path)
27
+ end
28
+
29
+ def check_create_lti_link_data_validity(create_lti_link_data)
30
+ schema = {
31
+ 'type' => 'object',
32
+ 'required' => %w(Title Url Description Key PlainSecret
33
+ IsVisible SignMessage SignWithTc SendTcInfo
34
+ SendContextInfo SendUserId SendUserName SendUserEmail
35
+ SendLinkTitle SendLinkDescription SendD2LUserName
36
+ SendD2LOrgDefinedId SendD2LOrgRoleId
37
+ UseToolProviderSecuritySettings CustomParameters),
38
+ 'properties' =>
39
+ {
40
+ 'Title' => { 'type' => 'string' },
41
+ 'Url' => { 'type' => 'string' },
42
+ 'Description' => { 'type' => 'string' },
43
+ 'Key' => { 'type' => 'string' },
44
+ 'PlainSecret' => { 'type' => 'string' },
45
+ 'IsVisible' => { 'type' => 'boolean' },
46
+ 'SignMessage' => { 'type' => 'boolean' },
47
+ 'SignWithTc' => { 'type' => 'boolean' },
48
+ 'SendTcInfo' => { 'type' => 'boolean' },
49
+ 'SendContextInfo' => { 'type' => 'boolean' },
50
+ 'SendUserId' => { 'type' => 'boolean' },
51
+ 'SendUserName' => { 'type' => 'boolean' },
52
+ 'SendUserEmail' => { 'type' => 'boolean' },
53
+ 'SendLinkTitle' => { 'type' => 'boolean' },
54
+ 'SendLinkDescription' => { 'type' => 'boolean' },
55
+ 'SendD2LUserName' => { 'type' => 'boolean' },
56
+ 'SendD2LOrgDefinedId' => { 'type' => 'boolean' },
57
+ 'SendD2LOrgRoleId' => { 'type' => 'boolean' },
58
+ 'UseToolProviderSecuritySettings' => { 'type' => 'boolean' },
59
+ 'CustomParameters' =>
60
+ { # define the CustomParameter array
61
+ # 'description' => 'The array of CustomParameters
62
+ 'type' => %w(array null),
63
+ 'items' =>
64
+ {
65
+ 'type' => 'object',
66
+ "properties" =>
67
+ {
68
+ "Name" => { 'type' => 'string' },
69
+ "Value" => { 'type' => 'string' }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ JSON::Validator.validate!(schema, create_lti_link_data, validate_schema: true)
76
+ end
77
+
78
+ # REVIEW: Register a new LTI link for an org unit.
15
79
  # => POST /d2l/api/le/(version)/lti/link/(orgUnitId)
16
- # TODO: Build a new quicklink around an existing LTI link.
80
+ def register_lti_link(org_unit_id, create_lti_link_data)
81
+ path = "/d2l/api/le/#{$le_ver}/lti/link/#{org_unit_id}"
82
+ payload = {
83
+ 'Title' => '',
84
+ 'Url' => '',
85
+ 'Description' => '',
86
+ 'Key' => '',
87
+ 'PlainSecret' => '',
88
+ 'IsVisible' => false,
89
+ 'SignMessage' => false,
90
+ 'SignWithTc' => false,
91
+ 'SendTcInfo' => false,
92
+ 'SendContextInfo' => false,
93
+ 'SendUserId' => false,
94
+ 'SendUserName' => false,
95
+ 'SendUserEmail' => false,
96
+ 'SendLinkTitle' => false,
97
+ 'SendLinkDescription' => false,
98
+ 'SendD2LUserName' => false,
99
+ 'SendD2LOrgDefinedId' => false,
100
+ 'SendD2LOrgRoleId' => false,
101
+ 'UseToolProviderSecuritySettings' => false,
102
+ 'CustomParameters' => nil # or Array of CustomParameter
103
+ # e.g. [{"Name" => "", "Value" => ""},{"Name" => "", "Value" => ""}]
104
+ }.merge!(create_lti_link_data)
105
+ check_create_lti_link_data_validity(payload)
106
+ _post(path, payload)
107
+ end
108
+
109
+
110
+ # REVIEW: Build a new quicklink around an existing LTI link.
17
111
  # => POST /d2l/api/le/(version)/lti/quicklink/(orgUnitId)/(ltiLinkId)
18
- # TODO: Update the information associated with a registered LTI link.
112
+ def create_lti_quicklink(org_unit_id, lti_link_id)
113
+ path = "/d2l/api/le/#{$le_ver}/lti/quicklink/#{org_unit_id}/#{lti_link_id}"
114
+ _post(path, {})
115
+ end
116
+
117
+ # REVIEW: Update the information associated with a registered LTI link.
19
118
  # => PUT /d2l/api/le/(version)/lti/link/(ltiLinkId)
119
+ def update_lti_link(lti_link_id, create_lti_link_data)
120
+ path = "/d2l/api/le/#{$le_ver}/lti/link/#{lti_link_id}"
121
+ payload = {
122
+ 'Title' => '',
123
+ 'Url' => '',
124
+ 'Description' => '',
125
+ 'Key' => '',
126
+ 'PlainSecret' => '',
127
+ 'IsVisible' => false,
128
+ 'SignMessage' => false,
129
+ 'SignWithTc' => false,
130
+ 'SendTcInfo' => false,
131
+ 'SendContextInfo' => false,
132
+ 'SendUserId' => false,
133
+ 'SendUserName' => false,
134
+ 'SendUserEmail' => false,
135
+ 'SendLinkTitle' => false,
136
+ 'SendLinkDescription' => false,
137
+ 'SendD2LUserName' => false,
138
+ 'SendD2LOrgDefinedId' => false,
139
+ 'SendD2LOrgRoleId' => false,
140
+ 'UseToolProviderSecuritySettings' => false,
141
+ 'CustomParameters' => nil # or Array of CustomParameter
142
+ # e.g. [{"Name" => "", "Value" => ""},{"Name" => "", "Value" => ""}]
143
+ }.merge!(create_lti_link_data)
144
+ check_create_lti_link_data_validity(payload)
145
+ _put(path, payload)
146
+ end
20
147
 
21
148
  #############################
22
149
  ## LTI TOOL PROVIDERS: ######
23
150
  #############################
24
151
 
25
- # TODO: Remove the registration for an LTI tool provider.
152
+ # REVIEW: Remove the registration for an LTI tool provider.
26
153
  # => DELETE /d2l/api/le/(version)/lti/tp/(tpId)
27
- # TODO: Retrieve the information for all LTI tool providers registered for an org unit.
154
+ def delete_LTI_tool_provider_registration(tp_id)
155
+ path = "/d2l/api/le/#{$le_ver}/lti/tp/#{tp_id}"
156
+ _delete(path)
157
+ end
158
+
159
+ # REVIEW: Retrieve the information for all LTI tool providers registered for an org unit.
28
160
  # => GET /d2l/api/le/(version)/lti/tp/(orgUnitId)/
29
- # TODO: Retrieve the information for a particular LTI tool provider.
161
+ def get_org_unit_lti_tool_providers(org_unit_id)
162
+ path = "/d2l/api/le/#{$le_ver}/lti/tp/#{org_unit_id}/"
163
+ _get(path)
164
+ end
165
+
166
+ # REVIEW: Retrieve the information for a particular LTI tool provider.
30
167
  # => GET /d2l/api/le/(version)/lti/tp/(orgUnitId)/(tpId)
31
- # TODO: Register a new LTI tool provider for an org unit.
168
+ def get_lti_tool_provider_information(org_unit_id, tp_id)
169
+ path = "/d2l/api/le/#{$le_ver}/lti/tp/#{org_unit_id}/#{tp_id}"
170
+ _get(path)
171
+ end
172
+
173
+ # Schema to check the CreateLtiProviderData JSON block validity.
174
+ def check_create_lti_provider_data_validity(create_lti_provider_data)
175
+ schema = {
176
+ 'type' => 'object',
177
+ 'required' => %w(LaunchPoint Secret UseDefaultTcInfo Key Name
178
+ Description ContactEmail SendTcInfo
179
+ SendContextInfo SendUserId SendUserName SendUserEmail
180
+ SendLinkTitle SendLinkDescription SendD2LUserName
181
+ SendD2LOrgDefinedId SendD2LOrgRoleId),
182
+ 'properties' =>
183
+ {
184
+ 'LaunchPoint' => { 'type' => 'string' },
185
+ 'Secret' => { 'type' => 'string' },
186
+ 'UseDefaultTcInfo' => { 'type' => 'string' },
187
+ 'Key' => { 'type' => 'string' },
188
+ 'Name' => { 'type' => 'string' },
189
+ 'Description' => { 'type' => 'string' },
190
+ 'ContactEmail' => { 'type' => 'string' },
191
+ 'IsVisible' => { 'type' => 'boolean' },
192
+ 'SendTcInfo' => { 'type' => 'boolean' }, # LE's 1.12+
193
+ 'SendContextInfo' => { 'type' => 'boolean' }, # LE's 1.12+
194
+ 'SendUserId' => { 'type' => 'boolean' }, # LE's 1.12+
195
+ 'SendUserName' => { 'type' => 'boolean' }, # LE's 1.12+
196
+ 'SendUserEmail' => { 'type' => 'boolean' }, # LE's 1.12+
197
+ 'SendLinkTitle' => { 'type' => 'boolean' }, # LE's 1.12+
198
+ 'SendLinkDescription' => { 'type' => 'boolean' }, # LE's 1.12+
199
+ 'SendD2LUserName' => { 'type' => 'boolean' }, # LE's 1.12+
200
+ 'SendD2LOrgDefinedId' => { 'type' => 'boolean' }, # LE's 1.12+
201
+ 'SendD2LOrgRoleId' => { 'type' => 'boolean' } # LE's 1.12+
202
+ }
203
+ }
204
+ JSON::Validator.validate!(schema, create_lti_provider_data, validate_schema: true)
205
+ end
206
+
207
+ # REVIEW: Register a new LTI tool provider for an org unit.
32
208
  # => POST /d2l/api/le/(version)/lti/tp/(orgUnitId)
33
- # TODO: Update the information associated with a registered LTI tool provider.
209
+ # INPUT: LTI.CreateLtiProviderData
210
+ def register_lti_tool_provider(org_unit_id, create_lti_provider_data)
211
+ path = "/d2l/api/le/#{$le_ver}/lti/tp/#{org_unit_id}"
212
+ payload = {
213
+ 'LaunchPoint' => '',
214
+ 'Secret' => '',
215
+ 'UseDefaultTcInfo' => '',
216
+ 'Key' => '',
217
+ 'Name' => '',
218
+ 'Description' => '',
219
+ 'ContactEmail' => '',
220
+ 'IsVisible' => false,
221
+ 'SendTcInfo' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
222
+ 'SendContextInfo' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
223
+ 'SendUserId' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
224
+ 'SendUserName' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
225
+ 'SendUserEmail' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
226
+ 'SendLinkTitle' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
227
+ 'SendLinkDescription' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
228
+ 'SendD2LUserName' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
229
+ 'SendD2LOrgDefinedId' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
230
+ 'SendD2LOrgRoleId' => false # Appears in LE's 1.12+ contract as of LE v10.6.0
231
+ }.merge!(create_lti_provider_data)
232
+ check_create_lti_provider_data_validity(payload)
233
+ _post(path, payload)
234
+ # RETURNS: a LtiToolProviderData JSON block
235
+ end
236
+
237
+
238
+ # REVIEW: Update the information associated with a registered LTI tool provider.
34
239
  # => PUT /d2l/api/le/(version)/lti/tp/(tpId)
240
+ # INPUT: LTI.CreateLtiProviderData
241
+ def update_lti_tool_provider(tp_id, create_lti_provider_data)
242
+ path = "/d2l/api/le/#{$le_ver}/lti/tp/#{tp_id}" # tp_id = tool provider id
243
+ payload = {
244
+ 'LaunchPoint' => '',
245
+ 'Secret' => '',
246
+ 'UseDefaultTcInfo' => '',
247
+ 'Key' => '',
248
+ 'Name' => '',
249
+ 'Description' => '',
250
+ 'ContactEmail' => '',
251
+ 'IsVisible' => false,
252
+ 'SendTcInfo' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
253
+ 'SendContextInfo' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
254
+ 'SendUserId' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
255
+ 'SendUserName' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
256
+ 'SendUserEmail' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
257
+ 'SendLinkTitle' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
258
+ 'SendLinkDescription' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
259
+ 'SendD2LUserName' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
260
+ 'SendD2LOrgDefinedId' => false, # Appears in LE's 1.12+ contract as of LE v10.6.0
261
+ 'SendD2LOrgRoleId' => false # Appears in LE's 1.12+ contract as of LE v10.6.0
262
+ }.merge!(create_lti_provider_data)
263
+ check_create_lti_provider_data_validity(payload)
264
+ _put(path, payload)
265
+ # RETURNS: a LtiToolProviderData JSON block
266
+ end
@@ -22,12 +22,12 @@ end
22
22
  # if since and until are specified, all items between these two dates are fetched
23
23
  # if since > until, an empty feed list is returned
24
24
  # purpose: fetch the feed for the current user context
25
- def get_current_user_feed(since = "", _until = "")
25
+ def get_current_user_feed(since = "", until_ = "")
26
26
  path = "/d2l/api/lp/#{$lp_ver}/feed/"
27
27
  # if since is specified, then until can be. Until is not required though.
28
28
  if since != ""
29
29
  path += "?since=#{since}"
30
- path += "&until=#{_until}" if _until != ""
30
+ path += "&until=#{until_}" if until_ != ""
31
31
  end
32
32
  _get(path)
33
33
  end
@@ -34,7 +34,7 @@ def delete_relationship_of_parent_with_child(parent_ou_id, child_ou_id)
34
34
  end
35
35
 
36
36
  def get_properties_of_all_org_units(org_unit_type = '', org_unit_code = '', org_unit_name = '',
37
- bookmark = '')
37
+ bookmark = '')
38
38
  path = "/d2l/api/lp/#{$lp_ver}/orgstructure/"
39
39
  path += "?orgUnitType=#{org_unit_type}" if org_unit_type != ''
40
40
  path += "?orgUnitCode=#{org_unit_code}" if org_unit_code != ''
@@ -165,9 +165,10 @@ def check_org_unit_data_validity(org_unit_data)
165
165
  'Type' => { 'type' => 'integer' },
166
166
  'Name' => { 'type' => 'string' },
167
167
  'Code' => { 'type' => 'string' },
168
- 'Parents' => { 'type' => 'array',
169
- 'items' => { 'type' => 'integer', 'minItems' => 1 }
170
- }
168
+ 'Parents' => {
169
+ 'type' => 'array',
170
+ 'items' => { 'type' => 'integer', 'minItems' => 1 }
171
+ }
171
172
  }
172
173
  }
173
174
  JSON::Validator.validate!(schema, org_unit_data, validate_schema: true)
@@ -177,11 +178,12 @@ end
177
178
  def create_custom_org_unit(org_unit_data)
178
179
  # Requires the type to have the correct parent. This will work fine in this
179
180
  # sample, as the department (101) can have the parent Organiation (6606)
180
- payload = { 'Type' => 101, # Number:D2LID
181
- 'Name' => 'custom_ou_name', # String
182
- 'Code' => 'custom_ou_code', # String
183
- 'Parents' => [6606], # Number:D2LID
184
- }.merge!(org_unit_data)
181
+ payload = {
182
+ 'Type' => 101, # Number:D2LID
183
+ 'Name' => 'custom_ou_name', # String
184
+ 'Code' => 'custom_ou_code', # String
185
+ 'Parents' => [6606], # Number:D2LID
186
+ }.merge!(org_unit_data)
185
187
  check_org_unit_data_validity(payload)
186
188
  path = "/d2l/api/lp/#{$lp_ver}/orgstructure/"
187
189
  # Requires: OrgUnitCreateData JSON block
@@ -268,20 +270,20 @@ end
268
270
  # COLOUR SCHEMES:#######
269
271
  ########################
270
272
 
271
- # REVIEW: Retrieve the colour scheme for an org unit.
273
+ # TODO: Retrieve the colour scheme for an org unit.
272
274
  # 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
+ # def get_org_unit_color_scheme(org_unit_id)
276
+ # path = "/d2l/api/lp/#{$lp_ver}/orgstructure/#{org_unit_id}/colours"
275
277
  # RETURNS: ColourScheme JSON data block containing the org unit’s current colour scheme.
276
- end
278
+ # end
277
279
 
278
280
  # TODO: Set a new colour scheme for an org unit.
279
281
  # INPUT: JSON PARAM of type +colourScheme+ (OrgUnitEditor.ColourScheme)
280
282
  # 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)
283
+ # def set_new_org_unit_color_scheme(org_unit_id, colour_scheme)
282
284
  # PUT /d2l/api/lp/(version)/orgstructure/(orgUnitId)/colours
283
285
  # RETURNS: ColourScheme JSON data block containing the org unit’s new colour scheme.
284
- end
286
+ # end
285
287
 
286
288
  ########################
287
289
  # RECYCLE BIN:##########
@@ -368,7 +370,7 @@ def check_create_org_unit_type_data_validity(org_unit_type_data)
368
370
  'Code' => { 'type' => 'string' },
369
371
  'Name' => { 'type' => 'string' },
370
372
  'Description' => { 'type' => 'string' },
371
- 'SortOrder' => { 'type' => 'integer'}
373
+ 'SortOrder' => { 'type' => 'integer' }
372
374
  }
373
375
  }
374
376
  JSON::Validator.validate!(schema, org_unit_type_data, validate_schema: true)
@@ -382,7 +384,7 @@ def create_custom_outype(create_org_unit_type_data)
382
384
  'Description' => '',
383
385
  'SortOrder' => 0
384
386
  }.merge!(create_org_unit_type_data)
385
- #validate schema
387
+ # validate schema
386
388
  check_create_org_unit_type_data_validity(payload)
387
389
  path = "/d2l/api/lp/#{$lp_ver}/outypes/"
388
390
  _post(path, payload)
@@ -399,7 +401,7 @@ def update_outype(outype_id, create_org_unit_type_data)
399
401
  'Description' => '',
400
402
  'SortOrder' => 0
401
403
  }.merge!(create_org_unit_type_data)
402
- #validate schema
404
+ # validate schema
403
405
  check_create_org_unit_type_data_validity(payload)
404
406
  path = "/d2l/api/lp/#{$lp_ver}/outypes/#{outype_id}"
405
407
  _post(path, payload)
@@ -21,7 +21,7 @@ def _get(path, isD2l = true)
21
21
  ap uri_string if @debug
22
22
  RestClient.get(uri_string) do |response, _request, _result|
23
23
  begin
24
- #ap _request
24
+ # ap _request
25
25
  case response.code
26
26
  when 200
27
27
  # ap JSON.parse(response) # Here is the JSON fmt'd response printed
@@ -30,7 +30,7 @@ def _get(path, isD2l = true)
30
30
  display_response_code(response.code)
31
31
  ap JSON.parse(response.body) if @debug
32
32
  end
33
- rescue => e
33
+ rescue # => e
34
34
  display_response_code(response.code)
35
35
  ap JSON.parse(response.body) if @debug
36
36
  raise
@@ -51,7 +51,7 @@ def _get_raw(path, isD2l = true)
51
51
  display_response_code(response.code)
52
52
  ap response.body
53
53
  end
54
- rescue => e
54
+ rescue # => e
55
55
  display_response_code(response.code)
56
56
  ap response.body
57
57
  raise
@@ -81,6 +81,36 @@ def _post(path, payload, isD2l = true)
81
81
  end
82
82
  end
83
83
 
84
+ # performs a put request using the path and the payload arguments. After first
85
+ # creating an authenticated uri, the put request is performed using the
86
+ # authenticated uri, the payload argument, and specifying that the payload is
87
+ # formatted in JSON.
88
+ def _put(path, payload, isD2l = true)
89
+ auth_uri = path
90
+ auth_uri = create_authenticated_uri(path, 'PUT') if isD2l == true
91
+ # Perform the put action, updating the data; Provide feedback to client.
92
+ RestClient.put(auth_uri, payload.to_json, content_type: :json) do |response|
93
+ case response.code
94
+ when 200
95
+ return nil if response == ""
96
+ JSON.parse(response)
97
+ # ap JSON.parse(response.body)
98
+ else
99
+ display_response_code(response.code)
100
+ ap JSON.parse(response.body) if $debug
101
+ end
102
+ end
103
+ end
104
+
105
+ # Performs a delete request by creating an authenticated uri and using the
106
+ # RestClient delete method and specifying the content_type as being JSON.
107
+ def _delete(path, isD2l = true, headers = {})
108
+ headers[:content_type] = :json
109
+ auth_uri = path
110
+ auth_uri = create_authenticated_uri(path, 'DELETE') if isD2l == true
111
+ RestClient.delete(auth_uri, headers)
112
+ end
113
+
84
114
  # NOTE: multipart code examples referrenced from danielwestendorf--
85
115
  # FTC 1867 and FTC 2388 implementations are based upon the following url:
86
116
  # => "https://coderwall.com/p/c-mu-a/http-posts-in-ruby"
@@ -95,12 +125,12 @@ def _learning_repository_upload(path, file, method)
95
125
  # file = the File's name in the directory.
96
126
  # method = POST or PUT
97
127
  # json = the json appended to the end of the request body
98
- auth_uri = path
128
+ # auth_uri = path
99
129
  auth_uri = create_authenticated_uri(path, method)
100
130
  uri = URI.parse(auth_uri)
101
131
 
102
132
  boundary = "xxBOUNDARYxx"
103
- header = {"Content-Type" => "multipart/form-data; boundary=#{boundary}"}
133
+ header = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" }
104
134
  # setup the post body
105
135
  post_body = []
106
136
  post_body << "--#{boundary}\n"
@@ -119,19 +149,50 @@ def _learning_repository_upload(path, file, method)
119
149
  JSON.parse(response)
120
150
  end
121
151
 
122
- # REVIEW: profile image upload process
123
- def _profile_image_upload(path, file, method)
152
+ # Upload a file to the learning repository.
153
+ def _course_package_upload(path, file, method)
154
+ # name = the content name,
155
+ # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers"
156
+ # file = the File's name in the directory.
157
+ # method = POST or PUT
158
+ # json = the json appended to the end of the request body
159
+ # auth_uri = path
160
+ auth_uri = create_authenticated_uri(path, method)
161
+ uri = URI.parse(auth_uri)
162
+
163
+ boundary = "xxBOUNDARYxx"
164
+ header = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" }
165
+ # setup the post body
166
+ post_body = []
167
+ post_body << "--#{boundary}\n"
168
+ post_body << "Content-Disposition: form-data; name = \"Resource\"; filename=\"#{File.basename(file)}\"\r\n"
169
+ post_body << "Content-Type: #{MIME::Types.type_for(file)}\r\n\r\n"
170
+ post_body << File.read(file)
171
+ post_body << "\r\n\r\n--#{boundary}--\r\n"
172
+
173
+ # Create the HTTP objects
174
+ http = Net::HTTP.new(uri.host, uri.port)
175
+ request = Net::HTTP::Post.new(uri.request_uri, header)
176
+ request.body = post_body.join
177
+
178
+ # Send the request
179
+ response = http.request(request)
180
+ JSON.parse(response)
181
+ end
182
+
183
+ # REVIEW: image upload process
184
+ def _image_upload(path, file, method)
124
185
  # name = the content name,
125
186
  # e.g. "Resource", "profileImage", "name", "description", "file", "targetUsers"
126
187
  # file = the File's name in the directory.
127
188
  # method = POST or PUT
128
189
  # json = the json appended to the end of the request body
129
- auth_uri = path
190
+ # auth_uri = path
130
191
  auth_uri = create_authenticated_uri(path, method)
131
192
  uri = URI.parse(auth_uri)
132
193
 
133
194
  boundary = "xxBOUNDARYxx"
134
- header = {"Content-Type" => "multipart/form-data; boundary=#{boundary}"}
195
+ header = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" }
135
196
  # setup the post body
136
197
  post_body = []
137
198
  post_body << "--#{boundary}\n"
@@ -156,12 +217,12 @@ def _ePortfolio_upload(path, file, method, description)
156
217
  # filename = the File's name in the directory.
157
218
  # method = POST or PUT
158
219
  # json = the json appended to the end of the request body
159
- auth_uri = path
220
+ # auth_uri = path
160
221
  auth_uri = create_authenticated_uri(path, method)
161
222
  uri = URI.parse(auth_uri)
162
223
 
163
224
  boundary = "xxBOUNDARYxx"
164
- header = {"Content-Type" => "multipart/form-data; boundary=#{boundary}"}
225
+ header = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" }
165
226
  # setup the post body
166
227
  post_body = []
167
228
  post_body << "--#{boundary}\r\n"
@@ -196,12 +257,12 @@ def _course_content_upload(path, json, file, method)
196
257
  # filename = the File's name in the directory.
197
258
  # method = POST or PUT
198
259
  # json = the json appended to the end of the request body
199
- auth_uri = path
260
+ # auth_uri = path
200
261
  auth_uri = create_authenticated_uri(path, method)
201
262
  uri = URI.parse(auth_uri)
202
263
 
203
264
  boundary = "xxBOUNDARYxx"
204
- header = {"Content-Type" => "multipart/mixed; boundary=#{boundary}"}
265
+ header = { "Content-Type" => "multipart/mixed; boundary=#{boundary}" }
205
266
  # setup the post body
206
267
  post_body = []
207
268
  post_body << "--#{boundary}\r\n"
@@ -232,12 +293,12 @@ def _dropbox_upload(path, json, file, method)
232
293
  # filename = the File's name in the directory.
233
294
  # method = POST or PUT
234
295
  # json = the json appended to the end of the request body
235
- auth_uri = path
296
+ # auth_uri = path
236
297
  auth_uri = create_authenticated_uri(path, method)
237
298
  uri = URI.parse(auth_uri)
238
299
 
239
300
  boundary = "xxBOUNDARYxx"
240
- header = {"Content-Type" => "multipart/mixed; boundary=#{boundary}"}
301
+ header = { "Content-Type" => "multipart/mixed; boundary=#{boundary}" }
241
302
  # setup the post body
242
303
  post_body = []
243
304
  post_body << "--#{boundary}\r\n"
@@ -270,12 +331,12 @@ def _news_upload(path, json, files, method)
270
331
  # files = array of filenames
271
332
  # method = POST or PUT
272
333
  # json = the json appended to the end of the request body
273
- auth_uri = path
334
+ # auth_uri = path
274
335
  auth_uri = create_authenticated_uri(path, method)
275
336
  uri = URI.parse(auth_uri)
276
337
 
277
338
  boundary = "xxBOUNDARYxx"
278
- header = {"Content-Type" => "multipart/mixed; boundary=#{boundary}"}
339
+ header = { "Content-Type" => "multipart/mixed; boundary=#{boundary}" }
279
340
  # setup the post body
280
341
  post_body = []
281
342
  post_body << "--#{boundary}\r\n"
@@ -305,25 +366,12 @@ def _news_upload(path, json, files, method)
305
366
  response.body
306
367
  end
307
368
 
308
- # performs a put request using the path and the payload arguments. After first
309
- # creating an authenticated uri, the put request is performed using the
310
- # authenticated uri, the payload argument, and specifying that the payload is
311
- # formatted in JSON.
312
- def _put(path, payload, isD2l = true)
313
- auth_uri = path
314
- auth_uri = create_authenticated_uri(path, 'PUT') if isD2l == true
315
- # Perform the put action, updating the data; Provide feedback to client.
316
- RestClient.put(auth_uri, payload.to_json, content_type: :json)
369
+ # bridge function ~~~
370
+ def _upload_post_data(path, json, files, method)
371
+ _news_upload(path, json, files, method)
317
372
  end
318
373
 
319
- # Performs a delete request by creating an authenticated uri and using the
320
- # RestClient delete method and specifying the content_type as being JSON.
321
- def _delete(path, isD2l = true, headers = {})
322
- headers[:content_type] = :json
323
- auth_uri = path
324
- auth_uri = create_authenticated_uri(path, 'DELETE') if isD2l == true
325
- RestClient.delete(auth_uri, headers)
326
- end
374
+
327
375
 
328
376
  # based upon the specific code that is returned from the http method, this
329
377
  # displays the response, in the case that it is an error within the request
@@ -334,41 +382,29 @@ end
334
382
  # the docs.valence.desire2learn.com website.
335
383
  def display_response_code(code)
336
384
  case code
337
- when 400
338
- puts '[!] 400: Bad Request'
339
- when 401
340
- puts '[!] 401: Unauthorized'
341
-
342
- when 403
343
- print '[!] Error Code Forbidden 403: accessing the page or resource '\
344
- 'you were trying to reach is absolutely forbidden for some reason.'
345
- when 404
346
- puts '[!] 404: Not Found'
347
- when 405
348
- puts '[!] 405: Method Not Allowed'
349
- when 406
350
- puts 'Unacceptable Type'\
351
- 'Unable to provide content type matching the client\'s Accept header.'
352
- when 412
353
- puts '[!] 412: Precondition failed\n'\
354
- 'Unsupported or invalid parameters, or missing required parameters.'
355
- when 415
356
- puts '[!] 415: Unsupported Media Type'\
357
- 'A PUT or POST payload cannot be accepted.'
358
- when 423
359
- puts '[!] 423'
360
- when 500
361
- puts '[!] 500: General Service Error\n'\
362
- 'Empty response body. The service has encountered an unexpected'\
363
- 'state and cannot continue to handle your action request.'
364
- when 504
365
- puts '[!] 504: Service Error'
385
+ when 400 then puts '[!] 400: Bad Request'
386
+ when 401 then puts '[!] 401: Unauthorized'
387
+ when 403 then puts '[!] Error Code Forbidden 403: accessing the page or resource '\
388
+ 'you were trying to reach is absolutely forbidden for some reason.'
389
+ when 404 then puts '[!] 404: Not Found'
390
+ when 405 then puts '[!] 405: Method Not Allowed'
391
+ when 406 then puts 'Unacceptable Type'\
392
+ 'Unable to provide content type matching the client\'s Accept header.'
393
+ when 412 then puts '[!] 412: Precondition failed\n'\
394
+ 'Unsupported or invalid parameters, or missing required parameters.'
395
+ when 415 then puts '[!] 415: Unsupported Media Type'\
396
+ 'A PUT or POST payload cannot be accepted.'
397
+ when 423 then puts '[!] 423'
398
+ when 500 then puts '[!] 500: General Service Error\n'\
399
+ 'Empty response body. The service has encountered an unexpected'\
400
+ 'state and cannot continue to handle your action request.'
401
+ when 504 then puts '[!] 504: Service Error'
366
402
  end
367
403
  end
368
404
 
369
- #################
370
- ###Versions######
371
- #################
405
+ ##################
406
+ ### Versions #####
407
+ ##################
372
408
  def get_all_products_supported_versions
373
409
  path = "/d2l/api/versions/"
374
410
  _get(path)
@@ -400,7 +436,7 @@ def get_versions
400
436
  # returns: SupportedVersion JSON block
401
437
  end
402
438
 
403
- #determine if a specific product component supports a particular API version
439
+ # determine if a specific product component supports a particular API version
404
440
  def check_if_product_supports_api_version(product_code, version)
405
441
  path = "/d2l/api/#{product_code}/versions/#{version}"
406
442
  _get(path)
@@ -414,8 +450,8 @@ def check_supported_version_request_validity(supported_version_request)
414
450
  'type' => "object",
415
451
  "properties" =>
416
452
  {
417
- "Productcode" => {'type'=>"string"},
418
- "Version" => {'type'=>"string"}
453
+ "Productcode" => { 'type' => "string" },
454
+ "Version" => { 'type' => "string" }
419
455
  }
420
456
  }
421
457
  }