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.
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'd2l_sdk/version'
@@ -85,7 +85,7 @@ end
85
85
  def _get_string(path, http_method)
86
86
  timestamp = Time.now.to_i
87
87
  signature = format_signature(path, http_method, timestamp)
88
- unless path.include? "/auth/api/token"
88
+ if !path.include? "/auth/api/token"
89
89
  build_authenticated_uri_query_string(signature, timestamp)
90
90
  else
91
91
  # build authenticated query string not using typical schema
@@ -30,9 +30,9 @@ end
30
30
  # REVIEW: Retrieve the calling user’s calendar events, within a
31
31
  # number of org units (see query parameter)
32
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)
33
+ def get_current_user_calendar_events_by_org_units(org_unit_ids_csv, start_date_time,
34
+ end_date_time, association = nil,
35
+ event_type = nil)
36
36
  path = "/d2l/api/le/#{$le_ver}/calendar/events/myEvents/"
37
37
  path += "?orgUnitIdsCSV=#{org_unit_ids_csv}"
38
38
  path += "&startDateTime=#{start_date_time}"
@@ -44,8 +44,8 @@ end
44
44
 
45
45
  # REVIEW: Retrieve the calling user’s events for a particular org unit.
46
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)
47
+ def get_current_user_events_by_org_unit(start_date_time, end_date_time,
48
+ association = nil, event_type = nil)
49
49
  path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/myEvents/"
50
50
  path += "&startDateTime=#{start_date_time}"
51
51
  path += "&endDateTime=#{end_date_time}"
@@ -56,8 +56,8 @@ end
56
56
 
57
57
  # REVIEW: Retrieve a count of calling user’s calendar events, within a number of org units
58
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)
59
+ def get_calendar_event_count(org_unit_ids_csv, start_date_time, end_date_time,
60
+ association = nil, event_type = nil)
61
61
  path = "/d2l/api/le/#{$le_ver}/calendar/events/myEvents/itemCounts/"
62
62
  path += "?orgUnitIdsCSV=#{org_unit_ids_csv}"
63
63
  path += "&startDateTime=#{start_date_time}"
@@ -70,8 +70,8 @@ end
70
70
  # REVIEW: Retrieve a count of calling user’s calendar events, within the
71
71
  # provided org unit context.
72
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)
73
+ def get_org_unit_calendar_event_count(start_date_time, end_date_time,
74
+ association = nil, event_type = nil)
75
75
  path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/events/myEvents/itemCounts/"
76
76
  path += "?startDateTime=#{start_date_time}"
77
77
  path += "&endDateTime=#{end_date_time}"
@@ -177,7 +177,7 @@ end
177
177
  def create_event(org_unit_id, event_data)
178
178
  # POST /d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/
179
179
  path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/"
180
- payload = { #Calendar.EventDataInfo
180
+ payload = { # Calendar.EventDataInfo
181
181
  "Title" => "",
182
182
  "Description" => "",
183
183
  "StartDateTime" => nil, # UTCDateTime || nil
@@ -214,7 +214,6 @@ def create_event(org_unit_id, event_data)
214
214
  }.merge!(event_data)
215
215
  check_calendar_event_data_validity(payload) # NOTE: Test later
216
216
  _post(path, payload)
217
-
218
217
  end
219
218
 
220
219
  # REVIEW: Create Schema checker; Check that this payload conforms to it.
@@ -224,7 +223,7 @@ end
224
223
  def update_event(org_unit_id, event_id, event_data)
225
224
  # PUT /d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}
226
225
  path = "/d2l/api/le/#{$le_ver}/#{org_unit_id}/calendar/event/#{event_id}"
227
- payload = { #Calendar.EventDataInfo
226
+ payload = { # Calendar.EventDataInfo
228
227
  "Title" => "",
229
228
  "Description" => "",
230
229
  "StartDateTime" => nil, # UTCDateTime || nil
@@ -1,4 +1,4 @@
1
- #Is this the production environment?
1
+ # Is this the production environment?
2
2
  require 'json'
3
3
  @production = true
4
4
  @debug = true
@@ -8,49 +8,49 @@ config_file_name = 'd2l_config.json'
8
8
  if File.exist?(config_file_name)
9
9
  config_file = File.read(config_file_name)
10
10
  config = JSON.parse(config_file)
11
- puts "[+] Configuration Variables:" if @debug
12
- puts "[-] hostname: #{config["hostname"]}" if @debug
13
- $hostname = config["hostname"]
14
- puts "[-] user_id: #{config["user_id"]}" if @debug
15
- $user_id = config["user_id"]
16
- puts "[-] user_key: #{config["user_key"]}" if @debug
17
- $user_key = config["user_key"]
18
- puts "[-] app_id: #{config["app_id"]}" if @debug
19
- $app_id = config["app_id"]
20
- puts "[-] app_key: #{config["app_key"]}" if @debug
21
- $app_key = config["app_key"]
11
+ puts '[+] Configuration Variables:' if @debug
12
+ puts "[-] hostname: #{config['hostname']}" if @debug
13
+ $hostname = config['hostname']
14
+ puts "[-] user_id: #{config['user_id']}" if @debug
15
+ $user_id = config['user_id']
16
+ puts "[-] user_key: #{config['user_key']}" if @debug
17
+ $user_key = config['user_key']
18
+ puts "[-] app_id: #{config['app_id']}" if @debug
19
+ $app_id = config['app_id']
20
+ puts "[-] app_key: #{config['app_key']}" if @debug
21
+ $app_key = config['app_key']
22
22
  # else if a configuration file doesnt exist, create one and load the config vars!
23
23
  else
24
24
  puts "[!] No file by the name 'd2l_config.json' found!"
25
25
  puts "[-] Initializing 'd2l_config.json' in current directory..\n"\
26
26
  " Please enter the following information..."
27
27
  # host of D2L server
28
- print "hostname: "
29
- $hostname = gets.chomp.gsub(/'|\"|https:\/\/|http:\/\/|/,'').strip
28
+ print 'hostname: '
29
+ $hostname = gets.chomp.gsub(/'|\"|https:\/\/|http:\/\/|/, '').strip
30
30
  # api-user id
31
- print "user_id: "
32
- $user_id = gets.chomp.gsub(/'|\"/,'').strip
31
+ print 'user_id: '
32
+ $user_id = gets.chomp.gsub(/'|\"/, '').strip
33
33
  # api-user key
34
- print "user_key: "
35
- $user_key = gets.chomp.gsub(/'|\"/,'').strip
34
+ print 'user_key: '
35
+ $user_key = gets.chomp.gsub(/'|\"/, '').strip
36
36
  # app id (received from apitesttool)
37
- print "app_id: "
38
- $app_id = gets.chomp.gsub(/'|\"/,'').strip
37
+ print 'app_id: '
38
+ $app_id = gets.chomp.gsub(/'|\"/, '').strip
39
39
  # app key (same as app id retrieval)
40
- print "app_key: "
41
- $app_key = gets.chomp.gsub(/'|\"/,'').strip
40
+ print 'app_key: '
41
+ $app_key = gets.chomp.gsub(/'|\"/, '').strip
42
42
 
43
43
  config_hash = {
44
- "hostname" => $hostname,
45
- "user_id" => $user_id,
46
- "user_key" => $user_key,
47
- "app_id" => $app_id,
48
- "app_key" => $app_key
44
+ 'hostname' => $hostname,
45
+ 'user_id' => $user_id,
46
+ 'user_key' => $user_key,
47
+ 'app_id' => $app_id,
48
+ 'app_key' => $app_key
49
49
  }
50
50
  json = JSON.pretty_generate(config_hash)
51
51
  puts json if @debug
52
- #puts JSON.parse(json)["hostname"] if @debug
53
- config = File.new("d2l_config.json","w")
52
+ # puts JSON.parse(json)["hostname"] if @debug
53
+ config = File.new('d2l_config.json', 'w')
54
54
  config.puts(json)
55
55
  config.close
56
56
  end
@@ -11,7 +11,7 @@ require_relative 'auth'
11
11
 
12
12
  # Retrieve the definitions for all the configuration variables the
13
13
  # user has access to view.
14
- def get_all_config_var_definitions(search='', bookmark='')
14
+ def get_all_config_var_definitions(search = '', bookmark = '')
15
15
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/definitions/"
16
16
  path += "?search=#{search}" if search != ''
17
17
  path += "?bookmark=#{bookmark}" if bookmark != ''
@@ -32,14 +32,14 @@ end
32
32
  # NOTE: These provide access to the values assigned to configuration
33
33
  # variables in the running back-end service.
34
34
 
35
- #Retrieve the value summary for a configuration variable.
35
+ # Retrieve the value summary for a configuration variable.
36
36
  def get_config_var_values(variable_id)
37
37
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values"
38
38
  _get(path)
39
39
  # returns Values JSON data block
40
40
  end
41
41
 
42
- #Retrieve the current org value for a configuration variable.
42
+ # Retrieve the current org value for a configuration variable.
43
43
  def get_config_var_current_org_value(variable_id)
44
44
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/org"
45
45
  _get(path)
@@ -47,7 +47,7 @@ def get_config_var_current_org_value(variable_id)
47
47
  end
48
48
 
49
49
  # Retrieve all the org unit override values for a configuration variable.
50
- def get_all_config_var_org_unit_override_values(variable_id, bookmark='')
50
+ def get_all_config_var_org_unit_override_values(variable_id, bookmark = '')
51
51
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/orgUnits/"
52
52
  path += "?bookmark=#{bookmark}" if bookmark != ''
53
53
  _get(path)
@@ -70,7 +70,7 @@ def get_config_var_org_unit_effective_value(variable_id, org_unit_id)
70
70
  end
71
71
 
72
72
  # Retrieve all the role override values for a configuration variable.
73
- def get_all_config_var_org_unit_role_override_values(variable_id, bookmark='')
73
+ def get_all_config_var_org_unit_role_override_values(variable_id, bookmark = '')
74
74
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/roles/"
75
75
  path += "?bookmark=#{bookmark}" if bookmark != ''
76
76
  _get(path)
@@ -90,45 +90,33 @@ end
90
90
  # REVIEW: Set a new org value for a configuration variable.
91
91
  def set_config_var_org_value(variable_id, org_value)
92
92
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/org"
93
- if org_value.is_a? String || org_value.nil?
94
- payload = {"OrgValue" => org_value}
95
- _put(path, payload)
96
- else
97
- raise ArgumentError, "Argument 'org_value' is not a String or nil"
98
- end
93
+ raise(ArgumentError, "Argument 'org_value' is not a String or nil") unless org_value.is_a?(String) || org_value.nil?
94
+ payload = { 'OrgValue' => org_value }
95
+ _put(path, payload)
99
96
  end
100
97
 
101
98
  # REVIEW: Set a new org unit override value for a configuration variable.
102
99
  def set_config_var_override_value(variable_id, org_unit_id, org_unit_value)
103
100
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/orgUnits/#{org_unit_id}"
104
- if org_unit_value.is_a? String || org_unit_value.nil?
105
- payload = {"OrgUnitValue" => org_unit_value}
106
- _put(path, payload)
107
- else
108
- raise ArgumentError, "Argument 'org_unit_value' is not a String or nil"
109
- end
101
+ raise(ArgumentError, "Argument 'org_unit_value' is not a String or nil") unless org_unit_value.is_a?(String) || org_unit_value.nil?
102
+ payload = { 'OrgUnitValue' => org_unit_value }
103
+ _put(path, payload)
110
104
  end
111
105
 
112
106
  # REVIEW: Set a new role override value for a configuration variable.
113
107
  def set_config_var_role_value(variable_id, role_id, role_value)
114
108
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/roles/#{role_id}"
115
- if role_value.is_a? String || role_value.nil?
116
- payload = {"RoleValue" => role_value}
117
- _put(path, payload)
118
- else
119
- raise ArgumentError, "Argument 'role_value' is not a String or nil"
120
- end
109
+ raise(ArgumentError, "Argument 'role_value' is not a String or nil") unless role_value.is_a? String || role_value.nil?
110
+ payload = { 'RoleValue' => role_value }
111
+ _put(path, payload)
121
112
  end
122
113
 
123
114
  # REVIEW: Set a new system value for a configuration variable.
124
115
  def set_config_var_system_value(variable_id, system_value)
125
116
  path = "/d2l/api/lp/#{$lp_ver}/configVariables/#{variable_id}/values/system"
126
- if system_value.is_a?(String) || system_value.nil?
127
- payload = {"SystemValue" => system_value}
128
- _put(path, payload)
129
- else
130
- raise ArgumentError, "Argument 'system_value' is not a String or nil"
131
- end
117
+ raise(ArgumentError, "Argument 'system_value' is not a String or nil") unless system_value.is_a?(String) || system_value.nil?
118
+ payload = { 'SystemValue' => system_value }
119
+ _put(path, payload)
132
120
  end
133
121
 
134
122
  ########################
@@ -139,9 +127,9 @@ end
139
127
 
140
128
  # NOTE: UNSTABLE!!!
141
129
  # TODO: UNSTABLE!!! --Restore the default resolution strategy for an org unit configuration variable.
142
- def restore_default_org_unit_config_var_resolution(variable_id)
130
+ def restore_default_org_unit_config_var_resolution(variable_id); end
143
131
  # DELETE /d2l/api/lp/(version)/configVariables/(variableId)/resolver
144
- end
132
+
145
133
 
146
134
  # NOTE: UNSTABLE!!!
147
135
  # REVIEW: Retrieve the resolution strategy for an org unit configuration variable.
@@ -152,9 +140,9 @@ end
152
140
 
153
141
  # NOTE: UNSTABLE!!!
154
142
  # TODO: UNSTABLE!!! --Update the resolution strategy for an org unit configuration variable.
155
- def update_org_unit_config_var_resolution(resolver_value)
143
+ def update_org_unit_config_var_resolution(resolver_value); end
156
144
  # PUT /d2l/api/lp/(version)/configVariables/(variableId)/resolver
157
- end
145
+
158
146
 
159
147
  ################################################################################
160
148
  ############################### TOOLS ###################################
@@ -193,7 +181,7 @@ def check_and_create_update_status_payload(update_status)
193
181
  if update_status != true && update_status != false
194
182
  raise ArgumentError, 'update_status is not a boolean'
195
183
  end
196
- payload = {"Status" => update_status} # Tools.UpdateStatus JSON data block
184
+ payload = { 'Status' => update_status } # Tools.UpdateStatus JSON data block
197
185
  payload
198
186
  end
199
187
 
@@ -262,11 +250,11 @@ def update_org_unit_level_tool_info(org_unit_id, tool_id, org_unit_information)
262
250
  path = "/d2l/api/lp/#{$lp_ver}/tools/orgUnits/#{org_unit_id}/#{tool_id}"
263
251
  payload =
264
252
  {
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>
253
+ 'ToolId' => '', # <string:D2LID>
254
+ 'DisplayName' => '', # <string> ## added with LP v1.6 API
255
+ 'OrgUnitId' => 0, # D2LID:number
256
+ 'Status' => false, # boolean
257
+ 'CustomNavbarName' => '' # <string>
270
258
  }.merge!(org_unit_information)
271
259
  check_org_unit_information_validity(payload) # NOTE: Check this later.
272
260
  _put(path, payload)
@@ -1,5 +1,6 @@
1
1
  require_relative 'requests'
2
2
  require 'json-schema'
3
+ require 'mime/types'
3
4
 
4
5
  ########################
5
6
  # ACTIONS:##############
@@ -10,7 +11,7 @@ require 'json-schema'
10
11
  # Then, a delete http method is executed using this path, deleting the course.
11
12
  def delete_course_by_id(org_unit_id)
12
13
  path = "/d2l/api/lp/#{$lp_ver}/courses/#{org_unit_id}" # setup user path
13
- #ap path
14
+ # ap path
14
15
  _delete(path)
15
16
  puts '[+] Course data deleted successfully'.green
16
17
  end
@@ -33,9 +34,8 @@ def get_course_by_id(org_unit_id)
33
34
  # returns: JSON object of the course
34
35
  end
35
36
 
36
-
37
37
  def get_course_image(org_unit_id, width = 0, height = 0)
38
- path = "/d2l/api/lp/#{lp_ver}/courses/#{org_unit_id}/image"
38
+ path = "/d2l/api/lp/#{$lp_ver}/courses/#{org_unit_id}/image"
39
39
  if width > 0 && height > 0
40
40
  path += "?width=#{width}"
41
41
  path += "&height=#{height}"
@@ -68,7 +68,6 @@ def check_course_data_validity(course_data)
68
68
  JSON::Validator.validate!(schema, course_data, validate_schema: true)
69
69
  end
70
70
 
71
-
72
71
  # Creates the course based upon a merged result of the argument course_data
73
72
  # and a preformatted payload. This is then passed as a new payload in the
74
73
  # +_post+ method in order to create the defined course.
@@ -82,23 +81,24 @@ def create_course_data(course_data)
82
81
  # Define a valid, empty payload and merge! with the user_data. Print it.
83
82
  # can be an issue if more than one course template associated with
84
83
  # a course and the last course template parent to a course cannot be deleted
85
- payload = { 'Name' => '', # String
86
- 'Code' => 'off_SEMESTERCODE_STARNUM', # String
87
- 'Path' => '', # String
88
- 'CourseTemplateId' => 99_989, # number: D2L_ID
89
- 'SemesterId' => nil, # number: D2L_ID | nil
90
- 'StartDate' => nil, # String: UTCDateTime | nil
91
- 'EndDate' => nil, # String: UTCDateTime | nil
92
- 'LocaleId' => nil, # number: D2L_ID | nil
93
- 'ForceLocale' => false, # bool
94
- 'ShowAddressBook' => false # bool
95
- }.merge!(course_data)
84
+ payload = {
85
+ 'Name' => '', # String
86
+ 'Code' => 'off_SEMESTERCODE_STARNUM', # String
87
+ 'Path' => '', # String
88
+ 'CourseTemplateId' => 99_989, # number: D2L_ID
89
+ 'SemesterId' => nil, # number: D2L_ID | nil
90
+ 'StartDate' => nil, # String: UTCDateTime | nil
91
+ 'EndDate' => nil, # String: UTCDateTime | nil
92
+ 'LocaleId' => nil, # number: D2L_ID | nil
93
+ 'ForceLocale' => false, # bool
94
+ 'ShowAddressBook' => false # bool
95
+ }.merge!(course_data)
96
96
  check_course_data_validity(payload)
97
97
  # ap payload
98
98
  # requires: CreateCourseOffering JSON block
99
99
  path = "/d2l/api/lp/#{$lp_ver}/courses/"
100
100
  _post(path, payload)
101
- #puts '[+] Course creation completed successfully'.green
101
+ # puts '[+] Course creation completed successfully'.green
102
102
  end
103
103
 
104
104
  # Checks whether the updated course data conforms to the valence api for the
@@ -112,9 +112,9 @@ def check_updated_course_data_validity(course_data)
112
112
  'properties' => {
113
113
  'Name' => { 'type' => 'string' },
114
114
  'Code' => { 'type' => 'string' },
115
- 'StartDate' => { 'type' => ['string', "null"] },
116
- 'EndDate' => { 'type' => ['string', "null"] },
117
- 'IsActive' => { 'type' => "boolean" },
115
+ 'StartDate' => { 'type' => %w(string null) },
116
+ 'EndDate' => { 'type' => %w(string null) },
117
+ 'IsActive' => { 'type' => 'boolean' }
118
118
  }
119
119
  }
120
120
  JSON::Validator.validate!(schema, course_data, validate_schema: true)
@@ -127,12 +127,13 @@ end
127
127
  # Utilize the second argument and perform a PUT action to replace the old data
128
128
  def update_course_data(course_id, new_data)
129
129
  # Define a valid, empty payload and merge! with the new data.
130
- payload = { 'Name' => '', # String
131
- 'Code' => 'off_SEMESTERCODE_STARNUM', # String
132
- 'StartDate' => nil, # String: UTCDateTime | nil
133
- 'EndDate' => nil, # String: UTCDateTime | nil
134
- 'IsActive' => false # bool
135
- }.merge!(new_data)
130
+ payload = {
131
+ 'Name' => '', # String
132
+ 'Code' => 'off_SEMESTERCODE_STARNUM', # String
133
+ 'StartDate' => nil, # String: UTCDateTime | nil
134
+ 'EndDate' => nil, # String: UTCDateTime | nil
135
+ 'IsActive' => false # bool
136
+ }.merge!(new_data)
136
137
  check_updated_course_data_validity(payload)
137
138
  # ap payload
138
139
  # Define a path referencing the courses path
@@ -145,8 +146,13 @@ def update_course_data(course_id, new_data)
145
146
  # Provide feedback that the update was successful
146
147
  end
147
148
 
148
- # TODO: Update the course image for a course offering.
149
- def update_course_image(org_unit_id, image_file)
149
+ # REVIEW: Update the course image for a course offering.
150
+ def update_course_image(org_unit_id, image_file_path)
151
+ path = "/d2l/api/lp/#{$lp_ver}/courses/#{org_unit_id}/image"
152
+ # (SCHEMA) Make sure file isnt > 2MB
153
+ raise ArgumentError, "File referrenced by 'image_file_path' must be less than 1000KB." if File.size(image_file_path) > 2_000_000
154
+ 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?
155
+ _image_upload(path, image_file_path, "PUT")
150
156
  # PUT /d2l/api/lp/(version)/courses/(orgUnitId)/image
151
157
  end
152
158
 
@@ -178,13 +184,13 @@ def check_create_copy_job_request_validity(create_copy_job_request)
178
184
  'properties' => {
179
185
  'SourceOrgUnitId' => { 'type' => 'integer' },
180
186
  'Components' => {
181
- 'type' => ['array', "null"],
187
+ 'type' => %w(array null),
182
188
  'items' =>
183
189
  {
184
- 'type' => "string"
190
+ 'type' => 'string'
185
191
  }
186
192
  },
187
- 'CallbackUrl' => { 'type' => ['string', 'null'] }
193
+ 'CallbackUrl' => { 'type' => %w(string null) }
188
194
  }
189
195
  }
190
196
  JSON::Validator.validate!(schema, create_copy_job_request, validate_schema: true)
@@ -192,7 +198,7 @@ end
192
198
 
193
199
  # simple schema check to assure the course component is an actual course component
194
200
  # returns: boolean
195
- def is_course_component(key)
201
+ def course_component?(key)
196
202
  valid_components = %w(AttendanceRegisters Glossary News Checklists
197
203
  Grades QuestionLibrary Competencies GradesSettings
198
204
  Quizzes Content Groups ReleaseConditions CourseFiles
@@ -216,19 +222,17 @@ def create_new_copy_job_request(org_unit_id, create_copy_job_request)
216
222
  # Check each one of the components to see if they are valid Component types
217
223
  payload["Components"].each do |component|
218
224
  # If one of the components is not valid, cancel the CopyJobRequest operation
219
- if(!is_course_component(key))
220
- puts "'#{component}' specified is not a valid Copy Job Request component"
221
- puts "Please retry with a valid course component such as 'Dropbox' or 'Grades'"
222
- break
223
- end
225
+ next if course_component?(key)
226
+ puts "'#{component}' specified is not a valid Copy Job Request component"
227
+ puts "Please retry with a valid course component such as 'Dropbox' or 'Grades'"
228
+ break
224
229
  end
225
230
  path = "/d2l/api/le/#{$le_ver}/import/#{org_unit_id}/copy/"
226
231
  _post(path, payload)
227
232
  # Returns CreateCopyJobResponse JSON block
228
233
  end
229
234
 
230
- # NOTE: UNSTABLE!!!!
231
- # TODO: --UNSTABLE-- Retrieve the list of logs for course copy jobs.
235
+ # TODO: UNSTABLE!!!! Retrieve the list of logs for course copy jobs.
232
236
  # Query Params:
233
237
  # --OPTIONAL--
234
238
  # -bookmark : string
@@ -263,13 +267,14 @@ def get_course_import_job_request_logs(org_unit_id, job_token, bookmark = '')
263
267
  # returns PAGED RESULT of ImportCourseLog JSON blocks following bookmark param
264
268
  end
265
269
 
266
- # TODO: Create a new course import job request.
267
- # INPUT: simple file upload process
268
- def create_course_import_request(org_unit_id, callback_url = '')
269
- #path = "/d2l/le/#{le_ver}/import/#{org_unit_id}/imports/"
270
- #path += "?callbackUrl=#{callback_url}" if callback_url != ''
271
- #_post(path, payload)
272
- #_upload(path, json, file, 'POST', 'file', filename)
270
+ # REVIEW: Create a new course import job request.
271
+ # INPUT: simple file upload process -- using "course package" as the uploaded file
272
+ def create_course_import_request(org_unit_id, file_path, callback_url = '')
273
+ path = "/d2l/le/#{le_ver}/import/#{org_unit_id}/imports/"
274
+ path += "?callbackUrl=#{callback_url}" if callback_url != ''
275
+ # TODO: (SCHEMA) Find out WTH a 'course package' entails as far as standards.
276
+ _course_package_upload(path, file_path, "POST")
277
+ # RETURNS: Parsed CreateImportJobResponse JSON block.
273
278
  end
274
279
 
275
280
  ################################################################################
@@ -304,10 +309,11 @@ def get_courses_by_code(org_unit_code)
304
309
  all_courses = get_all_courses
305
310
  courses = []
306
311
  all_courses.each do |course|
307
- courses.push(course) if course["Code"].downcase.include? "#{org_unit_code}".downcase
312
+ courses.push(course) if course["Code"].downcase.include? org_unit_code.to_s.downcase
308
313
  end
309
314
  courses
310
315
  end
316
+
311
317
  # Retrieves all courses that have a particular string (org_unit_name) within
312
318
  # their names. This is done by first defining that none are found yet and then
313
319
  # searching through all course for ones that do have a particular string within
@@ -352,7 +358,7 @@ def get_courses_by_property_by_regex(property, regex)
352
358
  courses_results = []
353
359
  results = get_all_courses
354
360
  results.each do |x|
355
- courses_results.push(x) if (x[property] =~ regex) != nil
361
+ courses_results.push(x) unless (x[property] =~ regex).nil?
356
362
  end
357
363
  courses_results
358
364
  # returns array of all matching courses in JSON format.