ruby-d2l 0.2.2 → 0.3.0

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.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = ruby-d2l
2
2
 
3
- Version 0.2.0 - Extremely limited functionality so far. At this point it's just a proof of concept. The only SOAP call that works is get_course_template_by_code.
3
+ Extremely limited functionality so far. At this point it's just a proof of concept. Only a few SOAP calls are implemented at the moment.
4
4
 
5
5
 
6
6
  This hopefully will eventually provide a much easier way to access the Web Services SOAP interface in Desire2Learn. This code should work with D2L versions 9.4.1 and prior. As of D2L version 9.4.1, a new REST based interface is available. This may be re-written to support REST when I get access to a 9.4.1 test system.
@@ -28,7 +28,7 @@ Then in your Ruby application you can use the configure block to set these value
28
28
 
29
29
  Code Example:
30
30
 
31
- template = RubyD2L::OrgUnit.get_course_template_by_code("TEMPLATE_CODE").to_hash
31
+ template = RubyD2L::OrgUnit.get_course_template_by_code(:template_code => "TEMPLATE_CODE").to_hash
32
32
  ap template[:get_course_template_response][:course_template][:name].to_s
33
33
 
34
34
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
data/lib/ruby-d2l/auth.rb CHANGED
@@ -5,7 +5,6 @@ module RubyD2L
5
5
 
6
6
  def self.connect(site_url)
7
7
  Savon::Client.new do
8
- ap site_url
9
8
  wsdl.document = "#{site_url}/d2l/AuthenticationTokenService.asmx?WSDL"
10
9
  wsdl.endpoint = "#{site_url}/d2l/AuthenticationTokenService.asmx"
11
10
  #http.proxy = @@proxy_server if @@proxy_server != nil
@@ -10,11 +10,11 @@ module RubyD2L
10
10
  end
11
11
  end
12
12
 
13
- def self.list_soap_actions(params)
14
- # Get available SOAP actions
13
+ # = CreateCourseOffering
14
+ # Get a list of available SOAP actions for OrgUnit
15
+ def self.list_soap_actions()
15
16
 
16
- site_url = params[0]
17
- ap connect(site_url).wsdl.soap_actions
17
+ ap connect(RubyD2L.site_url).wsdl.soap_actions
18
18
 
19
19
  # [
20
20
  # [ 0] :link_course_offering_to_navbar,
@@ -88,89 +88,73 @@ module RubyD2L
88
88
  # ]
89
89
  end
90
90
 
91
- def self.create_course_offering(params)
92
-
93
- # I don't use <Path>'+ @course_path +'</Path>. Add it if you need it.
91
+ # = CreateCourseOffering
92
+ # REQUIRED: { :offering_name => "NAME", :offering_code => "CODE" }
93
+ # OPTIONAL: { :is_active => "true|false", :start_date => DateTime.to_s (e.g. YYYYMMDDThh:mm:ss), :end_date => DateTime.to_s (e.g. YYYYMMDDThh:mm:ss) }
94
+ # NOT IMPLEMENTED: I don't use <Path>'+ @course_path +'</Path>. Add it if you need it.
95
+ def self.create_course_offering(params={})
96
+ self.required_params(params, [:offering_name, :offering_code, :template_id])
94
97
 
95
- @course_name = ""
96
- @course_code = ""
97
- @course_path = ""
98
- @template_id = ""
99
- @is_active = "false"
100
- @start_date = DateTime.now.to_s
101
- @end_date = DateTime.now.to_s
102
- @can_register = "false"
103
- @allow_sections = "false"
98
+ params = {
99
+ :offering_name => "",
100
+ :offering_code => "",
101
+ :template_id => "",
102
+ :is_active => "false",
103
+ :start_date => DateTime.now.to_s,
104
+ :end_date => DateTime.now.to_s,
105
+ :can_register => "false",
106
+ :allow_sections => "false"
107
+ }.merge(params)
104
108
 
105
- site_url = params[0]
106
- token = params[1]
107
- if params[2] == nil || params[2] == "list_params"
108
- ap "REQUIRED: [course_name, course_code, template_id]"
109
- ap "OPTIONAL: [is_active(T/F), start_date (2011-12-12T00:00:00), end_date, can_register(T/F), allow_sections(T/F)]"
110
- ap "Must be comma separated with no spaces. (e.g. -p course_name=CS100,course_code=123,is_active=false)"
111
- exit
112
- else
113
- params[2].split(',').each do |values|
114
- vals = values.split('=')
115
- instance_variable_set("@#{vals[0]}", vals[1])
116
- end
117
- end
118
-
119
- the_xml = '<?xml version="1.0" encoding="utf-8"?>
120
- <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
121
- <soap:Header>
122
- <RequestHeader xmlns="http://www.desire2learn.com/services/common/xsd/common-v1_0">
123
- <Version>1.0</Version>
124
- <CorellationId>12345</CorellationId>
125
- <AuthenticationToken>'+ token +'</AuthenticationToken>
126
- </RequestHeader>
127
- </soap:Header>
128
- <soap:Body>
129
- <CreateCourseOfferingRequest xmlns="http://www.desire2learn.com/services/oums/wsdl/OrgUnitManagementService-v1_0">
130
- <Name>'+ @course_name +'</Name>
131
- <Code>'+ @course_code +'</Code>
132
- <TemplateId>
133
- <Id xmlns="http://www.desire2learn.com/services/common/xsd/common-v1_0">'+ @template_id +'</Id>
134
- <Source xmlns="http://www.desire2learn.com/services/common/xsd/common-v1_0">Desire2Learn</Source>
135
- </TemplateId>
136
- <IsActive>'+ @is_active +'</IsActive>
137
- <StartDate>'+ @start_date +'</StartDate>
138
- <EndDate>'+ @end_date +'</EndDate>
139
- <CanRegister>'+ @can_register +'</CanRegister>
140
- <AllowSections>'+ @allow_sections +'</AllowSections>
141
- </CreateCourseOfferingRequest>
142
- </soap:Body>
143
- </soap:Envelope>'
144
-
145
- orgunit = connect(site_url).request :create_course_offering do
146
- soap.xml = the_xml
147
- end
148
-
149
- end
150
-
151
- def self.create_course_template(params)
152
-
153
- # I don't use <Path>'+ @template_path +'</Path>. Add it if you need it.
109
+ token = RubyD2L::Auth.get_token
154
110
 
155
- @template_name = ""
156
- @template_code = ""
157
- @is_active = "false"
158
- @start_date = DateTime.now.to_s
159
- @end_date = DateTime.now.to_s
111
+ the_xml = '<?xml version="1.0" encoding="utf-8"?>
112
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
113
+ <soap:Header>
114
+ <RequestHeader xmlns="http://www.desire2learn.com/services/common/xsd/common-v1_0">
115
+ <Version>1.0</Version>
116
+ <CorellationId>12345</CorellationId>
117
+ <AuthenticationToken>'+ token +'</AuthenticationToken>
118
+ </RequestHeader>
119
+ </soap:Header>
120
+ <soap:Body>
121
+ <CreateCourseOfferingRequest xmlns="http://www.desire2learn.com/services/oums/wsdl/OrgUnitManagementService-v1_0">
122
+ <Name>'+ params[:offering_name] +'</Name>
123
+ <Code>'+ params[:offering_code] +'</Code>
124
+ <TemplateId>
125
+ <Id xmlns="http://www.desire2learn.com/services/common/xsd/common-v1_0">'+ params[:template_id] +'</Id>
126
+ <Source xmlns="http://www.desire2learn.com/services/common/xsd/common-v1_0">Desire2Learn</Source>
127
+ </TemplateId>
128
+ <IsActive>'+ params[:is_active] +'</IsActive>
129
+ <StartDate>'+ params[:start_date] +'</StartDate>
130
+ <EndDate>'+ params[:end_date] +'</EndDate>
131
+ <CanRegister>'+ params[:can_register] +'</CanRegister>
132
+ <AllowSections>'+ params[:allow_sections] +'</AllowSections>
133
+ </CreateCourseOfferingRequest>
134
+ </soap:Body>
135
+ </soap:Envelope>'
160
136
 
161
- site_url = params[0]
162
- token = params[1]
163
- if params[2] == nil || params[2] == "list_params"
164
- ap "REQUIRED: [template_name, template_code]"
165
- ap "OPTIONAL: [is_active(true/false), start_date(YYYY-MM-DDThh:mm:ss), end_date(YYYY-MM-DDThh:mm:ss)]"
166
- ap "Must be comma separated with no spaces. (e.g. -p template_name=CS100,template_code=123,is_active=false)"
167
- exit
168
- else
169
- params[2].split(',').each do |values|
170
- vals = values.split('=')
171
- instance_variable_set("@#{vals[0]}", vals[1])
172
- end
137
+ orgunit = self.connect(RubyD2L.site_url).request :create_course_offering do
138
+ soap.xml = the_xml
173
139
  end
140
+
141
+ end
142
+
143
+ # = CreateCourseTemplate
144
+ # REQUIRED: { :template_name => "NAME", :template_code => "CODE" }
145
+ # OPTIONAL: { :is_active => "true|false", :start_date => DateTime.to_s (e.g. YYYYMMDDThh:mm:ss), :end_date => DateTime.to_s (e.g. YYYYMMDDThh:mm:ss) }
146
+ def self.create_course_template(params={})
147
+ self.required_params(params, [:template_name, :template_code])
148
+
149
+ params = {
150
+ :template_name => "",
151
+ :template_code => "",
152
+ :is_active => "false",
153
+ :start_date => DateTime.now.to_s,
154
+ :end_date => DateTime.now.to_s
155
+ }.merge(params)
156
+
157
+ token = RubyD2L::Auth.get_token
174
158
 
175
159
  the_xml = '<?xml version="1.0" encoding="utf-8"?>
176
160
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
@@ -183,39 +167,32 @@ module RubyD2L
183
167
  </soap:Header>
184
168
  <soap:Body>
185
169
  <CreateCourseTemplateRequest xmlns="http://www.desire2learn.com/services/oums/wsdl/OrgUnitManagementService-v1_0">
186
- <Name>'+ @template_name +'</Name>
187
- <Code>'+ @template_code +'</Code>
188
- <IsActive>'+ @is_active +'</IsActive>
189
- <StartDate>'+ @start_date +'</StartDate>
190
- <EndDate>'+ @end_date +'</EndDate>
170
+ <Name>'+ params[:template_name] +'</Name>
171
+ <Code>'+ params[:template_code] +'</Code>
172
+ <IsActive>'+ params[:is_active] +'</IsActive>
173
+ <StartDate>'+ params[:start_date] +'</StartDate>
174
+ <EndDate>'+ params[:end_date] +'</EndDate>
191
175
  </CreateCourseTemplateRequest>
192
176
  </soap:Body>
193
177
  </soap:Envelope>'
194
178
 
195
- template = connect(site_url).request :create_course_template do
179
+ template = self.connect(RubyD2L.site_url).request :create_course_template do
196
180
  soap.xml = the_xml
197
181
  end
198
182
 
199
-
200
183
  end
201
184
 
202
- def self.get_course_template_by_code(template_code)
203
-
204
- # @template_code = ""
185
+ # = GetCourseTemplateByCode
186
+ # REQUIRED: template_code => "CODE"
187
+ def self.get_course_template_by_code(params={})
188
+ self.required_params(params, [:template_code])
189
+
190
+ params = {
191
+ :template_code => ""
192
+ }.merge(params)
193
+
205
194
  token = RubyD2L::Auth.get_token
206
195
 
207
- # site_url = params[0]
208
- # token = params[1]
209
- # if params[2] == nil || params[2] == "list_params"
210
- # ap "REQUIRED: [template_code]"
211
- # exit
212
- # else
213
- # params[2].split(',').each do |values|
214
- # vals = values.split('=')
215
- # instance_variable_set("@#{vals[0]}", vals[1])
216
- # end
217
- # end
218
-
219
196
  the_xml = '<?xml version="1.0" encoding="utf-8"?>
220
197
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
221
198
  <soap:Header>
@@ -227,7 +204,7 @@ module RubyD2L
227
204
  </soap:Header>
228
205
  <soap:Body>
229
206
  <GetCourseTemplateByCodeRequest xmlns="http://www.desire2learn.com/services/oums/wsdl/OrgUnitManagementService-v1_0">
230
- <Code>'+ template_code +'</Code>
207
+ <Code>'+ params[:template_code] +'</Code>
231
208
  </GetCourseTemplateByCodeRequest>
232
209
  </soap:Body>
233
210
  </soap:Envelope>'
@@ -237,5 +214,13 @@ module RubyD2L
237
214
  end
238
215
 
239
216
  end
217
+
218
+ def self.required_params(passed_params={},*args)
219
+ required_params = *args[0]
220
+ required_params.each do |key|
221
+ raise ArgumentError.new("MISSING PARAM -- :#{key} parameter is required!") unless passed_params.has_key?(key)
222
+ end
223
+ end
224
+
240
225
  end
241
226
  end
data/lib/ruby-d2l/user.rb CHANGED
@@ -1,86 +1,89 @@
1
- class User
1
+ require "savon"
2
2
 
3
- def self.connect(site_url)
4
- Savon::Client.new do
5
- wsdl.document = "#{site_url}/D2LWS/UserManagementService-v1.asmx?WSDL"
6
- wsdl.endpoint = "#{site_url}/D2LWS/UserManagementService-v1.asmx"
7
- http.proxy = @@proxy_server if @@proxy_server != nil
8
- http.auth.ssl.verify_mode = :none
3
+ module RubyD2L
4
+ class User
5
+
6
+ def self.connect(site_url)
7
+ Savon::Client.new do
8
+ wsdl.document = "#{site_url}/D2LWS/UserManagementService-v1.asmx?WSDL"
9
+ wsdl.endpoint = "#{site_url}/D2LWS/UserManagementService-v1.asmx"
10
+ http.auth.ssl.verify_mode = :none
11
+ end
9
12
  end
10
- end
11
13
 
12
- def self.list_soap_actions(params)
13
- # Get available SOAP actions
14
+ def self.list_soap_actions(params)
15
+ # Get available SOAP actions
14
16
 
15
- site_url = params[0]
16
- ap connect(site_url).wsdl.soap_actions
17
+ site_url = params[0]
18
+ ap connect(site_url).wsdl.soap_actions
17
19
 
18
- # [
19
- # [ 0] :get_active_course_offerings_ex,
20
- # [ 1] :get_active_course_offerings,
21
- # [ 2] :activate_users,
22
- # [ 3] :deactivate_users,
23
- # [ 4] :get_user_activation_status,
24
- # [ 5] :create_auditor_relationship,
25
- # [ 6] :remove_auditor_relationship,
26
- # [ 7] :get_auditors,
27
- # [ 8] :get_auditees,
28
- # [ 9] :get_users_by_org_unit_role,
29
- # [10] :create_user,
30
- # [11] :delete_user,
31
- # [12] :get_user,
32
- # [13] :update_user,
33
- # [14] :delete_user_by_user_name,
34
- # [15] :delete_user_by_org_defined_id,
35
- # [16] :get_user_by_user_name,
36
- # [17] :get_user_by_org_defined_id,
37
- # [18] :get_roles,
38
- # [19] :get_role,
39
- # [20] :change_password,
40
- # [21] :enroll_user,
41
- # [22] :unenroll_user,
42
- # [23] :get_org_unit_enrollment,
43
- # [24] :get_enrollments_by_org_unit,
44
- # [25] :get_profile_by_user,
45
- # [26] :get_profile_picture,
46
- # [27] :update_profile,
47
- # [28] :get_users_by_group,
48
- # [29] :get_users_by_section,
49
- # [30] :get_users_by_course_offerings_index,
50
- # [31] :get_permitted_tasks_by_user_org_unit
51
- # ]
20
+ # [
21
+ # [ 0] :get_active_course_offerings_ex,
22
+ # [ 1] :get_active_course_offerings,
23
+ # [ 2] :activate_users,
24
+ # [ 3] :deactivate_users,
25
+ # [ 4] :get_user_activation_status,
26
+ # [ 5] :create_auditor_relationship,
27
+ # [ 6] :remove_auditor_relationship,
28
+ # [ 7] :get_auditors,
29
+ # [ 8] :get_auditees,
30
+ # [ 9] :get_users_by_org_unit_role,
31
+ # [10] :create_user,
32
+ # [11] :delete_user,
33
+ # [12] :get_user,
34
+ # [13] :update_user,
35
+ # [14] :delete_user_by_user_name,
36
+ # [15] :delete_user_by_org_defined_id,
37
+ # [16] :get_user_by_user_name,
38
+ # [17] :get_user_by_org_defined_id,
39
+ # [18] :get_roles,
40
+ # [19] :get_role,
41
+ # [20] :change_password,
42
+ # [21] :enroll_user,
43
+ # [22] :unenroll_user,
44
+ # [23] :get_org_unit_enrollment,
45
+ # [24] :get_enrollments_by_org_unit,
46
+ # [25] :get_profile_by_user,
47
+ # [26] :get_profile_picture,
48
+ # [27] :update_profile,
49
+ # [28] :get_users_by_group,
50
+ # [29] :get_users_by_section,
51
+ # [30] :get_users_by_course_offerings_index,
52
+ # [31] :get_permitted_tasks_by_user_org_unit
53
+ # ]
52
54
 
53
- end
55
+ end
54
56
 
55
57
 
56
- def self.get_user_by_user_name(params)
57
- site_url = params[0]
58
- token = params[1]
59
- if params[2] == nil || params[2] == "list_params"
60
- ap "[user_name] param required by get_user_by_user_name!"
61
- exit
62
- else
63
- user_name = params[2]
64
- end
58
+ def self.get_user_by_user_name(params)
59
+ site_url = params[0]
60
+ token = params[1]
61
+ if params[2] == nil || params[2] == "list_params"
62
+ ap "[user_name] param required by get_user_by_user_name!"
63
+ exit
64
+ else
65
+ user_name = params[2]
66
+ end
65
67
 
66
- user = connect(site_url).request :get_user_by_user_name do
67
- soap.xml = '<?xml version="1.0" encoding="utf-8"?>
68
- <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
69
- <soap:Header>
70
- <RequestHeader xmlns="http://www.desire2learn.com/services/common/xsd/common-v1_0">
71
- <Version>1.0</Version>
72
- <CorellationId>12345</CorellationId>
73
- <AuthenticationToken>'+ token +'</AuthenticationToken>
74
- </RequestHeader>
75
- </soap:Header>
76
- <soap:Body>
77
- <GetUserByUserNameRequest xmlns="http://www.desire2learn.com/services/ums/wsdl/UserManagementService-v1_0">
78
- <UserName>'+ user_name +'</UserName>
79
- </GetUserByUserNameRequest>
80
- </soap:Body>
81
- </soap:Envelope>'
68
+ user = connect(site_url).request :get_user_by_user_name do
69
+ soap.xml = '<?xml version="1.0" encoding="utf-8"?>
70
+ <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
71
+ <soap:Header>
72
+ <RequestHeader xmlns="http://www.desire2learn.com/services/common/xsd/common-v1_0">
73
+ <Version>1.0</Version>
74
+ <CorellationId>12345</CorellationId>
75
+ <AuthenticationToken>'+ token +'</AuthenticationToken>
76
+ </RequestHeader>
77
+ </soap:Header>
78
+ <soap:Body>
79
+ <GetUserByUserNameRequest xmlns="http://www.desire2learn.com/services/ums/wsdl/UserManagementService-v1_0">
80
+ <UserName>'+ user_name +'</UserName>
81
+ </GetUserByUserNameRequest>
82
+ </soap:Body>
83
+ </soap:Envelope>'
84
+ end
82
85
  end
83
- end
84
86
 
85
87
 
88
+ end
86
89
  end
data/ruby-d2l.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-d2l}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Mencel"]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matt Mencel
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
- hash: -1913843328194899907
129
+ hash: -3831117481161228882
130
130
  segments:
131
131
  - 0
132
132
  version: "0"