osm 0.0.19 → 0.0.20
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/CHANGELOG.md +9 -0
- data/README.md +32 -2
- data/lib/osm.rb +1 -0
- data/lib/osm/api.rb +178 -65
- data/lib/osm/event.rb +12 -9
- data/lib/osm/flexi_record_data.rb +68 -0
- data/lib/osm/flexi_record_field.rb +41 -0
- data/lib/osm/register_data.rb +10 -14
- data/lib/osm/role.rb +1 -1
- data/lib/osm/section.rb +5 -2
- data/spec/osm/api_spec.rb +109 -3
- data/spec/osm/api_strangeness_spec.rb +28 -1
- data/spec/osm/event_spec.rb +3 -1
- data/spec/osm/flexi_record_data_spec.rb +40 -0
- data/spec/osm/flexi_record_field_spec.rb +23 -0
- data/version.rb +1 -1
- metadata +20 -16
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## Version 0.0.20
|
2
|
+
|
3
|
+
* Start deprecation of api\_data option in Api methods (raise a warning and adjust documentation)
|
4
|
+
* Hide sesitive information when printing data sent to OSM in debug mode
|
5
|
+
* Add archived attribute to Event
|
6
|
+
* Add :include\_archived option to Api.get\_events method
|
7
|
+
* Add retreival of Flexi Records
|
8
|
+
* Make set\_user method of Api public
|
9
|
+
|
1
10
|
## Version 0.0.19
|
2
11
|
|
3
12
|
* Fix caching error in Api.get\_register\_data
|
data/README.md
CHANGED
@@ -73,12 +73,14 @@ however it should be noted that when the OSM API adds a feature it can be diffic
|
|
73
73
|
* API Access for our app
|
74
74
|
* Due Badges
|
75
75
|
* Events
|
76
|
+
* Flexi Record Data
|
77
|
+
* Flexi Record Structure
|
76
78
|
* Groupings (e.g. Sixes, Patrols)
|
77
79
|
* Members
|
78
80
|
* Notepad
|
79
81
|
* Notepads
|
80
82
|
* Programme
|
81
|
-
* Register
|
83
|
+
* Register Data
|
82
84
|
* Register Structure
|
83
85
|
* Roles
|
84
86
|
* Section
|
@@ -93,4 +95,32 @@ however it should be noted that when the OSM API adds a feature it can be diffic
|
|
93
95
|
* Evening
|
94
96
|
|
95
97
|
### Actions
|
96
|
-
* Authorise an app to use the API on a user's behalf
|
98
|
+
* Authorise an app to use the API on a user's behalf
|
99
|
+
|
100
|
+
|
101
|
+
## Parts of the OSM API currently NOT supported:
|
102
|
+
|
103
|
+
* Retreival of leader access
|
104
|
+
* Terms:
|
105
|
+
* Create
|
106
|
+
* Update
|
107
|
+
* Register - Update attendance
|
108
|
+
* Flexi Record - Update data
|
109
|
+
* Events:
|
110
|
+
* Attendance (everything)
|
111
|
+
* Create
|
112
|
+
* Update
|
113
|
+
* Member:
|
114
|
+
* Update
|
115
|
+
* Add
|
116
|
+
* Badges:
|
117
|
+
* Which requirements each member has met:
|
118
|
+
* Retreive
|
119
|
+
* Update
|
120
|
+
* Retrieve details for each badge (stock, short column names etc.)
|
121
|
+
* Update Activity
|
122
|
+
* Gift aid (everything)
|
123
|
+
* Finances (Everything)
|
124
|
+
* SMS:
|
125
|
+
* Retreival of delivery reports
|
126
|
+
* Sending a message
|
data/lib/osm.rb
CHANGED
@@ -6,6 +6,7 @@ module Osm
|
|
6
6
|
OSM_DATE_FORMAT = '%Y-%m-%d'
|
7
7
|
OSM_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
8
8
|
OSM_TIME_REGEX = /\A(?:[0-1][0-9]|2[0-3]):[0-5][0-9]\Z/
|
9
|
+
OSM_DATE_REGEX = /\A\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])\Z/
|
9
10
|
end
|
10
11
|
|
11
12
|
require File.join(File.dirname(__FILE__), '..', 'version')
|
data/lib/osm/api.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# @option options [Boolean] :no_cache (optional) if true then the data will be retreived from OSM not the cache
|
4
4
|
|
5
5
|
# @!macro [new] options_api_data
|
6
|
-
# @param [Hash] api_data
|
6
|
+
# @param [Hash] api_data - DEPRECATED (DO NOT USE THIS OPTION)
|
7
7
|
# @option api_data [String] 'userid' (optional) the OSM userid to make the request as
|
8
8
|
# @option api_data [String] 'secret' (optional) the OSM secret belonging to the above user
|
9
9
|
|
@@ -102,14 +102,25 @@ module Osm
|
|
102
102
|
return data
|
103
103
|
end
|
104
104
|
|
105
|
+
# Set the OSM user to make future requests as
|
106
|
+
# @param [String] userid the OSM userid to use (get this using the authorize method)
|
107
|
+
# @param [String] secret the OSM secret to use (get this using the authorize method)
|
108
|
+
def set_user(userid, secret)
|
109
|
+
@userid = userid
|
110
|
+
@secret = secret
|
111
|
+
end
|
112
|
+
|
113
|
+
|
105
114
|
# Get the user's roles
|
106
115
|
# @!macro options_get
|
107
116
|
# @!macro options_api_data
|
108
117
|
# @return [Array<Osm::Role>]
|
109
118
|
def get_roles(options={}, api_data={})
|
119
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
120
|
+
cache_key = "roles-#{api_data[:userid] || @userid}"
|
110
121
|
|
111
|
-
if !options[:no_cache] && cache_exist?(
|
112
|
-
return cache_read(
|
122
|
+
if !options[:no_cache] && cache_exist?(cache_key)
|
123
|
+
return cache_read(cache_key)
|
113
124
|
end
|
114
125
|
|
115
126
|
data = perform_query('api.php?action=getUserRoles', api_data)
|
@@ -121,7 +132,7 @@ module Osm
|
|
121
132
|
cache_write("section-#{role.section.id}", role.section, :expires_in => @@default_cache_ttl*2)
|
122
133
|
self.user_can_access :section, role.section.id, api_data
|
123
134
|
end
|
124
|
-
cache_write(
|
135
|
+
cache_write(cache_key, result, :expires_in => @@default_cache_ttl*2)
|
125
136
|
|
126
137
|
return result
|
127
138
|
end
|
@@ -131,8 +142,11 @@ module Osm
|
|
131
142
|
# @!macro options_api_data
|
132
143
|
# @return [Hash] a hash (keys are section IDs, values are a string)
|
133
144
|
def get_notepads(options={}, api_data={})
|
134
|
-
|
135
|
-
|
145
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
146
|
+
cache_key = "notepads-#{api_data[:userid] || @userid}"
|
147
|
+
|
148
|
+
if !options[:no_cache] && cache_exist?(cache_key)
|
149
|
+
return cache_read(cache_key)
|
136
150
|
end
|
137
151
|
|
138
152
|
notepads = perform_query('api.php?action=getNotepads', api_data)
|
@@ -144,7 +158,7 @@ module Osm
|
|
144
158
|
cache_write("notepad-#{key}", value, :expires_in => @@default_cache_ttl*2)
|
145
159
|
end
|
146
160
|
|
147
|
-
cache_write(
|
161
|
+
cache_write(cache_key, data, :expires_in => @@default_cache_ttl*2)
|
148
162
|
return data
|
149
163
|
end
|
150
164
|
|
@@ -155,10 +169,12 @@ module Osm
|
|
155
169
|
# @return nil if an error occured or the user does not have access to that section
|
156
170
|
# @return [String] the content of the notepad otherwise
|
157
171
|
def get_notepad(section, options={}, api_data={})
|
172
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
158
173
|
section_id = id_for_section(section)
|
174
|
+
cache_key = "notepad-#{section_id}"
|
159
175
|
|
160
|
-
if !options[:no_cache] && cache_exist?(
|
161
|
-
return cache_read(
|
176
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:section, section_id, api_data)
|
177
|
+
return cache_read(cache_key)
|
162
178
|
end
|
163
179
|
|
164
180
|
notepads = get_notepads(options, api_data)
|
@@ -178,8 +194,11 @@ module Osm
|
|
178
194
|
# @return nil if an error occured or the user does not have access to that section
|
179
195
|
# @return [Osm::Section]
|
180
196
|
def get_section(section_id, options={}, api_data={})
|
181
|
-
|
182
|
-
|
197
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
198
|
+
cache_key = "section-#{section_id}"
|
199
|
+
|
200
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:section, section_id, api_data)
|
201
|
+
return cache_read(cache_key)
|
183
202
|
end
|
184
203
|
|
185
204
|
roles = get_roles(options, api_data)
|
@@ -198,10 +217,12 @@ module Osm
|
|
198
217
|
# @!macro options_api_data
|
199
218
|
# @return [Array<Osm::Grouping>]
|
200
219
|
def get_groupings(section, options={}, api_data={})
|
220
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
201
221
|
section_id = id_for_section(section)
|
222
|
+
cache_key = "groupings-#{section_id}"
|
202
223
|
|
203
|
-
if !options[:no_cache] && cache_exist?(
|
204
|
-
return cache_read(
|
224
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:section, section_id, api_data)
|
225
|
+
return cache_read(cache_key)
|
205
226
|
end
|
206
227
|
|
207
228
|
data = perform_query("users.php?action=getPatrols§ionid=#{section_id}", api_data)
|
@@ -210,10 +231,9 @@ module Osm
|
|
210
231
|
data['patrols'].each do |item|
|
211
232
|
grouping = Osm::Grouping.from_api(item)
|
212
233
|
result.push grouping
|
213
|
-
cache_write("grouping-#{grouping.id}", grouping, :expires_in => @@default_cache_ttl*2)
|
214
234
|
self.user_can_access :grouping, grouping.id, api_data
|
215
235
|
end
|
216
|
-
cache_write(
|
236
|
+
cache_write(cache_key, result, :expires_in => @@default_cache_ttl*2)
|
217
237
|
|
218
238
|
return result
|
219
239
|
end
|
@@ -223,8 +243,11 @@ module Osm
|
|
223
243
|
# @!macro options_api_data
|
224
244
|
# @return [Array<Osm::Term>]
|
225
245
|
def get_terms(options={}, api_data={})
|
226
|
-
|
227
|
-
|
246
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
247
|
+
cache_key = "terms-#{api_data[:userid] || @userid}"
|
248
|
+
|
249
|
+
if !options[:no_cache] && cache_exist?(cache_key)
|
250
|
+
return cache_read(cache_key)
|
228
251
|
end
|
229
252
|
|
230
253
|
data = perform_query('api.php?action=getTerms', api_data)
|
@@ -239,7 +262,7 @@ module Osm
|
|
239
262
|
end
|
240
263
|
end
|
241
264
|
|
242
|
-
cache_write(
|
265
|
+
cache_write(cache_key, result, :expires_in => @@default_cache_ttl*2)
|
243
266
|
return result
|
244
267
|
end
|
245
268
|
|
@@ -250,8 +273,11 @@ module Osm
|
|
250
273
|
# @return nil if an error occured or the user does not have access to that term
|
251
274
|
# @return [Osm::Term]
|
252
275
|
def get_term(term_id, options={}, api_data={})
|
253
|
-
|
254
|
-
|
276
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
277
|
+
cache_key = "term-#{term_id}"
|
278
|
+
|
279
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:term, term_id, api_data)
|
280
|
+
return cache_read(cache_key)
|
255
281
|
end
|
256
282
|
|
257
283
|
terms = get_terms(options)
|
@@ -271,11 +297,13 @@ module Osm
|
|
271
297
|
# @!macro options_api_data
|
272
298
|
# @return [Array<Osm::Evening>]
|
273
299
|
def get_programme(section, term, options={}, api_data={})
|
300
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
274
301
|
section_id = id_for_section(section)
|
275
302
|
term_id = id_for_term(term, section, api_data)
|
303
|
+
cache_key = "programme-#{section_id}-#{term_id}"
|
276
304
|
|
277
|
-
if !options[:no_cache] && cache_exist?(
|
278
|
-
return cache_read(
|
305
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:programme, section_id, api_data)
|
306
|
+
return cache_read(cache_key)
|
279
307
|
end
|
280
308
|
|
281
309
|
data = perform_query("programme.php?action=getProgramme§ionid=#{section_id}&termid=#{term_id}", api_data)
|
@@ -294,7 +322,7 @@ module Osm
|
|
294
322
|
end
|
295
323
|
end
|
296
324
|
|
297
|
-
cache_write(
|
325
|
+
cache_write(cache_key, result, :expires_in => @@default_cache_ttl)
|
298
326
|
return result
|
299
327
|
end
|
300
328
|
|
@@ -305,8 +333,11 @@ module Osm
|
|
305
333
|
# @!macro options_api_data
|
306
334
|
# @return [Osm::Activity]
|
307
335
|
def get_activity(activity_id, version=nil, options={}, api_data={})
|
308
|
-
|
309
|
-
|
336
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
337
|
+
cache_key = "activity-#{activity_id}-"
|
338
|
+
|
339
|
+
if !options[:no_cache] && cache_exist?("#{cache_key}-#{version}") && self.user_can_access?(:activity, activity_id, api_data)
|
340
|
+
return cache_read("#{cache_key}-#{version}")
|
310
341
|
end
|
311
342
|
|
312
343
|
data = nil
|
@@ -317,8 +348,8 @@ module Osm
|
|
317
348
|
end
|
318
349
|
|
319
350
|
activity = Osm::Activity.from_api(data)
|
320
|
-
cache_write("
|
321
|
-
cache_write("
|
351
|
+
cache_write("#{cache_key}-#{nil}", activity, :expires_in => @@default_cache_ttl*2) if version.nil?
|
352
|
+
cache_write("#{cache_key}-#{activity.version}", activity, :expires_in => @@default_cache_ttl/2)
|
322
353
|
self.user_can_access :activity, activity.id, api_data
|
323
354
|
|
324
355
|
return activity
|
@@ -331,11 +362,13 @@ module Osm
|
|
331
362
|
# @!macro options_api_data
|
332
363
|
# @return [Array<Osm::Member>]
|
333
364
|
def get_members(section, term=nil, options={}, api_data={})
|
365
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
334
366
|
section_id = id_for_section(section)
|
335
367
|
term_id = id_for_term(term, section, api_data)
|
368
|
+
cache_key = "members-#{section_id}-#{term_id}"
|
336
369
|
|
337
|
-
if !options[:no_cache] && cache_exist?(
|
338
|
-
return cache_read(
|
370
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:member, section_id, api_data)
|
371
|
+
return cache_read(cache_key)
|
339
372
|
end
|
340
373
|
|
341
374
|
data = perform_query("users.php?action=getUserDetails§ionid=#{section_id}&termid=#{term_id}", api_data)
|
@@ -345,7 +378,7 @@ module Osm
|
|
345
378
|
result.push Osm::Member.from_api(item)
|
346
379
|
end
|
347
380
|
self.user_can_access :member, section_id, api_data
|
348
|
-
cache_write(
|
381
|
+
cache_write(cache_key, result, :expires_in => @@default_cache_ttl)
|
349
382
|
|
350
383
|
return result
|
351
384
|
end
|
@@ -356,10 +389,12 @@ module Osm
|
|
356
389
|
# @!macro options_api_data
|
357
390
|
# @return [Array<Osm::ApiAccess>]
|
358
391
|
def get_api_access(section, options={}, api_data={})
|
392
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
359
393
|
section_id = id_for_section(section)
|
394
|
+
cache_key = "api_access-#{api_data['userid'] || @userid}-#{section_id}"
|
360
395
|
|
361
|
-
if !options[:no_cache] && cache_exist?(
|
362
|
-
return cache_read(
|
396
|
+
if !options[:no_cache] && cache_exist?(cache_key)
|
397
|
+
return cache_read(cache_key)
|
363
398
|
end
|
364
399
|
|
365
400
|
data = perform_query("users.php?action=getAPIAccess§ionid=#{section_id}", api_data)
|
@@ -371,8 +406,9 @@ module Osm
|
|
371
406
|
self.user_can_access(:programme, section_id, api_data) if this_item.can_read?(:programme)
|
372
407
|
self.user_can_access(:member, section_id, api_data) if this_item.can_read?(:member)
|
373
408
|
self.user_can_access(:badge, section_id, api_data) if this_item.can_read?(:badge)
|
374
|
-
cache_write("
|
409
|
+
cache_write("#{cache_key}-#{this_item.id}", this_item, :expires_in => @@default_cache_ttl*2)
|
375
410
|
end
|
411
|
+
cache_write(cache_key, result, :expires_in => @@default_cache_ttl*2)
|
376
412
|
|
377
413
|
return result
|
378
414
|
end
|
@@ -383,10 +419,12 @@ module Osm
|
|
383
419
|
# @!macro options_api_data
|
384
420
|
# @return [Osm::ApiAccess]
|
385
421
|
def get_our_api_access(section, options={}, api_data={})
|
422
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
386
423
|
section_id = id_for_section(section)
|
424
|
+
cache_key = "api_access-#{api_data['userid'] || @userid}-#{section_id}-#{Osm::Api.api_id}"
|
387
425
|
|
388
|
-
if !options[:no_cache] && cache_exist?(
|
389
|
-
return cache_read(
|
426
|
+
if !options[:no_cache] && cache_exist?(cache_key)
|
427
|
+
return cache_read(cache_key)
|
390
428
|
end
|
391
429
|
|
392
430
|
data = get_api_access(section_id, options)
|
@@ -401,27 +439,35 @@ module Osm
|
|
401
439
|
# Get events
|
402
440
|
# @param [Osm:Section, Fixnum] section the section (or its ID) to get the events for
|
403
441
|
# @!macro options_get
|
442
|
+
# @option options [Boolean] :include_archived (optional) if true then archived activities will also be returned
|
404
443
|
# @!macro options_api_data
|
405
444
|
# @return [Array<Osm::Event>]
|
406
445
|
def get_events(section, options={}, api_data={})
|
446
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
407
447
|
section_id = id_for_section(section)
|
448
|
+
cache_key = "events-#{section_id}"
|
449
|
+
events = nil
|
408
450
|
|
409
|
-
if !options[:no_cache] && cache_exist?(
|
410
|
-
|
411
|
-
|
451
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:programme, section_id, api_data)
|
452
|
+
events = cache_read(cache_key)
|
453
|
+
else
|
412
454
|
|
413
|
-
|
455
|
+
data = perform_query("events.php?action=getEvents§ionid=#{section_id}&showArchived=true", api_data)
|
414
456
|
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
457
|
+
events = Array.new
|
458
|
+
unless data['items'].nil?
|
459
|
+
data['items'].each do |item|
|
460
|
+
events.push Osm::Event.from_api(item)
|
461
|
+
end
|
419
462
|
end
|
463
|
+
self.user_can_access :programme, section_id, api_data
|
464
|
+
cache_write(cache_key, events, :expires_in => @@default_cache_ttl)
|
420
465
|
end
|
421
|
-
self.user_can_access :programme, section_id, api_data
|
422
|
-
cache_write("events-#{section_id}", result, :expires_in => @@default_cache_ttl)
|
423
466
|
|
424
|
-
return
|
467
|
+
return events if options[:include_archived]
|
468
|
+
return events.reject do |event|
|
469
|
+
event.archived?
|
470
|
+
end
|
425
471
|
end
|
426
472
|
|
427
473
|
# Get due badges
|
@@ -430,19 +476,21 @@ module Osm
|
|
430
476
|
# @!macro options_api_data
|
431
477
|
# @return [Osm::DueBadges]
|
432
478
|
def get_due_badges(section, term=nil, options={}, api_data={})
|
479
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
433
480
|
section_id = id_for_section(section)
|
481
|
+
section_type = type_for_section(section, api_data)
|
434
482
|
term_id = id_for_term(term, section, api_data)
|
483
|
+
cache_key = "due_badges-#{section_id}-#{term_id}"
|
435
484
|
|
436
|
-
if !options[:no_cache] && cache_exist?(
|
437
|
-
return cache_read(
|
485
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:badge, section_id, api_data)
|
486
|
+
return cache_read(cache_key)
|
438
487
|
end
|
439
488
|
|
440
|
-
section_type = get_section(section_id, api_data).type.to_s
|
441
489
|
data = perform_query("challenges.php?action=outstandingBadges§ion=#{section_type}§ionid=#{section_id}&termid=#{term_id}", api_data)
|
442
490
|
|
443
491
|
data = Osm::DueBadges.from_api(data)
|
444
492
|
self.user_can_access :badge, section_id, api_data
|
445
|
-
cache_write(
|
493
|
+
cache_write(cache_key, data, :expires_in => @@default_cache_ttl*2)
|
446
494
|
|
447
495
|
return data
|
448
496
|
end
|
@@ -454,11 +502,13 @@ module Osm
|
|
454
502
|
# @!macro options_api_data
|
455
503
|
# @return [Array<Osm::RegisterField>] representing the fields of the register
|
456
504
|
def get_register_structure(section, term=nil, options={}, api_data={})
|
505
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
457
506
|
section_id = id_for_section(section)
|
458
507
|
term_id = id_for_term(term, section, api_data)
|
508
|
+
cache_key = "register_structure-#{section_id}-#{term_id}"
|
459
509
|
|
460
|
-
if !options[:no_cache] && cache_exist?(
|
461
|
-
return cache_read(
|
510
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:register, section_id, api_data)
|
511
|
+
return cache_read(cache_key)
|
462
512
|
end
|
463
513
|
|
464
514
|
data = perform_query("users.php?action=registerStructure§ionid=#{section_id}&termid=#{term_id}", api_data)
|
@@ -470,7 +520,7 @@ module Osm
|
|
470
520
|
end
|
471
521
|
end
|
472
522
|
self.user_can_access :register, section_id, api_data
|
473
|
-
cache_write(
|
523
|
+
cache_write(cache_key, structure, :expires_in => @@default_cache_ttl/2)
|
474
524
|
|
475
525
|
return structure
|
476
526
|
end
|
@@ -482,11 +532,13 @@ module Osm
|
|
482
532
|
# @!macro options_api_data
|
483
533
|
# @return [Array<RegisterData>] representing the attendance of each member
|
484
534
|
def get_register_data(section, term=nil, options={}, api_data={})
|
535
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
485
536
|
section_id = id_for_section(section)
|
486
537
|
term_id = id_for_term(term, section, api_data)
|
538
|
+
cache_key = "register-#{section_id}-#{term_id}"
|
487
539
|
|
488
|
-
if !options[:no_cache] && cache_exist?(
|
489
|
-
return cache_read(
|
540
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:register, section_id, api_data)
|
541
|
+
return cache_read(cache_key)
|
490
542
|
end
|
491
543
|
|
492
544
|
data = perform_query("users.php?action=register§ionid=#{section_id}&termid=#{term_id}", api_data)
|
@@ -497,7 +549,65 @@ module Osm
|
|
497
549
|
to_return.push Osm::RegisterData.from_api(item)
|
498
550
|
end
|
499
551
|
self.user_can_access :register, section_id, api_data
|
500
|
-
cache_write(
|
552
|
+
cache_write(cache_key, to_return, :expires_in => @@default_cache_ttl/2)
|
553
|
+
return to_return
|
554
|
+
end
|
555
|
+
|
556
|
+
# Get flexirecord structure
|
557
|
+
# @param [Osm:Section, Fixnum] section the section (or its ID) to get the structure for
|
558
|
+
# @param [Fixnum] the id of the Flexi Record
|
559
|
+
# @!macro options_get
|
560
|
+
# @!macro options_api_data
|
561
|
+
# @return [Array<Osm::FlexiRecordField>] representing the fields of the flexi record
|
562
|
+
def get_flexi_record_fields(section, id, options={}, api_data={})
|
563
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
564
|
+
section_id = id_for_section(section)
|
565
|
+
cache_key = "flexi_record_structure-#{section_id}-#{id}"
|
566
|
+
|
567
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:flexi, section_id, api_data)
|
568
|
+
return cache_read(cache_key)
|
569
|
+
end
|
570
|
+
|
571
|
+
data = perform_query("extras.php?action=getExtra§ionid=#{section_id}&extraid=#{id}", api_data)
|
572
|
+
|
573
|
+
structure = []
|
574
|
+
data['structure'].each do |item|
|
575
|
+
item['rows'].each do |row|
|
576
|
+
structure.push Osm::FlexiRecordField.from_api(row)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
self.user_can_access :flexi, section_id, api_data
|
580
|
+
cache_write(cache_key, structure, :expires_in => @@default_cache_ttl/2)
|
581
|
+
|
582
|
+
return structure
|
583
|
+
end
|
584
|
+
|
585
|
+
# Get flexi record data
|
586
|
+
# @param [Osm:Section, Fixnum] section the section (or its ID) to get the register for
|
587
|
+
# @param [Fixnum] the id of the Flexi Record
|
588
|
+
# @param [Osm:Term, Fixnum] section the term (or its ID) to get the register for, passing nil causes the current term to be used
|
589
|
+
# @!macro options_get
|
590
|
+
# @!macro options_api_data
|
591
|
+
# @return [Array<FlexiRecordData>]
|
592
|
+
def get_flexi_record_data(section, id, term=nil, options={}, api_data={})
|
593
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
594
|
+
section_id = id_for_section(section)
|
595
|
+
section_type = type_for_section(section, api_data)
|
596
|
+
term_id = id_for_term(term, section, api_data)
|
597
|
+
cache_key = "flexi_record_data-#{section_id}-#{term_id}-#{id}"
|
598
|
+
|
599
|
+
if !options[:no_cache] && cache_exist?(cache_key) && self.user_can_access?(:flexi, section_id, api_data)
|
600
|
+
return cache_read(cache_key)
|
601
|
+
end
|
602
|
+
|
603
|
+
data = perform_query("extras.php?action=getExtraRecords§ionid=#{section_id}&extraid=#{id}&termid=#{term_id}§ion=#{section_type}", api_data)
|
604
|
+
|
605
|
+
to_return = []
|
606
|
+
data['items'].each do |item|
|
607
|
+
to_return.push Osm::FlexiRecordData.from_api(item)
|
608
|
+
end
|
609
|
+
self.user_can_access :flexi, section_id, api_data
|
610
|
+
cache_write(cache_key, to_return, :expires_in => @@default_cache_ttl/2)
|
501
611
|
return to_return
|
502
612
|
end
|
503
613
|
|
@@ -507,6 +617,7 @@ module Osm
|
|
507
617
|
# @!macro options_api_data
|
508
618
|
# @return [Boolean] if the operation suceeded or not
|
509
619
|
def create_evening(section, meeting_date, api_data={})
|
620
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
510
621
|
section_id = id_for_section(section)
|
511
622
|
evening_api_data = {
|
512
623
|
'meetingdate' => meeting_date.strftime(Osm::OSM_DATE_FORMAT),
|
@@ -529,6 +640,7 @@ module Osm
|
|
529
640
|
# @!macro options_api_data
|
530
641
|
# @return [Boolean] if the operation suceeded or not
|
531
642
|
def update_evening(evening, api_data={})
|
643
|
+
warn "[DEPRECATION OF OPTION] use of the api_data option is deprecated." unless api_data == {}
|
532
644
|
raise ArgumentIsInvalid, 'evening is invalid' unless evening.valid?
|
533
645
|
response = perform_query("programme.php?action=editEvening", api_data.merge(evening.to_api))
|
534
646
|
|
@@ -577,17 +689,11 @@ module Osm
|
|
577
689
|
|
578
690
|
|
579
691
|
private
|
580
|
-
# Set the OSM user to make future requests as
|
581
|
-
# @param [String] userid the OSM userid to use (get this using the authorize method)
|
582
|
-
# @param [String] secret the OSM secret to use (get this using the authorize method)
|
583
|
-
def set_user(userid, secret)
|
584
|
-
@userid = userid
|
585
|
-
@secret = secret
|
586
|
-
end
|
587
|
-
|
588
692
|
# Make the query to the OSM API
|
589
693
|
# @param [String] url the script on the remote server to invoke
|
590
694
|
# @param [Hash] api_data a hash containing the values to be sent to the server
|
695
|
+
# @option api_data [String] 'userid' (optional) the OSM userid to make the request as
|
696
|
+
# @option api_data [String] 'secret' (optional) the OSM secret belonging to the above user
|
591
697
|
# @return [Hash, Array, String] the parsed JSON returned by OSM
|
592
698
|
def perform_query(url, api_data={})
|
593
699
|
api_data['apiid'] = @@api_id
|
@@ -602,7 +708,9 @@ module Osm
|
|
602
708
|
|
603
709
|
if @@debug
|
604
710
|
puts "Making OSM API request to #{url}"
|
605
|
-
|
711
|
+
hide_values_for = ['secret', 'token']
|
712
|
+
api_data_as_string = api_data.sort.map{ |key, value| "#{key} => #{hide_values_for.include?(key) ? 'PRESENT' : value.inspect}" }.join(', ')
|
713
|
+
puts "{#{api_data_as_string}}"
|
606
714
|
end
|
607
715
|
|
608
716
|
begin
|
@@ -676,6 +784,11 @@ module Osm
|
|
676
784
|
def id_for_section(section)
|
677
785
|
id_for(Osm::Section, section, 'section')
|
678
786
|
end
|
787
|
+
|
788
|
+
def type_for_section(section, api_data)
|
789
|
+
(section.is_a?(Osm::Section) ? section : get_section(section, api_data)).type.to_s
|
790
|
+
end
|
791
|
+
|
679
792
|
def id_for_term(term, section, api_data)
|
680
793
|
return term.nil? ? Osm::find_current_term_id(self, id_for_section(section), api_data) : id_for(Osm::Term, term, 'term')
|
681
794
|
end
|
data/lib/osm/event.rb
CHANGED
@@ -4,22 +4,23 @@ module Osm
|
|
4
4
|
include ::ActiveAttr::MassAssignmentSecurity
|
5
5
|
include ::ActiveAttr::Model
|
6
6
|
|
7
|
-
# @!attribute [
|
7
|
+
# @!attribute [rw] id
|
8
8
|
# @return [Fixnum] the id for the event
|
9
|
-
# @!attribute [
|
9
|
+
# @!attribute [rw] section_id
|
10
10
|
# @return [Fixnum] the id for the section
|
11
|
-
# @!attribute [
|
11
|
+
# @!attribute [rw] name
|
12
12
|
# @return [String] the name of the event
|
13
|
-
# @!attribute [
|
13
|
+
# @!attribute [rw] start
|
14
14
|
# @return [DateTime] when the event starts
|
15
|
-
# @!attribute [
|
15
|
+
# @!attribute [rw] finish
|
16
16
|
# @return [DateTime] when the event ends
|
17
|
-
# @!attribute [
|
17
|
+
# @!attribute [rw] cost
|
18
18
|
# @return [String] the cost of the event
|
19
|
-
# @!attribute [
|
19
|
+
# @!attribute [rw] location
|
20
20
|
# @return [String] where the event is
|
21
|
-
# @!attribute [
|
21
|
+
# @!attribute [rw] notes
|
22
22
|
# @return [String] notes about the event
|
23
|
+
# @!attribute [rw] archived
|
23
24
|
|
24
25
|
attribute :id, :type => Integer
|
25
26
|
attribute :section_id, :type => Integer
|
@@ -29,8 +30,9 @@ module Osm
|
|
29
30
|
attribute :cost, :type => String, :default => ''
|
30
31
|
attribute :location, :type => String, :default => ''
|
31
32
|
attribute :notes, :type => String, :default => ''
|
33
|
+
attribute :archived, :type => Boolean, :default => false
|
32
34
|
|
33
|
-
attr_accessible :id, :section_id, :name, :start, :finish, :cost, :location, :notes
|
35
|
+
attr_accessible :id, :section_id, :name, :start, :finish, :cost, :location, :notes, :archived
|
34
36
|
|
35
37
|
validates_numericality_of :id, :only_integer=>true, :greater_than=>0
|
36
38
|
validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
|
@@ -53,6 +55,7 @@ module Osm
|
|
53
55
|
:cost => data['cost'],
|
54
56
|
:location => data['location'],
|
55
57
|
:notes => data['notes'],
|
58
|
+
:archived => data['archived'].eql?('1')
|
56
59
|
})
|
57
60
|
end
|
58
61
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Osm
|
2
|
+
|
3
|
+
class FlexiRecordData
|
4
|
+
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
+
include ::ActiveAttr::Model
|
6
|
+
|
7
|
+
# @!attribute [rw] member_id
|
8
|
+
# @return [Fixnum] OSM id for the member
|
9
|
+
# @!attribute [rw] first_name
|
10
|
+
# @return [String] Member's first name
|
11
|
+
# @!attribute [rw] last_name
|
12
|
+
# @return [String] Member's last name
|
13
|
+
# @!attribute [rw] grouping__id
|
14
|
+
# @return [Fixnum] OSM id for the grouping the member is in
|
15
|
+
# @!attribute [rw] fields
|
16
|
+
# @return [Hash] Keys are the field'd id, values are the field values
|
17
|
+
# @!attribute [rw] total
|
18
|
+
# @return [Fixnum, nil] The total of the field values, nil if the flexi record does not have this column type
|
19
|
+
# @!attribute [rw] completed
|
20
|
+
# @return [Fixnum, nil] The count of completed fields, nil if the flexi record does not have this column type
|
21
|
+
# @!attribute [rw] date_of_birth
|
22
|
+
# @return [Date, nil] The member's date of birth, nil if the flexi record does not have this column type
|
23
|
+
# @!attribute [rw] age
|
24
|
+
# @return [String, nil] The member's age (yy/mm), nil if the flexi record does not have this column type
|
25
|
+
|
26
|
+
attribute :member_id, :type => Integer
|
27
|
+
attribute :first_name, :type => String
|
28
|
+
attribute :last_name, :type => String
|
29
|
+
attribute :grouping_id, :type => Integer
|
30
|
+
attribute :date_of_birth, :type => Date
|
31
|
+
attribute :total, :type => Integer
|
32
|
+
attribute :completed, :type => Integer
|
33
|
+
attribute :age, :type => String
|
34
|
+
attribute :fields, :default => {}
|
35
|
+
|
36
|
+
attr_accessible :member_id, :first_name, :last_name, :date_of_birth, :grouping_id, :total, :completed, :age, :fields
|
37
|
+
|
38
|
+
validates_presence_of :first_name
|
39
|
+
validates_presence_of :last_name
|
40
|
+
validates_numericality_of :grouping_id, :only_integer=>true, :greater_than_or_equal_to=>-2
|
41
|
+
validates_format_of :age, :with => /\A[0-9]{2}\/(0[0-9]|1[012])\Z/, :message => 'age is not in the correct format (yy/mm)', :allow_nil => true
|
42
|
+
validates :fields, :hash => {:key_type => String, :value_type => String}
|
43
|
+
|
44
|
+
|
45
|
+
# @!method initialize
|
46
|
+
# Initialize a new FlexiRecordData
|
47
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
48
|
+
|
49
|
+
|
50
|
+
# Initialize a new FlexiRecordData from api data
|
51
|
+
# @param [Hash] data the hash of data provided by the API
|
52
|
+
def self.from_api(data)
|
53
|
+
new({
|
54
|
+
:member_id => Osm::to_i_or_nil(data['scoutid']),
|
55
|
+
:first_name => data['firstname'],
|
56
|
+
:last_name => data['lastname'],
|
57
|
+
:grouping_id => Osm::to_i_or_nil(data['patrolid'].eql?('') ? nil : data['patrolid']),
|
58
|
+
:date_of_birth => data['dob'].nil? ? nil : Osm::parse_date(data['dob'], :ignore_epoch => true),
|
59
|
+
:total => Osm::to_i_or_nil(data['total'].eql?('') ? nil : data['total']),
|
60
|
+
:completed => Osm::to_i_or_nil(data['completed'].eql?('') ? nil : data['completed']),
|
61
|
+
:age => data['age'].eql?('') ? nil : data['age'],
|
62
|
+
:fields => data.select { |key, value| key.to_s.match(/^f_\d+/) }
|
63
|
+
})
|
64
|
+
end
|
65
|
+
|
66
|
+
end # Class FlexiRecordData
|
67
|
+
|
68
|
+
end # Module
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Osm
|
2
|
+
|
3
|
+
class FlexiRecordField
|
4
|
+
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
+
include ::ActiveAttr::Model
|
6
|
+
|
7
|
+
# @!attribute [rw] id
|
8
|
+
# @return [String] OSM identifier for the field. Special ones are 'dob', 'total', 'completed', 'age', 'firstname' and 'lastname', user ones are of the format 'f\_NUMBER'
|
9
|
+
# @!attribute [rw] name
|
10
|
+
# @return [String] Human readable name for the field
|
11
|
+
# @!attribute [rw] editable
|
12
|
+
# @return [Boolean] Wether the field can be edited
|
13
|
+
|
14
|
+
attribute :id, :type => String
|
15
|
+
attribute :name, :type => String
|
16
|
+
attribute :editable, :type => Boolean, :default => false
|
17
|
+
|
18
|
+
attr_accessible :id, :name, :editable
|
19
|
+
|
20
|
+
validates_presence_of :id
|
21
|
+
validates_presence_of :name
|
22
|
+
|
23
|
+
|
24
|
+
# @!method initialize
|
25
|
+
# Initialize a new FlexiRecordField
|
26
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
27
|
+
|
28
|
+
|
29
|
+
# Initialize a new FlexiRecordField from api data
|
30
|
+
# @param [Hash] data the hash of data provided by the API
|
31
|
+
def self.from_api(data)
|
32
|
+
new({
|
33
|
+
:id => data['field'],
|
34
|
+
:name => data['name'],
|
35
|
+
:editable => data['editable'],
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
end # Class FlexiRecordField
|
40
|
+
|
41
|
+
end # Module
|
data/lib/osm/register_data.rb
CHANGED
@@ -47,20 +47,16 @@ module Osm
|
|
47
47
|
# Initialize a new RegisterData from api data
|
48
48
|
# @param [Hash] data the hash of data provided by the API
|
49
49
|
def self.from_api(data)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
attributes[:attendance][Date.strptime(key, Osm::OSM_DATE_FORMAT)] = data[key]
|
61
|
-
end
|
62
|
-
|
63
|
-
new(attributes)
|
50
|
+
new(
|
51
|
+
:member_id => Osm::to_i_or_nil(data['scoutid']),
|
52
|
+
:grouping_id => Osm::to_i_or_nil(data['patrolid']),
|
53
|
+
:section_id => Osm::to_i_or_nil(data['sectionid']),
|
54
|
+
:first_name => data['firstname'],
|
55
|
+
:last_name => data['lastname'],
|
56
|
+
:total => data['total'].to_i,
|
57
|
+
:attendance => data.select { |key, value| key.to_s.match(Osm::OSM_DATE_REGEX) }.
|
58
|
+
inject({}){ |new_hash,(date, attendance)| new_hash[Date.strptime(date, Osm::OSM_DATE_FORMAT)] = attendance; new_hash },
|
59
|
+
)
|
64
60
|
end
|
65
61
|
|
66
62
|
end # Class RegisterData
|
data/lib/osm/role.rb
CHANGED
@@ -111,7 +111,7 @@ module Osm
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def inspect
|
114
|
-
attribute_descriptions = attributes.merge('section' => section.inspect_without_role(self))
|
114
|
+
attribute_descriptions = attributes.merge('section' => (section.nil? ? nil : section.inspect_without_role(self)))
|
115
115
|
return_inspect(attribute_descriptions)
|
116
116
|
end
|
117
117
|
|
data/lib/osm/section.rb
CHANGED
@@ -96,7 +96,10 @@ module Osm
|
|
96
96
|
}
|
97
97
|
|
98
98
|
# Populate arrays
|
99
|
-
|
99
|
+
fr = []
|
100
|
+
fr = data['extraRecords'] if data['extraRecords'].is_a?(Array)
|
101
|
+
fr = data['extraRecords'].values if data['extraRecords'].is_a?(Hash)
|
102
|
+
fr.each do |record_data|
|
100
103
|
attributes[:flexi_records].push FlexiRecord.from_api(record_data)
|
101
104
|
end
|
102
105
|
|
@@ -151,7 +154,7 @@ module Osm
|
|
151
154
|
end
|
152
155
|
|
153
156
|
def inspect
|
154
|
-
attribute_descriptions = attributes.merge('role' => role.inspect_without_section(self))
|
157
|
+
attribute_descriptions = attributes.merge('role' => (role.nil? ? nil : role.inspect_without_section(self)))
|
155
158
|
return_inspect(attribute_descriptions)
|
156
159
|
end
|
157
160
|
|
data/spec/osm/api_spec.rb
CHANGED
@@ -85,6 +85,18 @@ describe "API" do
|
|
85
85
|
Osm::Api.new.authorize(user_email, user_password).should == {'userid' => 'id', 'secret' => 'secret'}
|
86
86
|
end
|
87
87
|
|
88
|
+
it "sets a new API user" do
|
89
|
+
api = Osm::Api.new
|
90
|
+
api.set_user('1', '2')
|
91
|
+
|
92
|
+
HTTParty.should_receive(:post).with("https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", {:body => {
|
93
|
+
'apiid' => @api_config[:api_id],
|
94
|
+
'token' => @api_config[:api_token],
|
95
|
+
'userid' => '1',
|
96
|
+
'secret' => '2',
|
97
|
+
}}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'[]'}) }
|
98
|
+
api.get_roles
|
99
|
+
end
|
88
100
|
|
89
101
|
|
90
102
|
describe "Using the API:" do
|
@@ -325,14 +337,53 @@ describe "API" do
|
|
325
337
|
'location' => '',
|
326
338
|
'notes' => '',
|
327
339
|
'sectionid' => 1,
|
328
|
-
'googlecalendar' => nil
|
340
|
+
'googlecalendar' => nil,
|
341
|
+
'archived' => '0'
|
329
342
|
}]
|
330
343
|
}
|
331
|
-
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents§ionid=1", :body => body.to_json)
|
344
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents§ionid=1&showArchived=true", :body => body.to_json)
|
332
345
|
events = Osm::Api.new('1', '2').get_events(1)
|
333
346
|
events[0].id.should == 1
|
334
347
|
end
|
335
348
|
|
349
|
+
it "Fetch events for a section honoring archived option" do
|
350
|
+
body = {
|
351
|
+
'identifier' => 'eventid',
|
352
|
+
'label' => 'name',
|
353
|
+
'items' => [{
|
354
|
+
'eventid' => '1',
|
355
|
+
'name' => 'An Event',
|
356
|
+
'startdate' => '2001-02-03',
|
357
|
+
'enddate' => nil,
|
358
|
+
'starttime' => '00:00:00',
|
359
|
+
'endtime' => '00:00:00',
|
360
|
+
'cost' => '0.00',
|
361
|
+
'location' => '',
|
362
|
+
'notes' => '',
|
363
|
+
'sectionid' => 1,
|
364
|
+
'googlecalendar' => nil,
|
365
|
+
'archived' => '0'
|
366
|
+
},{
|
367
|
+
'eventid' => '2',
|
368
|
+
'name' => 'An Archived Event',
|
369
|
+
'startdate' => '2001-02-03',
|
370
|
+
'enddate' => nil,
|
371
|
+
'starttime' => '00:00:00',
|
372
|
+
'endtime' => '00:00:00',
|
373
|
+
'cost' => '0.00',
|
374
|
+
'location' => '',
|
375
|
+
'notes' => '',
|
376
|
+
'sectionid' => 1,
|
377
|
+
'googlecalendar' => nil,
|
378
|
+
'archived' => '1'
|
379
|
+
}]
|
380
|
+
}
|
381
|
+
|
382
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents§ionid=1&showArchived=true", :body => body.to_json)
|
383
|
+
Osm::Api.new('1', '2').get_events(1).size.should == 1
|
384
|
+
Osm::Api.new('1', '2').get_events(1, {:include_archived => true}).size.should == 2
|
385
|
+
end
|
386
|
+
|
336
387
|
|
337
388
|
it "Fetch due badges for a section" do
|
338
389
|
badges_body = []
|
@@ -374,6 +425,58 @@ describe "API" do
|
|
374
425
|
end
|
375
426
|
|
376
427
|
|
428
|
+
it "Fetch the flexi record fields for a section" do
|
429
|
+
data = {
|
430
|
+
"extraid" => "2",
|
431
|
+
"sectionid" => "1",
|
432
|
+
"name" => "A Flexi Record",
|
433
|
+
"config" => "[{\"id\":\"f_1\",\"name\":\"Field 1\",\"width\":\"150\"},{\"id\":\"f_2\",\"name\":\"Field 2\",\"width\":\"150\"}]",
|
434
|
+
"total" => "none",
|
435
|
+
"extrafields" => "[]",
|
436
|
+
"structure" => [
|
437
|
+
{
|
438
|
+
"rows" => [
|
439
|
+
{"name" => "First name","field" => "firstname","width" => "150px"},
|
440
|
+
{"name" => "Last name","field" => "lastname","width" => "150px"},
|
441
|
+
],
|
442
|
+
"noscroll" => true
|
443
|
+
},
|
444
|
+
{"rows" => [
|
445
|
+
{"name" => "Field 1","field" => "f_1","width" => "150px","editable" => true},
|
446
|
+
{"name" => "Filed 2","field" => "f_2","width" => "150px","editable" => true},
|
447
|
+
]}
|
448
|
+
]
|
449
|
+
}
|
450
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/extras.php?action=getExtra§ionid=1&extraid=2", :body => data.to_json)
|
451
|
+
|
452
|
+
fields = Osm::Api.new('1', '2').get_flexi_record_fields(1, 2)
|
453
|
+
fields.is_a?(Array).should be_true
|
454
|
+
end
|
455
|
+
|
456
|
+
it "Fetch the flexi record data for a section" do
|
457
|
+
data = {
|
458
|
+
'identifier' => 'scoutid',
|
459
|
+
'label' => "name",
|
460
|
+
'items' => [{
|
461
|
+
"scoutid" => "1",
|
462
|
+
"firstname" => "First",
|
463
|
+
"lastname" => "Last",
|
464
|
+
"dob" => "",
|
465
|
+
"patrolid" => "2",
|
466
|
+
"total" => "",
|
467
|
+
"completed" => "",
|
468
|
+
"f_1" => "A",
|
469
|
+
"f_2" => "B",
|
470
|
+
"age" => "",
|
471
|
+
"patrol" => "Green"
|
472
|
+
}]
|
473
|
+
}
|
474
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/extras.php?action=getExtraRecords§ionid=1&extraid=2&termid=3§ion=cubs", :body => data.to_json)
|
475
|
+
|
476
|
+
records = Osm::Api.new('1', '2').get_flexi_record_data(Osm::Section.new(:id => 1, :type => :cubs), 2, 3)
|
477
|
+
records.is_a?(Array).should be_true
|
478
|
+
end
|
479
|
+
|
377
480
|
|
378
481
|
it "Create an evening (succeded)" do
|
379
482
|
url = 'https://www.onlinescoutmanager.co.uk/programme.php?action=addActivityToProgramme'
|
@@ -479,9 +582,12 @@ describe "API" do
|
|
479
582
|
'userid' => 'user',
|
480
583
|
'secret' => 'secret',
|
481
584
|
}
|
585
|
+
api = Osm::Api.new('1', '2')
|
482
586
|
|
483
587
|
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"1":"Section 1"}'}) }
|
484
|
-
|
588
|
+
api.should_receive(:warn).with('[DEPRECATION OF OPTION] use of the api_data option is deprecated.')
|
589
|
+
|
590
|
+
api.get_notepads({}, {'userid'=>'user', 'secret'=>'secret'}).should == {1 => 'Section 1'}
|
485
591
|
end
|
486
592
|
end
|
487
593
|
|
@@ -40,7 +40,7 @@ describe "Online Scout Manager API Strangeness" do
|
|
40
40
|
|
41
41
|
it "handles a non existant array when no events" do
|
42
42
|
data = '{"identifier":"eventid","label":"name"}'
|
43
|
-
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents§ionid=1", :body => data)
|
43
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/events.php?action=getEvents§ionid=1&showArchived=true", :body => data)
|
44
44
|
|
45
45
|
@api.get_events(1).should == []
|
46
46
|
end
|
@@ -51,6 +51,33 @@ describe "Online Scout Manager API Strangeness" do
|
|
51
51
|
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/api.php?action=getUserRoles", :body => body)
|
52
52
|
|
53
53
|
@api.get_section(1).fields.should == {}
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
it "handles a section's flexi records being a hash" do
|
58
|
+
data = {
|
59
|
+
'subscription_level' => '3',
|
60
|
+
'subscription_expires' => (Date.today + 60).strftime('%Y-%m-%d'),
|
61
|
+
'sectionType' => 'cubs',
|
62
|
+
'numscouts' => 10,
|
63
|
+
'columnNames' => {},
|
64
|
+
'fields' => {},
|
65
|
+
'intouch' => {},
|
66
|
+
'mobFields' => {},
|
67
|
+
'extraRecords' => {
|
68
|
+
'1' => {
|
69
|
+
'name' => 'Name 1',
|
70
|
+
'extraid' => 1
|
71
|
+
},
|
72
|
+
'2' => {
|
73
|
+
'name' => 'Name 2',
|
74
|
+
'extraid' => 2
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
section = Osm::Section.from_api(1, 'Name', data, nil)
|
79
|
+
section.flexi_records.size.should == 2
|
54
80
|
|
55
81
|
end
|
82
|
+
|
56
83
|
end
|
data/spec/osm/event_spec.rb
CHANGED
@@ -15,7 +15,8 @@ describe "Event" do
|
|
15
15
|
'endtime' => '',
|
16
16
|
'cost' => 'Free',
|
17
17
|
'location' => 'Somewhere',
|
18
|
-
'notes' => 'None'
|
18
|
+
'notes' => 'None',
|
19
|
+
'archived' => '0'
|
19
20
|
}
|
20
21
|
event = Osm::Event.from_api(data)
|
21
22
|
|
@@ -27,6 +28,7 @@ describe "Event" do
|
|
27
28
|
event.cost.should == 'Free'
|
28
29
|
event.location.should == 'Somewhere'
|
29
30
|
event.notes.should == 'None'
|
31
|
+
event.archived.should be_false
|
30
32
|
event.valid?.should be_true
|
31
33
|
end
|
32
34
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
|
6
|
+
describe "Flexi Record Data" do
|
7
|
+
|
8
|
+
it "Create from API data" do
|
9
|
+
data = {
|
10
|
+
"scoutid" => "1",
|
11
|
+
"firstname" => "First",
|
12
|
+
"lastname" => "Last",
|
13
|
+
"dob" => "1899-11-30",
|
14
|
+
"patrolid" => "2",
|
15
|
+
"total" => "3",
|
16
|
+
"completed" => "",
|
17
|
+
"f_1" => "a",
|
18
|
+
"f_2" => "b",
|
19
|
+
"age" => "",
|
20
|
+
"patrol" => "Green"
|
21
|
+
}
|
22
|
+
|
23
|
+
rd = Osm::FlexiRecordData.from_api(data)
|
24
|
+
|
25
|
+
rd.member_id.should == 1
|
26
|
+
rd.grouping_id.should == 2
|
27
|
+
rd.first_name.should == 'First'
|
28
|
+
rd.last_name.should == 'Last'
|
29
|
+
rd.total.should == 3
|
30
|
+
rd.completed.nil?.should be_true
|
31
|
+
rd.age.nil?.should be_true
|
32
|
+
rd.date_of_birth.should == Date.new(1899, 11, 30)
|
33
|
+
rd.fields.should == {
|
34
|
+
'f_1' => 'a',
|
35
|
+
'f_2' => 'b',
|
36
|
+
}
|
37
|
+
rd.valid?.should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
|
5
|
+
describe "Flexi Record Field" do
|
6
|
+
|
7
|
+
it "Create from API data" do
|
8
|
+
data = {
|
9
|
+
"field" => "f_1",
|
10
|
+
"name" => "Field Name",
|
11
|
+
"width" => "150",
|
12
|
+
"editable" => true
|
13
|
+
}
|
14
|
+
|
15
|
+
field = Osm::FlexiRecordField.from_api(data)
|
16
|
+
|
17
|
+
field.id.should == 'f_1'
|
18
|
+
field.name.should == 'Field Name'
|
19
|
+
field.editable.should be_true
|
20
|
+
field.valid?.should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-24 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &80777240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *80777240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &80776920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *80776920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: active_attr
|
38
|
-
requirement: &
|
38
|
+
requirement: &80776570 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *80776570
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activemodel
|
49
|
-
requirement: &
|
49
|
+
requirement: &80776260 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *80776260
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &80775920 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *80775920
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &80775540 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *80775540
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: fakeweb
|
82
|
-
requirement: &
|
82
|
+
requirement: &80775080 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *80775080
|
91
91
|
description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
|
92
92
|
to retrieve and save data.
|
93
93
|
email:
|
@@ -113,6 +113,8 @@ files:
|
|
113
113
|
- lib/osm/due_badges.rb
|
114
114
|
- lib/osm/evening.rb
|
115
115
|
- lib/osm/event.rb
|
116
|
+
- lib/osm/flexi_record_data.rb
|
117
|
+
- lib/osm/flexi_record_field.rb
|
116
118
|
- lib/osm/grouping.rb
|
117
119
|
- lib/osm/member.rb
|
118
120
|
- lib/osm/register_data.rb
|
@@ -128,6 +130,8 @@ files:
|
|
128
130
|
- spec/osm/due_badges_spec.rb
|
129
131
|
- spec/osm/evening_spec.rb
|
130
132
|
- spec/osm/event_spec.rb
|
133
|
+
- spec/osm/flexi_record_data_spec.rb
|
134
|
+
- spec/osm/flexi_record_field_spec.rb
|
131
135
|
- spec/osm/grouping_spec.rb
|
132
136
|
- spec/osm/member_spec.rb
|
133
137
|
- spec/osm/osm_spec.rb
|