sakai-info 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # sakai-info Change History #
2
2
 
3
+ ### 0.4.4 ###
4
+
5
+ *Released 2012-05-12*
6
+
7
+ * Standardized gradebook and gradebook-item APIs
8
+ * Renamed GradableObject class to GradebookItem
9
+ * CLI access to gradebook and gradebook-item objects
10
+
3
11
  ### 0.4.3 ###
4
12
 
5
13
  *Released 2012-05-10*
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # sakai-info #
2
2
 
3
- last updated: 2012-05-10
3
+ last updated: 2012-05-12
4
4
  author: David Adams (daveadams@gmail.com)
5
5
  github url: https://github.com/daveadams/sakai-info
6
6
 
@@ -24,7 +24,7 @@ Use `rake` to test and build the gem:
24
24
  $ rake gem:build
25
25
 
26
26
  The resulting gem will be saved to the working directory as
27
- `sakai-info-0.4.3.gem`.
27
+ `sakai-info-0.4.4.gem`.
28
28
 
29
29
  Cleanup built gems using:
30
30
 
data/ROADMAP.md CHANGED
@@ -1,10 +1,6 @@
1
1
  # sakai-info Roadmap #
2
2
 
3
- *Last updated 2012-05-10*
4
-
5
- ### 0.4.4 ###
6
-
7
- * CLI access to gradebook
3
+ *Last updated 2012-05-12*
8
4
 
9
5
  ### 0.4.5 ###
10
6
 
@@ -13,6 +9,8 @@
13
9
  ### 0.5.0 ###
14
10
 
15
11
  * Sqlite test infrastructure for a few basic objects
12
+ * Deeper query functionality and field specification
13
+ * Simple web query interface - HTML, JSON, and YAML
16
14
 
17
15
  ### 0.6.0 ###
18
16
 
@@ -2,7 +2,7 @@
2
2
  # - sakai-info command line tool support
3
3
  #
4
4
  # Created 2012-02-19 daveadams@gmail.com
5
- # Last updated 2012-05-10 daveadams@gmail.com
5
+ # Last updated 2012-05-12 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -38,6 +38,8 @@ module SakaiInfo
38
38
  "content" => Content,
39
39
  "announcement" => Announcement,
40
40
  "announcement-channel" => AnnouncementChannel,
41
+ "gradebook" => Gradebook,
42
+ "gradebook-item" => GradebookItem,
41
43
  }
42
44
  end
43
45
  end
@@ -2,7 +2,7 @@
2
2
  # - sin command line help
3
3
  #
4
4
  # Created 2012-02-19 daveadams@gmail.com
5
- # Last updated 2012-05-10 daveadams@gmail.com
5
+ # Last updated 2012-05-12 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -21,7 +21,7 @@ sin #{VERSION}
21
21
  user, group, site, page, tool, quiz, quiz-section, quiz-item, quiz-attempt,
22
22
  quiz-attempt-item, quiz-attempt-item-attachment, question-pool, assignment,
23
23
  assignment-submission, forum, forum-thread, forum-post, content,
24
- announcement, announcement-channel
24
+ announcement, announcement-channel, gradebook, gradebook-item
25
25
 
26
26
  Misc commands:
27
27
  test Tests configured database connections
@@ -99,7 +99,6 @@ sin user
99
99
 
100
100
  --sites Print site membership information
101
101
  --pools Print list of owned question pools
102
- --all Print all possible details
103
102
  EOF
104
103
 
105
104
  "group" => <<EOF,
@@ -112,7 +111,6 @@ sin group
112
111
 
113
112
  --users Print user membership information
114
113
  --realm Print corresponding realm information
115
- --all Print all possible details
116
114
  EOF
117
115
 
118
116
  "site" => <<EOF,
@@ -133,7 +131,6 @@ sin site
133
131
  --realm Print site realm details
134
132
  --forums Print forum details
135
133
  --mod Print creation/modification info
136
- --all Print all possible details
137
134
  EOF
138
135
 
139
136
  "page" => <<EOF,
@@ -164,7 +161,6 @@ sin quiz
164
161
  --sections Print section summary list
165
162
  --attempts Print summary of user quiz attempts
166
163
  --mod Print creation/modification info
167
- --all Print all possible details
168
164
 
169
165
  Not yet implemented:
170
166
  --items Print summary of items on the quiz
@@ -181,7 +177,6 @@ sin quiz-section
181
177
 
182
178
  --items Print summary of items in the section
183
179
  --mod Print creation/modification info
184
- --all Print all possible details
185
180
  EOF
186
181
 
187
182
  "quiz-item" => <<EOF,
@@ -194,7 +189,6 @@ sin quiz-item
194
189
  passed to include additional information:
195
190
 
196
191
  --mod Print creation/modification info
197
- --all Print all possible details
198
192
  EOF
199
193
 
200
194
  "question-pool" => <<EOF,
@@ -211,7 +205,6 @@ sin question-pool
211
205
  Not yet implemented:
212
206
  --items Print summary of items in the pool
213
207
  --quizzes Print summary of quizzes that link to this pool
214
- --all Print all possible details
215
208
  EOF
216
209
 
217
210
  "quiz-attempt" => <<EOF,
@@ -223,7 +216,6 @@ sin quiz-attempt
223
216
  may be passed to include additional information:
224
217
 
225
218
  --items Print list of attempted items
226
- --all Print all possible details
227
219
  EOF
228
220
 
229
221
 
@@ -236,7 +228,6 @@ sin quiz-attempt-item
236
228
  options may be passed to include additional information:
237
229
 
238
230
  --attachments Print a list of file attachments, if any
239
- --all Print all possible details
240
231
  EOF
241
232
 
242
233
  "quiz-attempt-item-attachment" => <<EOF,
@@ -248,7 +239,6 @@ sin quiz-attempt-item-attachment
248
239
  Additional options may be passed to include additional information:
249
240
 
250
241
  --mod Print creation/modification info
251
- --all Print all possible details
252
242
  EOF
253
243
 
254
244
  "assignment" => <<EOF,
@@ -262,7 +252,6 @@ sin assignment
262
252
  --submissions Print summary of all submissions
263
253
  --xml Print the raw XML
264
254
  --mod Print creation/modification info
265
- --all Print all possible details
266
255
  EOF
267
256
 
268
257
  "assignment-submission" => <<EOF,
@@ -275,7 +264,6 @@ sin assignment-submission
275
264
 
276
265
  --xml Print the raw XML
277
266
  --mod Print creation/modification info
278
- --all Print all possible details
279
267
  EOF
280
268
 
281
269
  "forum" => <<EOF,
@@ -288,7 +276,6 @@ sin forum
288
276
 
289
277
  --threads Print summary of all threads
290
278
  --mod Print creation/modification info
291
- --all Print all possible details
292
279
  EOF
293
280
 
294
281
  "forum-thread" => <<EOF,
@@ -301,7 +288,6 @@ sin forum-thread
301
288
 
302
289
  --posts Print summary of all posts
303
290
  --mod Print creation/modification info
304
- --all Print all possible details
305
291
  EOF
306
292
 
307
293
  "forum-post" => <<EOF,
@@ -313,7 +299,6 @@ sin forum-post
313
299
  may be passed to include additional information:
314
300
 
315
301
  --mod Print creation/modification info
316
- --all Print all possible details
317
302
  EOF
318
303
 
319
304
  "content" => <<EOF,
@@ -327,7 +312,6 @@ sin content
327
312
  --properties Print all properties
328
313
  --children Recursively print collection children
329
314
  --mod Print creation/modification info
330
- --all Print all possible details
331
315
  EOF
332
316
  "announcement" => <<EOF,
333
317
  sin announcement
@@ -338,10 +322,9 @@ sin announcement
338
322
  be passed to include additional information:
339
323
 
340
324
  --xml Print raw XML content
341
- --all Print all possible details
342
325
  EOF
343
326
  "announcement-channel" => <<EOF,
344
- sin content
327
+ sin announcement-channel
345
328
 
346
329
  Usage: sin announcement-channel <id> [<options>]
347
330
 
@@ -350,7 +333,23 @@ sin content
350
333
 
351
334
  --announcements Print a summary of all announcements in this channel
352
335
  --xml Print raw XML content
353
- --all Print all possible details
336
+ EOF
337
+ "gradebook" => <<EOF,
338
+ sin gradebook
339
+
340
+ Usage: sin gradebook <id> [<options>]
341
+
342
+ Prints information about the gradebook ID specified. Additional options may
343
+ be passed to include additional information:
344
+
345
+ --items Print all gradebook items
346
+ EOF
347
+ "gradebook-item" => <<EOF,
348
+ sin gradebook-item
349
+
350
+ Usage: sin gradebook-item <id> [<options>]
351
+
352
+ Prints information about the gradebook item ID specified.
354
353
  EOF
355
354
  }
356
355
 
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Gradebook library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-05-10 daveadams@gmail.com
5
+ # Last updated 2012-05-12 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -11,150 +11,151 @@
11
11
 
12
12
  module SakaiInfo
13
13
  class Gradebook < SakaiObject
14
- attr_reader :version, :site, :name
14
+ attr_reader :version, :site_id, :name
15
15
 
16
16
  def self.clear_cache
17
17
  @@cache = {}
18
- @@cache_by_site_id = {}
19
18
  end
20
19
  clear_cache
21
20
 
22
- def initialize(id, version, site, name)
23
- @id = id
24
- @version = version
25
- @site = site
26
- @name = name
21
+ def initialize(dbrow)
22
+ @dbrow = dbrow
23
+
24
+ @id = @dbrow[:id].to_i
25
+ @version = @dbrow[:version].to_i
26
+ @site_id = @dbrow[:gradebook_uid]
27
+ @name = @dbrow[:name]
27
28
  end
28
29
 
29
30
  def self.find(id)
30
31
  if @@cache[id].nil?
31
- row = DB.connect.fetch("select version, gradebook_uid, name " +
32
- "from gb_gradebook_t " +
33
- "where id = :id", id).first
32
+ row = DB.connect[:gb_gradebook_t].where(:id => id).first
34
33
  if row.nil?
35
34
  raise ObjectNotFoundException.new(Gradebook, id)
36
35
  end
37
36
 
38
- version = row[:version].to_i
39
- site = Site.find(row[:gradebook_uid])
40
- name = row[:name]
41
- @@cache[id] = Gradebook.new(id, version, site, name)
42
- @@cache_by_site_id[site.id] = @@cache[id]
37
+ @@cache[id] = Gradebook.new(row)
43
38
  end
44
39
  @@cache[id]
45
40
  end
46
41
 
47
- def self.find_by_site_id(site_id)
48
- if @@cache_by_site_id[site_id].nil?
49
- row = DB.connect.fetch("select id, version, name " +
50
- "from gb_gradebook_t " +
51
- "where gradebook_uid = ?", site_id).first
52
- if row.nil?
53
- raise ObjectNotFoundException.new(Gradebook, site_id)
54
- end
42
+ def site
43
+ @site ||= Site.find(self.site_id)
44
+ end
55
45
 
56
- id = row[:id].to_i
57
- version = row[:version].to_i
58
- name = row[:name]
59
- site = Site.find(site_id)
60
- @@cache[id] = Gradebook.new(id, version, site, name)
61
- @@cache_by_site_id[site_id] = @@cache[id]
62
- end
63
- @@cache_by_site_id[site_id]
46
+ def self.query_by_site_id(site_id)
47
+ DB.connect[:gb_gradebook_t].where(:gradebook_uid => site_id)
48
+ end
49
+
50
+ def self.count_by_site_id(site_id)
51
+ Gradebook.query_by_site_id(site_id).count
52
+ end
53
+
54
+ def self.find_by_site_id(site_id)
55
+ Gradebook.query_by_site_id(site_id).all.collect { |row| Gradebook.new(row) }
64
56
  end
65
57
 
66
58
  def items
67
- @items ||= GradableObject.find_by_gradebook_id(@id)
59
+ @items ||= GradebookItem.find_by_gradebook_id(self.id)
68
60
  end
69
61
 
70
62
  def item_count
71
- items.length
63
+ @item_count ||= GradebookItem.count_by_gradebook_id(self.id)
64
+ end
65
+
66
+ def default_serialization
67
+ {
68
+ "id" => self.id,
69
+ "name" => self.name,
70
+ "site" => self.site.serialize(:summary),
71
+ "version" => self.version,
72
+ "item_count" => self.item_count,
73
+ }
74
+ end
75
+
76
+ def summary_serialization
77
+ {
78
+ "id" => self.id,
79
+ "name" => self.name,
80
+ "site_id" => self.site_id,
81
+ "item_count" => self.item_count,
82
+ }
83
+ end
84
+
85
+ def site_summary_serialization
86
+ {
87
+ "id" => self.id,
88
+ }
89
+ end
90
+
91
+ def items_serialization
92
+ {
93
+ "items" => self.items.collect { |item| item.serialize(:summary) }
94
+ }
95
+ end
96
+
97
+ def self.all_serializations
98
+ [
99
+ :default,
100
+ :items
101
+ ]
72
102
  end
73
103
  end
74
104
 
75
- class GradableObject < SakaiObject
76
- attr_reader :id, :gradebook, :object_type, :version, :name
77
- attr_reader :points_possible, :due_date, :weight
105
+ class GradebookItem < SakaiObject
106
+ attr_reader :gradebook_id, :object_type_id, :version, :name, :points_possible, :due_date, :weight
78
107
 
79
108
  def self.clear_cache
80
109
  @@cache = {}
81
- @@cache_by_gradebook_id = {}
82
110
  end
83
111
  clear_cache
84
112
 
85
- def initialize(id, gradebook, object_type, version, name,
86
- points_possible, due_date, weight)
87
- @id = id
88
- @gradebook = gradebook
89
- @object_type = object_type
90
- @version = version
91
- @name = name
92
- @points_possible = points_possible
93
- @due_date = due_date
94
- @weight = weight
113
+ def initialize(dbrow)
114
+ @dbrow = dbrow
115
+
116
+ @id = @dbrow[:id]
117
+ @gradebook_id = @dbrow[:gradebook_id].to_i
118
+ @object_type_id = @dbrow[:object_type_id].to_i
119
+ @version = @dbrow[:version].to_i
120
+ @name = @dbrow[:name]
121
+ @points_possible = @dbrow[:points_possible].to_f
122
+ @due_date = @dbrow[:due_date]
123
+ @weight = @dbrow[:assignment_weighting].to_f
95
124
  end
96
125
 
97
126
  def self.find(id)
98
127
  if @@cache[id].nil?
99
- row = DB.connect.fetch("select gradebook_id, object_type_id, version, " +
100
- "name, points_possible, " +
101
- "to_char(due_date, 'YYYY-MM-DD') as due, " +
102
- "assignment_weighting " +
103
- "from gb_gradable_object_t " +
104
- "where id = ?", id).first
105
-
128
+ row = DB.connect[:gb_gradable_object_t].where(:id => id).first
106
129
  if row.nil?
107
- raise ObjectNotFoundException.new(GradableObject, id)
130
+ raise ObjectNotFoundException.new(GradebookItem, id)
108
131
  end
109
-
110
- gradebook = Gradebook.find(row[:gradebook_id].to_i)
111
- object_type = row[:object_type_id].to_i
112
- version = row[:version].to_i
113
- name = row[:name]
114
- points_possible = row[:points_possible].to_f
115
- due_date = row[:due]
116
- weight = row[:assignment_weighting].to_f
117
- @@cache[id] = GradableObject.new(id, gradebook, object_type,
118
- version, name, points_possible,
119
- due_date, weight)
132
+ @@cache[id] = GradebookItem.new(row)
120
133
  end
121
134
  @@cache[id]
122
135
  end
123
136
 
124
- def self.find_by_gradebook_id(gradebook_id)
125
- if @@cache_by_gradebook_id[gradebook_id].nil?
126
- objects = []
127
- gradebook = Gradebook.find(gradebook_id)
128
- DB.connect.fetch("select id, object_type_id, version, " +
129
- "name, points_possible, " +
130
- "to_char(due_date, 'YYYY-MM-DD') as due, " +
131
- "assignment_weighting " +
132
- "from gb_gradable_object_t " +
133
- "where gradebook_id = ? " +
134
- "order by due_date asc", gradebook_id) do |row|
135
- id = row[:id].to_i
136
- object_type = row[:object_type_id].to_i
137
- version = row[:version].to_i
138
- name = row[:name]
139
- points_possible = row[:points_possible].to_f
140
- due_date = row[:due]
141
- weight = row[:assignment_weighting].to_f
142
- objects << GradableObject.new(id, gradebook, object_type,
143
- version, name, points_possible,
144
- due_date, weight)
137
+ def gradebook
138
+ @gradebook = Gradebook.find(self.gradebook_id)
139
+ end
145
140
 
146
- end
147
- @@cache_by_gradebook_id[gradebook_id] = objects
148
- end
149
- @@cache_by_gradebook_id[gradebook_id]
141
+ def self.query_by_gradebook_id(gradebook_id)
142
+ DB.connect[:gb_gradable_object_t].where(:gradebook_id => gradebook_id)
143
+ end
144
+
145
+ def self.count_by_gradebook_id(gradebook_id)
146
+ GradebookItem.query_by_gradebook_id(gradebook_id).count
147
+ end
148
+
149
+ def self.find_by_gradebook_id(gradebook_id)
150
+ GradebookItem.query_by_gradebook_id(gradebook_id).all.collect { |row| GradebookItem.new(row) }
150
151
  end
151
152
 
152
153
  def default_serialization
153
154
  result = {
154
155
  "id" => self.id,
155
156
  "name" => self.name,
156
- "gradebook_id" => self.gradebook.id,
157
- "object_type" => self.object_type,
157
+ "gradebook_id" => self.gradebook_id,
158
+ "object_type_id" => self.object_type_id,
158
159
  "version" => self.version,
159
160
  "points_possible" => self.points_possible,
160
161
  "due_date" => self.due_date,
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Site library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-05-10 daveadams@gmail.com
5
+ # Last updated 2012-05-12 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -135,10 +135,7 @@ module SakaiInfo
135
135
 
136
136
  # gradebook properties
137
137
  def gradebook
138
- @gradebook ||= Gradebook.find_by_site_id(@id)
139
- rescue ObjectNotFoundException
140
- # not all sites have a gradebook, don't panic
141
- nil
138
+ @gradebook ||= Gradebook.find_by_site_id(@id).first
142
139
  end
143
140
 
144
141
  # forum properties
@@ -363,9 +360,9 @@ module SakaiInfo
363
360
  end
364
361
 
365
362
  def gradebook_serialization
366
- if self.gradebook and self.gradebook.item_count > 0
363
+ if self.gradebook
367
364
  {
368
- "gradebook_items" => self.gradebook.items.collect { |item| item.serialize(:summary) }
365
+ "gradebook" => self.gradebook.serialize(:site_summary, :items)
369
366
  }
370
367
  else
371
368
  {}
@@ -1,3 +1,3 @@
1
1
  module SakaiInfo
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sakai-info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-10 00:00:00.000000000 Z
12
+ date: 2012-05-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel