sakai-info 0.3.4 → 0.3.5

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.3.5 ##
4
+
5
+ *Released 2012-04-02*
6
+
7
+ * Basic Forum, ForumThread, and ForumPost support in CLI
8
+ * Refactored Forum support in library
9
+ * Fixed join_role serialization for Site
10
+
3
11
  ## 0.3.4 ##
4
12
 
5
13
  *Released 2012-03-09*
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # sakai-info #
2
2
 
3
- last updated: 2012-03-09
3
+ last updated: 2012-04-02
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.3.4.gem`.
27
+ `sakai-info-0.3.5.gem`.
28
28
 
29
29
  Cleanup built gems using:
30
30
 
data/ROADMAP.md CHANGED
@@ -1,38 +1,35 @@
1
1
  # sakai-info Roadmap #
2
2
 
3
- *Last updated 2012-03-09*
3
+ *Last updated 2012-04-02*
4
4
 
5
- ### 0.3.5 ###
5
+ ### 0.4.0 ###
6
6
 
7
- * CLI access to forums
8
-
9
- ### 0.3.6 ###
10
-
11
- * CLI access to gradebook
7
+ * CLI access to content
8
+ * Content binary entity parsing
9
+ * Command line tool name change to "sin"
12
10
 
13
- ### 0.3.7 ###
11
+ ### 0.4.1 ###
14
12
 
15
13
  * CLI access to announcements
16
14
 
17
- ### 0.3.8 ###
15
+ ### 0.4.2 ###
18
16
 
19
- * CLI access to content
17
+ * CLI access to gradebook
20
18
 
21
- ### 0.3.9 ###
19
+ ### 0.4.3 ###
22
20
 
23
21
  * CLI access to authz (realms, roles, functions)
24
22
 
25
- ### 0.4 ###
23
+ ### 0.5.0 ###
26
24
 
27
25
  * Sqlite test infrastructure for a few basic objects
28
- * Command line tool name change to "sin"
29
26
 
30
- ### 0.5 ###
27
+ ### 0.6.0 ###
31
28
 
32
29
  * Test fixtures and basic unit tests for all represented objects
33
30
  * RDoc coverage for every class
34
31
 
35
- ### 0.6 ###
32
+ ### 0.7.0 ###
36
33
 
37
34
  * Basic OSP support
38
35
 
data/lib/sakai-info.rb CHANGED
@@ -88,7 +88,8 @@ require 'sakai-info/authz'
88
88
  require 'sakai-info/content'
89
89
  require 'sakai-info/gradebook'
90
90
  require 'sakai-info/group'
91
- require 'sakai-info/message'
92
91
  require 'sakai-info/quiz'
93
92
  require 'sakai-info/question_pool'
93
+ require 'sakai-info/generic_message'
94
+ require 'sakai-info/forum'
94
95
 
@@ -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-03-09 daveadams@gmail.com
5
+ # Last updated 2012-04-02 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -32,6 +32,9 @@ module SakaiInfo
32
32
  "question-pool" => QuestionPool,
33
33
  "assignment" => Assignment,
34
34
  "assignment-submission" => AssignmentSubmission,
35
+ "forum" => Forum,
36
+ "forum-thread" => ForumThread,
37
+ "forum-post" => ForumPost,
35
38
  }
36
39
  end
37
40
  end
@@ -2,7 +2,7 @@
2
2
  # - sakai-info command line help
3
3
  #
4
4
  # Created 2012-02-19 daveadams@gmail.com
5
- # Last updated 2012-03-09 daveadams@gmail.com
5
+ # Last updated 2012-04-02 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -41,6 +41,10 @@ sakai-info #{VERSION}
41
41
  assignment-submission
42
42
  Assignment submission information
43
43
 
44
+ forum Forum information
45
+ forum-thread Forum Thread information
46
+ forum-post Forum Post information
47
+
44
48
  Misc commands:
45
49
  test Tests configured database connections
46
50
  help Prints general help
@@ -292,6 +296,44 @@ sakai-info assignment-submission
292
296
  --mod Print creation/modification info
293
297
  --all Print all possible details
294
298
  EOF
299
+
300
+ "forum" => <<EOF,
301
+ sakai-info forum
302
+
303
+ Usage: sakai-info forum <id> [<options>]
304
+
305
+ Prints information about the forum ID specified. Additional options may be
306
+ passed to include additional information:
307
+
308
+ --threads Print summary of all threads
309
+ --mod Print creation/modification info
310
+ --all Print all possible details
311
+ EOF
312
+
313
+ "forum-thread" => <<EOF,
314
+ sakai-info forum-thread
315
+
316
+ Usage: sakai-info forum-thread <id> [<options>]
317
+
318
+ Prints information about the forum thread ID specified. Additional options
319
+ may be passed to include additional information:
320
+
321
+ --posts Print summary of all posts
322
+ --mod Print creation/modification info
323
+ --all Print all possible details
324
+ EOF
325
+
326
+ "forum-post" => <<EOF,
327
+ sakai-info forum-post
328
+
329
+ Usage: sakai-info forum-post <id> [<options>]
330
+
331
+ Prints information about the forum post ID specified. Additional options
332
+ may be passed to include additional information:
333
+
334
+ --mod Print creation/modification info
335
+ --all Print all possible details
336
+ EOF
295
337
  }
296
338
 
297
339
  def self.help(topic = :default, io = STDOUT)
@@ -0,0 +1,263 @@
1
+ # sakai-info/forum.rb
2
+ # SakaiInfo::Forum library
3
+ #
4
+ # Created 2012-04-01 daveadams@gmail.com
5
+ # Last updated 2012-04-01 daveadams@gmail.com
6
+ #
7
+ # https://github.com/daveadams/sakai-info
8
+ #
9
+ # This software is public domain.
10
+ #
11
+
12
+ module SakaiInfo
13
+ class Forum < SakaiObject
14
+ attr_reader :id, :title, :dbrow
15
+
16
+ include ModProps
17
+ created_by_key :created_by
18
+ created_at_key :created
19
+ modified_by_key :modified_by
20
+ modified_at_key :modified
21
+
22
+ @@cache = {}
23
+ def self.find(id)
24
+ if @@cache[id.to_s].nil?
25
+ row = DB.connect[:mfr_open_forum_t].where(:id => id).first
26
+ if row.nil?
27
+ raise ObjectNotFoundException.new(Forum, id)
28
+ end
29
+ @@cache[id.to_s] = Forum.new(row)
30
+ end
31
+ @@cache[id.to_s]
32
+ end
33
+
34
+ def initialize(dbrow)
35
+ @dbrow = dbrow
36
+
37
+ @id = dbrow[:id].to_i
38
+ @title = dbrow[:title]
39
+ @area_id = dbrow[:surrogatekey]
40
+
41
+ @site_id_is_nil = false
42
+ end
43
+
44
+ def site_id
45
+ return nil if @site_id_is_nil
46
+
47
+ if @site_id.nil?
48
+ result = DB.connect[:mfr_area_t].
49
+ select(:context_id).where(:id => @area_id).first
50
+ if result.nil?
51
+ @site_id_is_nil = true
52
+ return nil
53
+ else
54
+ @site_id = result[:context_id]
55
+ end
56
+ end
57
+ @site_id
58
+ end
59
+
60
+ def site
61
+ if self.site_id.nil?
62
+ return nil
63
+ end
64
+
65
+ @site ||= Site.find(self.site_id)
66
+ end
67
+
68
+ def thread_count
69
+ @thread_count ||= ForumThread.count_by_forum_id(self.id)
70
+ end
71
+
72
+ def threads
73
+ @threads ||= ForumThread.find_by_forum_id(self.id)
74
+ end
75
+
76
+ def self.query_by_site_id(site_id)
77
+ db = DB.connect
78
+ db[:mfr_open_forum_t].
79
+ where(:surrogatekey =>
80
+ db[:mfr_area_t].select(:id).where(:context_id => site_id)).
81
+ where(:forum_dtype => "DF")
82
+ end
83
+
84
+ def self.count_by_site_id(site_id)
85
+ Forum.query_by_site_id(site_id).count
86
+ end
87
+
88
+ def self.find_by_site_id(site_id)
89
+ Forum.query_by_site_id(site_id).all.
90
+ collect { |row| @@cache[row[:id].to_i.to_s] = Forum.new(row) }
91
+ end
92
+
93
+ def default_serialization
94
+ {
95
+ "id" => self.id,
96
+ "title" => self.title,
97
+ "site" => self.site.serialize(:summary),
98
+ "thread_count" => self.thread_count,
99
+ }
100
+ end
101
+
102
+ def threads_serialization
103
+ {
104
+ "threads" => self.threads.collect { |t| t.serialize(:summary) }
105
+ }
106
+ end
107
+
108
+ def summary_serialization
109
+ {
110
+ "id" => self.id,
111
+ "title" => self.title
112
+ }
113
+ end
114
+
115
+ def self.all_serializations
116
+ [ :default, :threads ]
117
+ end
118
+ end
119
+
120
+ class ForumThread < GenericThread
121
+ attr_reader :id, :title, :dbrow
122
+
123
+ include ModProps
124
+ created_by_key :created_by
125
+ created_at_key :created
126
+ modified_by_key :modified_by
127
+ modified_at_key :modified
128
+
129
+ @@cache = {}
130
+ def self.find(id)
131
+ if @@cache[id.to_s].nil?
132
+ row = DB.connect[:mfr_topic_t].where(:id => id, :topic_dtype => "DT").first
133
+ if row.nil?
134
+ raise ObjectNotFoundException.new(ForumThread, id)
135
+ end
136
+ @@cache[id.to_s] = ForumThread.new(row)
137
+ end
138
+ @@cache[id.to_s]
139
+ end
140
+
141
+ def initialize(dbrow)
142
+ @dbrow = dbrow
143
+
144
+ @id = dbrow[:id].to_i
145
+ @title = dbrow[:title]
146
+ end
147
+
148
+ def post_count
149
+ @post_count ||= ForumPost.count_by_thread_id(self.id)
150
+ end
151
+
152
+ def posts
153
+ @posts ||= ForumPost.find_by_thread_id(self.id)
154
+ end
155
+
156
+ def self.query_by_forum_id(forum_id)
157
+ DB.connect[:mfr_topic_t].where(:of_surrogatekey => forum_id)
158
+ end
159
+
160
+ def self.count_by_forum_id(forum_id)
161
+ ForumThread.query_by_forum_id(forum_id).count
162
+ end
163
+
164
+ def self.find_by_forum_id(forum_id)
165
+ ForumThread.query_by_forum_id(forum_id).all.collect { |r| ForumThread.new(r) }
166
+ end
167
+
168
+ def default_serialization
169
+ {
170
+ "id" => self.id,
171
+ "title" => self.title,
172
+ "post_count" => self.post_count,
173
+ }
174
+ end
175
+
176
+ def posts_serialization
177
+ if self.post_count > 0
178
+ {
179
+ "posts" => self.posts.collect { |p| p.serialize(:summary) }
180
+ }
181
+ else
182
+ { }
183
+ end
184
+ end
185
+
186
+ def summary_serialization
187
+ {
188
+ "id" => self.id,
189
+ "title" => self.title,
190
+ }
191
+ end
192
+
193
+ def self.all_serializations
194
+ [ :default, :posts ]
195
+ end
196
+ end
197
+
198
+ class ForumPost < GenericMessage
199
+ attr_reader :id, :title, :dbrow
200
+
201
+ include ModProps
202
+ created_by_key :created_by
203
+ created_at_key :created
204
+ modified_by_key :modified_by
205
+ modified_at_key :modified
206
+
207
+ @@cache = {}
208
+ def self.find(id)
209
+ if @@cache[id.to_s].nil?
210
+ row = DB.connect[:mfr_message_t].where(:id => id, :message_dtype => "ME").first
211
+ if row.nil?
212
+ raise ObjectNotFoundException.new(ForumPost, id)
213
+ end
214
+ @@cache[id.to_s] = ForumPost.new(row)
215
+ end
216
+ @@cache[id.to_s]
217
+ end
218
+
219
+ def initialize(dbrow)
220
+ @dbrow = dbrow
221
+
222
+ @id = dbrow[:id].to_i
223
+ @title = dbrow[:title]
224
+ end
225
+
226
+ def author
227
+ @author ||= User.find(@dbrow[:author])
228
+ end
229
+
230
+ def thread
231
+ @thread ||= ForumThread.find(@dbrow[:surrogatekey])
232
+ end
233
+
234
+ def self.query_by_thread_id(thread_id)
235
+ DB.connect[:mfr_message_t].where(:surrogatekey => thread_id)
236
+ end
237
+
238
+ def self.count_by_thread_id(thread_id)
239
+ ForumPost.query_by_thread_id(thread_id).count
240
+ end
241
+
242
+ def self.find_by_thread_id(thread_id)
243
+ ForumPost.query_by_thread_id(thread_id).all.collect { |r| ForumPost.new(r) }
244
+ end
245
+
246
+ def default_serialization
247
+ {
248
+ "id" => self.id,
249
+ "title" => self.title,
250
+ "author" => self.author.serialize(:summary),
251
+ "thread" => self.thread.serialize(:summary),
252
+ }
253
+ end
254
+
255
+ def summary_serialization
256
+ {
257
+ "id" => self.id,
258
+ "title" => self.title,
259
+ }
260
+ end
261
+ end
262
+ end
263
+
@@ -0,0 +1,67 @@
1
+ # sakai-info/generic_message.rb
2
+ # SakaiInfo::GenericMessage library
3
+ #
4
+ # Created 2012-04-01 daveadams@gmail.com
5
+ # Last updated 2012-04-01 daveadams@gmail.com
6
+ #
7
+ # https://github.com/daveadams/sakai-info
8
+ #
9
+ # This software is public domain.
10
+ #
11
+
12
+ module SakaiInfo
13
+ class UnknownMessageTypeException < SakaiException; end
14
+ class GenericMessage < SakaiObject
15
+ def self.types
16
+ {
17
+ "ME" => "Forum Post",
18
+ "PM" => "Private Message"
19
+ }
20
+ end
21
+
22
+ def self.valid_message_type?(mt)
23
+ GenericMessage.types.keys.include?(mt)
24
+ end
25
+
26
+ def self.count_by_date_and_message_type(count_date, message_type)
27
+ date_str = nil
28
+ if count_date.is_a? Time
29
+ date_str = count_date.strftime("%Y-%m-%d")
30
+ elsif count_date.is_a? String
31
+ if count_date =~ /^\d\d\d\d-\d\d-\d\d$/
32
+ date_str = count_date
33
+ else
34
+ raise InvalidDateException
35
+ end
36
+ else
37
+ raise InvalidDateException
38
+ end
39
+
40
+ if not valid_message_type? message_type
41
+ raise UnknownMessageTypeException
42
+ end
43
+
44
+ DB.connect.fetch("select count(*) as count from mfr_message_t " +
45
+ "where message_dtype = ? and " +
46
+ "to_char(created,'YYYY-MM-DD') = ? ",
47
+ message_type, date_str).first[:count].to_i
48
+ end
49
+ end
50
+
51
+ class GenericThread < SakaiObject
52
+ def self.types
53
+ {
54
+ "TO" => "Generic Thread",
55
+ "PT" => "Private Thread",
56
+ "OT" => "Open Thread",
57
+ "DT" => "Discussion Thread"
58
+ }
59
+ end
60
+
61
+ def self.valid_message_type?(mt)
62
+ GenericThread.types.keys.include?(mt)
63
+ end
64
+ end
65
+ end
66
+
67
+
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Site library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-03-09 daveadams@gmail.com
5
+ # Last updated 2012-04-01 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -244,7 +244,7 @@ module SakaiInfo
244
244
  "site_properties" => self.properties,
245
245
  "providers" => self.realm.providers,
246
246
  "is_joinable" => self.joinable?,
247
- "join_role" => (self.joinable? ? self.join_role : nil),
247
+ "join_role" => (self.joinable? ? self.join_role.name : nil),
248
248
  "user_count" => self.user_count,
249
249
  "group_count" => self.group_count,
250
250
  "page_count" => self.page_count,
@@ -1,3 +1,3 @@
1
1
  module SakaiInfo
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sakai-info
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Adams
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-09 00:00:00 -06:00
18
+ date: 2012-04-02 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,7 @@ files:
64
64
  - lib/sakai-info/authz.rb
65
65
  - lib/sakai-info/gradebook.rb
66
66
  - lib/sakai-info/mod_props.rb
67
+ - lib/sakai-info/forum.rb
67
68
  - lib/sakai-info/sakai_object.rb
68
69
  - lib/sakai-info/quiz.rb
69
70
  - lib/sakai-info/user.rb
@@ -72,6 +73,7 @@ files:
72
73
  - lib/sakai-info/database.rb
73
74
  - lib/sakai-info/cli.rb
74
75
  - lib/sakai-info/question_pool.rb
76
+ - lib/sakai-info/generic_message.rb
75
77
  - lib/sakai-info/message.rb
76
78
  - lib/sakai-info/content.rb
77
79
  - lib/sakai-info/page.rb