osm 0.0.5 → 0.0.6
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 +30 -0
- data/README.md +36 -2
- data/lib/osm/activity.rb +41 -0
- data/lib/osm/api.rb +145 -202
- data/lib/osm/api_access.rb +11 -5
- data/lib/osm/due_badges.rb +8 -0
- data/lib/osm/event.rb +16 -0
- data/lib/osm/grouping.rb +8 -0
- data/lib/osm/member.rb +65 -4
- data/lib/osm/programme_activity.rb +8 -0
- data/lib/osm/programme_item.rb +29 -0
- data/lib/osm/role.rb +19 -7
- data/lib/osm/section.rb +51 -0
- data/lib/osm/term.rb +19 -9
- data/spec/osm/api_spec.rb +1 -1
- data/version.rb +1 -1
- metadata +14 -14
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
## Version 0.0.6
|
2
|
+
|
3
|
+
* Usage changes:
|
4
|
+
* When calling an api.get\_\* method api_data is now passed as an additional paramter not as part of the options
|
5
|
+
* Work on documentation:
|
6
|
+
* Tidy up params
|
7
|
+
* Tidy up returns
|
8
|
+
* Add class attributes
|
9
|
+
* Update README file:
|
10
|
+
* Improve installation instructions
|
11
|
+
* Add use section
|
12
|
+
* Add versioning section
|
13
|
+
|
14
|
+
## Version 0.0.5
|
15
|
+
|
16
|
+
* Bug fix
|
17
|
+
|
18
|
+
## Version 0.0.4
|
19
|
+
|
20
|
+
* Bug fix
|
21
|
+
|
22
|
+
## Version 0.0.3
|
23
|
+
|
24
|
+
* Retrieve grouping points from OSM
|
25
|
+
* Respond to OSM chaninging how it returns member's groupings
|
26
|
+
|
27
|
+
## Version 0.0.2
|
28
|
+
|
29
|
+
* Bug fixes
|
30
|
+
|
1
31
|
## Version 0.0.1
|
2
32
|
|
3
33
|
* Initial release.
|
data/README.md
CHANGED
@@ -13,14 +13,48 @@ Staging [ API.
|
14
14
|
|
15
15
|
|
16
|
-
## Installation
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
**Requires Ruby 1.9.2 or later.**
|
17
19
|
|
18
20
|
Add to your Gemfile and run the `bundle` command to install it.
|
19
21
|
|
20
22
|
```ruby
|
21
23
|
gem 'osm'
|
22
24
|
```
|
23
|
-
**Requires Ruby 1.9.2 or later.**
|
24
25
|
|
26
|
+
Configure the gem during the initalization of the app (e.g. in config/initializers/osm.rb).
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
ActionDispatch::Callbacks.to_prepare do
|
30
|
+
Osm::Api.configure(
|
31
|
+
:api_id => 'YOU WILL BE GIVEN THIS BY ED AT OSM',
|
32
|
+
:api_token => 'YOU WILL BE GIVEN THIS BY ED AT OSM',
|
33
|
+
:api_name => 'YOU WILL GIVE THIS TO ED AT OSM',
|
34
|
+
:api_site => :scout,
|
35
|
+
)
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
## Use
|
41
|
+
|
42
|
+
In order to use the OSM API you first need to authorize the api to be used by the user, to do this use the {Osm::Api#authorize} method to get a userid and secret.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Osm::Api.new.authorize(users_email_address, users_osm_password)
|
46
|
+
```
|
47
|
+
|
48
|
+
Once you have done this you should store the userid and secret somewhere, you can then create an {Osm::Api} object to start acting as the user.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
api_for_this_user = Osm::Api.new(userid, secret)
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
## Documentation & Versioning
|
25
56
|
|
26
57
|
Documentation can be found on [rubydoc.info](http://rubydoc.info/github/robertgauld/osm/master/frames)
|
58
|
+
|
59
|
+
We follow the [Semantic Versioning](http://semver.org/) concept,
|
60
|
+
however it should be noted that when the OSM API adds a feature it can be difficult to decide wether to bump the patch or minor version number up. A smaller change (such as adding score into the grouping object) will bump the patch whereas a larger change wil bump the minor version.
|
data/lib/osm/activity.rb
CHANGED
@@ -3,6 +3,47 @@ module Osm
|
|
3
3
|
class Activity
|
4
4
|
|
5
5
|
attr_reader :id, :version, :group_id, :user_id, :title, :description, :resources, :instructions, :running_time, :location, :shared, :rating, :editable, :deletable, :used, :versions, :sections, :tags, :files, :badges
|
6
|
+
# @!attribute [r] id
|
7
|
+
# @return [FixNum] the id for the activity
|
8
|
+
# @!attribute [r] version
|
9
|
+
# @return [FixNum] the version of the activity
|
10
|
+
# @!attribute [r] group_id
|
11
|
+
# @return [FixNum] the group_id
|
12
|
+
# @!attribute [r] user_id
|
13
|
+
# @return [FixNum] the user_id of the creator of the activity
|
14
|
+
# @!attribute [r] title
|
15
|
+
# @return [String] the activity's title
|
16
|
+
# @!attribute [r] description
|
17
|
+
# @return [String] the description of the activity
|
18
|
+
# @!attribute [r] resources
|
19
|
+
# @return [String] resources required to do the activity
|
20
|
+
# @!attribute [r] instructions
|
21
|
+
# @return [String] instructions for doing the activity
|
22
|
+
# @!attribute [r] running_time
|
23
|
+
# @return [FixNum] duration of the activity in minutes
|
24
|
+
# @!attribute [r] location
|
25
|
+
# @return [Symbol] :indoors or :outdoors
|
26
|
+
# @!attribute [r] shared
|
27
|
+
# @return [FixNum] ?
|
28
|
+
# @!attribute [r] rating
|
29
|
+
# @return [FixNum] ?
|
30
|
+
# @!attribute [r] editable
|
31
|
+
# @return [Boolean] ?
|
32
|
+
# @!attribute [r] deletable
|
33
|
+
# @return [Boolean] ?
|
34
|
+
# @!attribute [r] used
|
35
|
+
# @return [FixNum] ?
|
36
|
+
# @!attribute [r] versions
|
37
|
+
# @return [Hash] ?
|
38
|
+
# @!attribute [r] sections
|
39
|
+
# @return [Array<Symbol>] the sections the activity is appropriate for
|
40
|
+
# @!attribute [r] tags
|
41
|
+
# @return [Array<String>] the tags attached to the activity
|
42
|
+
# @!attribute [r] files
|
43
|
+
# @return [Array] ?
|
44
|
+
# @!attribute [r] badges
|
45
|
+
# @return [Array] ?
|
46
|
+
|
6
47
|
|
7
48
|
# Initialize a new Activity using the hash returned by the API call
|
8
49
|
# @param data the hash of data for the object returned by the API
|
data/lib/osm/api.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# @!macro [new] options_get
|
2
|
+
# @param [Hash] options
|
3
|
+
# @option options [Boolean] :no_cache (optional) if true then the data will be retreived from OSM not the cache
|
4
|
+
|
5
|
+
# @!macro [new] options_api_data
|
6
|
+
# @param [Hash] api_data
|
7
|
+
# @option api_data [String] 'userid' (optional) the OSM userid to make the request as
|
8
|
+
# @option api_data [String] 'secret' (optional) the OSM secret belonging to the above user
|
9
|
+
|
10
|
+
|
1
11
|
module Osm
|
2
12
|
|
3
13
|
class Api
|
@@ -11,9 +21,10 @@ module Osm
|
|
11
21
|
|
12
22
|
# Initialize a new API connection
|
13
23
|
# If passing user details then both must be passed
|
14
|
-
# @param userid
|
15
|
-
# @param secret
|
16
|
-
# @param site
|
24
|
+
# @param [String] userid osm userid of the user to act as
|
25
|
+
# @param [String] secret osm secret of the user to act as
|
26
|
+
# @param [Symbol] site wether to use OSM (:scout) or OGM (:guide), defaults to the value set for the class
|
27
|
+
# @return nil
|
17
28
|
def initialize(userid=nil, secret=nil, site=@@api_site)
|
18
29
|
raise ArgumentError, 'You must pass a secret if you are passing a userid' if secret.nil? && !userid.nil?
|
19
30
|
raise ArgumentError, 'You must pass a userid if you are passing a secret' if userid.nil? && !secret.nil?
|
@@ -22,15 +33,17 @@ module Osm
|
|
22
33
|
@base_url = 'https://www.onlinescoutmanager.co.uk' if site == :scout
|
23
34
|
@base_url = 'http://www.onlineguidemanager.co.uk' if site == :guide
|
24
35
|
set_user(userid, secret)
|
36
|
+
nil
|
25
37
|
end
|
26
38
|
|
27
39
|
# Configure the API options used by all instances of the class
|
28
|
-
# @param options
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
40
|
+
# @param [Hash] options
|
41
|
+
# @option options [String] :api_id the apiid given to you for using the OSM id
|
42
|
+
# @option options [String] :api_token the token which goes with the above api
|
43
|
+
# @option options [String] :api_name the name displayed in the External Access tab of OSM
|
44
|
+
# @option options [Symbol] :api_sate wether to use OSM (if :scout) or OGM (if :guide)
|
45
|
+
# @option options [FixNum] :default_cache_ttl (optional, default = 30.minutes) The default TTL value for the cache, note that some items are cached for twice this time and others are cached for half this time (in seconds).
|
46
|
+
# @return nil
|
34
47
|
def self.configure(options)
|
35
48
|
raise ArgumentError, ':api_id does not exist in options hash' if options[:api_id].nil?
|
36
49
|
raise ArgumentError, ':api_token does not exist in options hash' if options[:api_token].nil?
|
@@ -38,30 +51,31 @@ module Osm
|
|
38
51
|
raise ArgumentError, ':api_site does not exist in options hash or is invalid, this should be set to either :scout or :guide' unless [:scout, :guide].include?(options[:api_site])
|
39
52
|
raise ArgumentError, ':default_cache_ttl must be greater than 0' unless (options[:default_cache_ttl].nil? || options[:default_cache_ttl].to_i > 0)
|
40
53
|
|
41
|
-
@@api_id = options[:api_id]
|
42
|
-
@@api_token = options[:api_token]
|
43
|
-
@@api_name = options[:api_name]
|
54
|
+
@@api_id = options[:api_id].to_s
|
55
|
+
@@api_token = options[:api_token].to_s
|
56
|
+
@@api_name = options[:api_name].to_s
|
44
57
|
@@api_site = options[:api_site]
|
45
58
|
@@default_cache_ttl = options[:default_cache_ttl].to_i unless options[:default_cache_ttl].nil?
|
59
|
+
nil
|
46
60
|
end
|
47
61
|
|
48
62
|
# Get the API ID used in this class
|
49
|
-
# @
|
63
|
+
# @return [String] the API ID
|
50
64
|
def self.api_id
|
51
65
|
return @@api_id
|
52
66
|
end
|
53
67
|
|
54
68
|
# Get the API name displayed in the External Access tab of OSM
|
55
|
-
# @
|
69
|
+
# @return [String] the API name
|
56
70
|
def self.api_name
|
57
71
|
return @@api_name
|
58
72
|
end
|
59
73
|
|
60
74
|
# Get the userid and secret to be able to act as a certain user on the OSM system
|
61
75
|
# Also set's the 'current user'
|
62
|
-
# @param email the login email address of the user on OSM
|
63
|
-
# @param password the login password of the user on OSM
|
64
|
-
# @
|
76
|
+
# @param [String] email the login email address of the user on OSM
|
77
|
+
# @param [String] password the login password of the user on OSM
|
78
|
+
# @return [Hash] a hash containing the following keys:
|
65
79
|
# * 'userid' - the userid to use in future requests
|
66
80
|
# * 'secret' - the secret to use in future requests
|
67
81
|
def authorize(email, password)
|
@@ -75,14 +89,10 @@ module Osm
|
|
75
89
|
end
|
76
90
|
|
77
91
|
# Get the user's roles
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
|
82
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
83
|
-
# @returns an array of Osm::Role objects
|
84
|
-
def get_roles(options={})
|
85
|
-
api_data = options[:api_data] || {}
|
92
|
+
# @!macro options_get
|
93
|
+
# @!macro options_api_data
|
94
|
+
# @return [Array<Osm::Role>]
|
95
|
+
def get_roles(options={}, api_data={})
|
86
96
|
|
87
97
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-roles-#{api_data[:userid] || @userid}")
|
88
98
|
return Rails.cache.read("OSMAPI-roles-#{api_data[:userid] || @userid}")
|
@@ -103,15 +113,10 @@ module Osm
|
|
103
113
|
end
|
104
114
|
|
105
115
|
# Get the user's notepads
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
|
110
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
111
|
-
# @returns a hash (keys are section IDs, values are a string)
|
112
|
-
def get_notepads(options={})
|
113
|
-
api_data = options[:api_data] || {}
|
114
|
-
|
116
|
+
# @!macro options_get
|
117
|
+
# @!macro options_api_data
|
118
|
+
# @return [Hash] a hash (keys are section IDs, values are a string)
|
119
|
+
def get_notepads(options={}, api_data={})
|
115
120
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-notepads-#{api_data[:userid] || @userid}")
|
116
121
|
return Rails.cache.read("OSMAPI-notepads-#{api_data[:userid] || @userid}")
|
117
122
|
end
|
@@ -130,22 +135,17 @@ module Osm
|
|
130
135
|
end
|
131
136
|
|
132
137
|
# Get the notepad for a specified section
|
133
|
-
# @param section_id the section id of the required section
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
|
139
|
-
# @returns nil if an error occured or the user does not have access to that section
|
140
|
-
# @returns a string otherwise
|
141
|
-
def get_notepad(section_id, options={})
|
142
|
-
api_data = options[:api_data] || {}
|
143
|
-
|
138
|
+
# @param [FixNum] section_id the section id of the required section
|
139
|
+
# @!macro options_get
|
140
|
+
# @!macro options_api_data
|
141
|
+
# @return nil if an error occured or the user does not have access to that section
|
142
|
+
# @return [String] the content of the notepad otherwise
|
143
|
+
def get_notepad(section_id, options={}, api_data={})
|
144
144
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-notepad-#{section_id}") && self.user_can_access?(:section, section_id, api_data)
|
145
145
|
return Rails.cache.read("OSMAPI-notepad-#{section_id}")
|
146
146
|
end
|
147
147
|
|
148
|
-
notepads = get_notepads(options)
|
148
|
+
notepads = get_notepads(options, api_data)
|
149
149
|
return nil unless notepads.is_a? Hash
|
150
150
|
|
151
151
|
notepads.each_key do |key|
|
@@ -156,22 +156,18 @@ module Osm
|
|
156
156
|
end
|
157
157
|
|
158
158
|
# Get the section (and its configuration)
|
159
|
-
# @param section_id the section id of the required section
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
|
165
|
-
# @returns nil if an error occured or the user does not have access to that section
|
166
|
-
# @returns an Osm::SectionConfig object otherwise
|
167
|
-
def get_section(section_id, options={})
|
168
|
-
api_data = options[:api_data] || {}
|
159
|
+
# @param [FixNum] section_id the section id of the required section
|
160
|
+
# @!macro options_get
|
161
|
+
# @!macro options_api_data
|
162
|
+
# @return nil if an error occured or the user does not have access to that section
|
163
|
+
# @return [Osm::Section]
|
164
|
+
def get_section(section_id, options={}, api_data={})
|
169
165
|
|
170
166
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-section-#{section_id}") && self.user_can_access?(:section, section_id, api_data)
|
171
167
|
return Rails.cache.read("OSMAPI-section-#{section_id}")
|
172
168
|
end
|
173
169
|
|
174
|
-
roles = get_roles(options)
|
170
|
+
roles = get_roles(options, api_data)
|
175
171
|
return nil unless roles.is_a? Array
|
176
172
|
|
177
173
|
roles.each do |role|
|
@@ -182,16 +178,11 @@ module Osm
|
|
182
178
|
end
|
183
179
|
|
184
180
|
# Get the groupings (e.g. patrols, sixes, lodges) for a given section
|
185
|
-
# @param section_id the section to get the programme for
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
|
190
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
191
|
-
# @returns an array of Osm::Patrol objects
|
192
|
-
def get_groupings(section_id, options={})
|
193
|
-
api_data = options[:api_data] || {}
|
194
|
-
|
181
|
+
# @param [FixNum] section_id the section to get the programme for
|
182
|
+
# @!macro options_get
|
183
|
+
# @!macro options_api_data
|
184
|
+
# @return [Array<Osm::Grouping>]
|
185
|
+
def get_groupings(section_id, options={}, api_data={})
|
195
186
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-groupings-#{section_id}") && self.user_can_access?(:section, section_id, api_data)
|
196
187
|
return Rails.cache.read("OSMAPI-groupings-#{section_id}")
|
197
188
|
end
|
@@ -211,15 +202,10 @@ module Osm
|
|
211
202
|
end
|
212
203
|
|
213
204
|
# Get the terms that the OSM user can access
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
|
218
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
219
|
-
# @returns an array of Osm::Term objects
|
220
|
-
def get_terms(options={})
|
221
|
-
api_data = options[:api_data] || {}
|
222
|
-
|
205
|
+
# @!macro options_get
|
206
|
+
# @!macro options_api_data
|
207
|
+
# @return [Array<Osm::Term>]
|
208
|
+
def get_terms(options={}, api_data={})
|
223
209
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-terms-#{api_data[:userid] || @userid}")
|
224
210
|
return Rails.cache.read("OSMAPI-terms-#{api_data[:userid] || @userid}")
|
225
211
|
end
|
@@ -241,17 +227,12 @@ module Osm
|
|
241
227
|
end
|
242
228
|
|
243
229
|
# Get a term
|
244
|
-
# @param term_id the id of the required term
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
|
250
|
-
# @returns nil if an error occured or the user does not have access to that term
|
251
|
-
# @returns an Osm::Term object otherwise
|
252
|
-
def get_term(term_id, options={})
|
253
|
-
api_data = options[:api_data] || {}
|
254
|
-
|
230
|
+
# @param [FixNum] term_id the id of the required term
|
231
|
+
# @!macro options_get
|
232
|
+
# @!macro options_api_data
|
233
|
+
# @return nil if an error occured or the user does not have access to that term
|
234
|
+
# @return [Osm::Term]
|
235
|
+
def get_term(term_id, options={}, api_data={})
|
255
236
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-term-#{term_id}") && self.user_can_access?(:term, term_id, api_data)
|
256
237
|
return Rails.cache.read("OSMAPI-term-#{term_id}")
|
257
238
|
end
|
@@ -267,17 +248,12 @@ module Osm
|
|
267
248
|
end
|
268
249
|
|
269
250
|
# Get the programme for a given term
|
270
|
-
# @param
|
271
|
-
# @param
|
272
|
-
#
|
273
|
-
#
|
274
|
-
#
|
275
|
-
|
276
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
277
|
-
# @returns an array of Osm::ProgrammeItem objects
|
278
|
-
def get_programme(section_id, term_id, options={})
|
279
|
-
api_data = options[:api_data] || {}
|
280
|
-
|
251
|
+
# @param [FixNum] section_id the section to get the programme for
|
252
|
+
# @param [FixNum] term_id the term to get the programme for
|
253
|
+
# @!macro options_get
|
254
|
+
# @!macro options_api_data
|
255
|
+
# @return [Array<Osm::ProgrammeItem>]
|
256
|
+
def get_programme(section_id, term_id, options={}, api_data={})
|
281
257
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-programme-#{section_id}-#{term_id}") && self.user_can_access?(:programme, section_id, api_data)
|
282
258
|
return Rails.cache.read("OSMAPI-programme-#{section_id}-#{term_id}")
|
283
259
|
end
|
@@ -303,17 +279,12 @@ module Osm
|
|
303
279
|
end
|
304
280
|
|
305
281
|
# Get activity details
|
306
|
-
# @param activity_id the activity ID
|
307
|
-
# @param version
|
308
|
-
#
|
309
|
-
#
|
310
|
-
#
|
311
|
-
|
312
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
313
|
-
# @returns an Osm::Activity object
|
314
|
-
def get_activity(activity_id, version=nil, options={})
|
315
|
-
api_data = options[:api_data] || {}
|
316
|
-
|
282
|
+
# @param [FixNum] activity_id the activity ID
|
283
|
+
# @param [FixNum] version the version of the activity to retreive, if nil the latest version will be assumed
|
284
|
+
# @!macro options_get
|
285
|
+
# @!macro options_api_data
|
286
|
+
# @return [Osm::Activity]
|
287
|
+
def get_activity(activity_id, version=nil, options={}, api_data={})
|
317
288
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-activity-#{activity_id}-#{version}") && self.user_can_access?(:activity, activity_id, api_data)
|
318
289
|
return Rails.cache.read("OSMAPI-activity-#{activity_id}-#{version}")
|
319
290
|
end
|
@@ -334,16 +305,12 @@ module Osm
|
|
334
305
|
end
|
335
306
|
|
336
307
|
# Get member details
|
337
|
-
# @section_id the section to get details for
|
338
|
-
# @term_id
|
339
|
-
#
|
340
|
-
#
|
341
|
-
#
|
342
|
-
|
343
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
344
|
-
# @returns an array of Osm::Member objects
|
345
|
-
def get_members(section_id, term_id=nil, options={})
|
346
|
-
api_data = options[:api_data] || {}
|
308
|
+
# @param [FixNum] section_id the section to get details for
|
309
|
+
# @param [FixNum] term_id the term to get details for, if nil the current term is assumed
|
310
|
+
# @!macro options_get
|
311
|
+
# @!macro options_api_data
|
312
|
+
# @return [Array<Osm::Member>]
|
313
|
+
def get_members(section_id, term_id=nil, options={}, api_data={})
|
347
314
|
term_id = Osm::find_current_term_id(self, section_id, api_data) if term_id.nil?
|
348
315
|
|
349
316
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-members-#{section_id}-#{term_id}") && self.user_can_access?(:member, section_id, api_data)
|
@@ -363,16 +330,11 @@ module Osm
|
|
363
330
|
end
|
364
331
|
|
365
332
|
# Get API access details for a given section
|
366
|
-
# @param section_id the section to get details for
|
367
|
-
#
|
368
|
-
#
|
369
|
-
#
|
370
|
-
|
371
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
372
|
-
# @returns an array of Osm::ApiAccess objects
|
373
|
-
def get_api_access(section_id, options={})
|
374
|
-
api_data = options[:api_data] || {}
|
375
|
-
|
333
|
+
# @param [FixNum] section_id the section to get details for
|
334
|
+
# @!macro options_get
|
335
|
+
# @!macro options_api_data
|
336
|
+
# @return [Array<Osm::ApiAccess>]
|
337
|
+
def get_api_access(section_id, options={}, api_data={})
|
376
338
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-api_access-#{api_data['userid'] || @userid}-#{section_id}")
|
377
339
|
return Rails.cache.read("OSMAPI-api_access-#{api_data['userid'] || @userid}-#{section_id}")
|
378
340
|
end
|
@@ -393,16 +355,11 @@ module Osm
|
|
393
355
|
end
|
394
356
|
|
395
357
|
# Get our API access details for a given section
|
396
|
-
# @param section_id the section to get details for
|
397
|
-
#
|
398
|
-
#
|
399
|
-
#
|
400
|
-
|
401
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
402
|
-
# @returns an Osm::ApiAccess objects
|
403
|
-
def get_our_api_access(section_id, options={})
|
404
|
-
api_data = options[:api_data] || {}
|
405
|
-
|
358
|
+
# @param [FixNum] section_id the section to get details for
|
359
|
+
# @!macro options_get
|
360
|
+
# @!macro options_api_data
|
361
|
+
# @return [Osm::ApiAccess]
|
362
|
+
def get_our_api_access(section_id, options={}, api_data={})
|
406
363
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-api_access-#{api_data['userid'] || @userid}-#{section_id}-#{Osm::Api.api_id}")
|
407
364
|
return Rails.cache.read("OSMAPI-api_access-#{api_data['userid'] || @userid}-#{section_id}-#{Osm::Api.api_id}")
|
408
365
|
end
|
@@ -417,16 +374,11 @@ module Osm
|
|
417
374
|
end
|
418
375
|
|
419
376
|
# Get events
|
420
|
-
# @section_id the section to get details for
|
421
|
-
#
|
422
|
-
#
|
423
|
-
#
|
424
|
-
|
425
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
426
|
-
# @returns an array of Osm::Event objects
|
427
|
-
def get_events(section_id, options={})
|
428
|
-
api_data = options[:api_data] || {}
|
429
|
-
|
377
|
+
# @param [FixNum] section_id the section to get details for
|
378
|
+
# @!macro options_get
|
379
|
+
# @!macro options_api_data
|
380
|
+
# @return [Array<Osm::Event>]
|
381
|
+
def get_events(section_id, options={}, api_data={})
|
430
382
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-events-#{section_id}") && self.user_can_access?(:programme, section_id, api_data)
|
431
383
|
return Rails.cache.read("OSMAPI-events-#{section_id}")
|
432
384
|
end
|
@@ -446,15 +398,11 @@ module Osm
|
|
446
398
|
end
|
447
399
|
|
448
400
|
# Get due badges
|
449
|
-
# @section_id the section to get details for
|
450
|
-
#
|
451
|
-
#
|
452
|
-
#
|
453
|
-
|
454
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
455
|
-
# @returns an Osm::DueBadges object
|
456
|
-
def get_due_badges(section_id, term_id=nil, options={})
|
457
|
-
api_data = options[:api_data] || {}
|
401
|
+
# @param [FixNum] section_id the section to get details for
|
402
|
+
# @!macro options_get
|
403
|
+
# @!macro options_api_data
|
404
|
+
# @return [Osm::DueBadges]
|
405
|
+
def get_due_badges(section_id, term_id=nil, options={}, api_data={})
|
458
406
|
term_id = Osm::find_current_term_id(self, section_id, api_data) if term_id.nil?
|
459
407
|
|
460
408
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-due_badges-#{section_id}-#{term_id}") && self.user_can_access?(:badge, section_id, api_data)
|
@@ -472,15 +420,11 @@ module Osm
|
|
472
420
|
end
|
473
421
|
|
474
422
|
# Get register structure
|
475
|
-
# @section_id the section to get details for
|
476
|
-
#
|
477
|
-
#
|
478
|
-
#
|
479
|
-
|
480
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
481
|
-
# @returns an array of hashes representing the rows of the register
|
482
|
-
def get_register_structure(section_id, term_id=nil, options={})
|
483
|
-
api_data = options[:api_data] || {}
|
423
|
+
# @param [FixNum] section_id the section to get details for
|
424
|
+
# @!macro options_get
|
425
|
+
# @!macro options_api_data
|
426
|
+
# @return [Array<Hash>] representing the rows of the register
|
427
|
+
def get_register_structure(section_id, term_id=nil, options={}, api_data={})
|
484
428
|
term_id = Osm::find_current_term_id(self, section_id, api_data) if term_id.nil?
|
485
429
|
|
486
430
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-register_structure-#{section_id}-#{term_id}") && self.user_can_access?(:register, section_id, api_data)
|
@@ -502,15 +446,11 @@ module Osm
|
|
502
446
|
end
|
503
447
|
|
504
448
|
# Get register
|
505
|
-
# @section_id the section to get details for
|
506
|
-
#
|
507
|
-
#
|
508
|
-
#
|
509
|
-
|
510
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
511
|
-
# @returns an array of hashes representing the attendance of each member
|
512
|
-
def get_register(section_id, term_id=nil, options={})
|
513
|
-
api_data = options[:api_data] || {}
|
449
|
+
# @param [FixNum] section_id the section to get details for
|
450
|
+
# @!macro options_get
|
451
|
+
# @!macro options_api_data
|
452
|
+
# @return [Array<Hash>] representing the attendance of each member
|
453
|
+
def get_register(section_id, term_id=nil, options={}, api_data={})
|
514
454
|
term_id = Osm::find_current_term_id(self, section_id, api_data) if term_id.nil?
|
515
455
|
|
516
456
|
if !options[:no_cache] && Rails.cache.exist?("OSMAPI-register-#{section_id}-#{term_id}") && self.user_can_access?(:register, section_id, api_data)
|
@@ -532,12 +472,10 @@ module Osm
|
|
532
472
|
end
|
533
473
|
|
534
474
|
# Create an evening in OSM
|
535
|
-
# @param section_id the id of the section to add the term to
|
536
|
-
# @param meeting_date the date of the meeting
|
537
|
-
#
|
538
|
-
#
|
539
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
540
|
-
# @returns a boolean representing if the operation suceeded or not
|
475
|
+
# @param [FixNum] section_id the id of the section to add the term to
|
476
|
+
# @param [Date] meeting_date the date of the meeting
|
477
|
+
# @!macro options_api_data
|
478
|
+
# @return [Boolean] if the operation suceeded or not
|
541
479
|
def create_evening(section_id, meeting_date, api_data={})
|
542
480
|
section_id = section_id.to_i
|
543
481
|
evening_api_data = {
|
@@ -557,11 +495,9 @@ module Osm
|
|
557
495
|
end
|
558
496
|
|
559
497
|
# Update an evening in OSM
|
560
|
-
# @param programme_item is the Osm::ProgrammeItem object to update
|
561
|
-
#
|
562
|
-
#
|
563
|
-
# * 'secret' (optional) the OSM secret belonging to the above user
|
564
|
-
# @returns a boolean representing if the operation suceeded or not
|
498
|
+
# @param [Osm::ProgrammeItem] programme_item is the Osm::ProgrammeItem object to update
|
499
|
+
# @!macro options_api_data
|
500
|
+
# @return [Boolean] if the operation suceeded or not
|
565
501
|
def update_evening(programme_item, api_data={})
|
566
502
|
response = perform_query("programme.php?action=editEvening", api_data.merge({
|
567
503
|
'eveningid' => programme_item.evening_id,
|
@@ -590,10 +526,11 @@ module Osm
|
|
590
526
|
|
591
527
|
protected
|
592
528
|
# Set access permission for the current user on a resource stored in the cache
|
593
|
-
# @param resource_type a symbol representing the resource type (:section, :grouping, :term, :activity, :programme, :member, :badge, :register)
|
594
|
-
# @param resource_id the id of the resource being checked
|
595
|
-
# @param api_data the data hash used in accessing the api
|
596
|
-
# @param permission
|
529
|
+
# @param [Symbol] resource_type a symbol representing the resource type (:section, :grouping, :term, :activity, :programme, :member, :badge, :register)
|
530
|
+
# @param [FixNum] resource_id the id of the resource being checked
|
531
|
+
# @param [Hash] api_data the data hash used in accessing the api
|
532
|
+
# @param [Boolean] permission wether the user can access the resource
|
533
|
+
# @return [Boolean] the permission which was set
|
597
534
|
def user_can_access(resource_type, resource_id, api_data, permission=true)
|
598
535
|
user = (api_data['userid'] || @userid).to_i
|
599
536
|
resource_id = resource_id.to_i
|
@@ -606,12 +543,11 @@ module Osm
|
|
606
543
|
end
|
607
544
|
|
608
545
|
# Get access permission for the current user on a resource stored in the cache
|
609
|
-
# @param resource_type a symbol representing the resource type (:section, :grouping, :term, :activity, :programme, :member, :badge, :register)
|
610
|
-
# @param resource_id the id of the resource being checked
|
611
|
-
# @param api_data the data hash used in accessing the api
|
612
|
-
# @
|
613
|
-
# @
|
614
|
-
# @returns nil if the combination of user and resource has not been seen
|
546
|
+
# @param [Symbol] resource_type a symbol representing the resource type (:section, :grouping, :term, :activity, :programme, :member, :badge, :register)
|
547
|
+
# @param [FixNum] resource_id the id of the resource being checked
|
548
|
+
# @param [Hash] api_data the data hash used in accessing the api
|
549
|
+
# @return nil if the combination of user and resource has not been set
|
550
|
+
# @return [Boolean] if the user can access the resource
|
615
551
|
def user_can_access?(resource_type, resource_id, api_data)
|
616
552
|
user = (api_data['userid'] || @userid).to_i
|
617
553
|
resource_id = resource_id.to_i
|
@@ -625,17 +561,17 @@ module Osm
|
|
625
561
|
|
626
562
|
private
|
627
563
|
# Set the OSM user to make future requests as
|
628
|
-
# @param userid the OSM userid to use (get this using the authorize method)
|
629
|
-
# @param secret the OSM secret to use (get this using the authorize method)
|
564
|
+
# @param [String] userid the OSM userid to use (get this using the authorize method)
|
565
|
+
# @param [String] secret the OSM secret to use (get this using the authorize method)
|
630
566
|
def set_user(userid, secret)
|
631
567
|
@userid = userid
|
632
568
|
@secret = secret
|
633
569
|
end
|
634
570
|
|
635
571
|
# Make the query to the OSM API
|
636
|
-
# @param url the script on the remote server to invoke
|
637
|
-
# @param api_data
|
638
|
-
# @
|
572
|
+
# @param [String] url the script on the remote server to invoke
|
573
|
+
# @param [Hash] api_data a hash containing the values to be sent to the server
|
574
|
+
# @return [Hash, Array, String] the parsed JSON returned by OSM
|
639
575
|
def perform_query(url, api_data={})
|
640
576
|
api_data['apiid'] = @@api_id
|
641
577
|
api_data['token'] = @@api_token
|
@@ -671,10 +607,17 @@ module Osm
|
|
671
607
|
return decoded
|
672
608
|
end
|
673
609
|
|
610
|
+
# Check if text looks like it's JSON
|
611
|
+
# @param [String] text what to look at
|
612
|
+
# @return [Boolean]
|
674
613
|
def looks_like_json?(text)
|
675
614
|
(['[', '{'].include?(text[0]))
|
676
615
|
end
|
677
616
|
|
617
|
+
# Get the error returned by OSM
|
618
|
+
# @param data what OSM gave us
|
619
|
+
# @return false if no error message was found
|
620
|
+
# @return [String] the error message
|
678
621
|
def get_osm_error(data)
|
679
622
|
return false unless data.is_a?(Hash)
|
680
623
|
to_return = data['error'] || data['err'] || false
|
data/lib/osm/api_access.rb
CHANGED
@@ -3,6 +3,12 @@ module Osm
|
|
3
3
|
class ApiAccess
|
4
4
|
|
5
5
|
attr_reader :id, :name, :permissions
|
6
|
+
# @!attribute [r] id
|
7
|
+
# @return [FixNum] the id for the API
|
8
|
+
# @!attribute [r] name
|
9
|
+
# @return [String] the name of the API
|
10
|
+
# @!attribute [r] permissions
|
11
|
+
# @return [Hash] the permissions assigned to this API by the user in OSM
|
6
12
|
|
7
13
|
# Initialize a new API Access using the hash returned by the API call
|
8
14
|
# @param data the hash of data for the object returned by the API
|
@@ -19,21 +25,21 @@ module Osm
|
|
19
25
|
end
|
20
26
|
|
21
27
|
# Determine if this API has read access for the provided permission
|
22
|
-
# @param
|
23
|
-
# @
|
28
|
+
# @param [Symbol] key the permission being queried
|
29
|
+
# @return [Boolean] if this API can read the passed permission
|
24
30
|
def can_read?(key)
|
25
31
|
return [20, 10].include?(@permissions[key])
|
26
32
|
end
|
27
33
|
|
28
34
|
# Determine if this API has write access for the provided permission
|
29
|
-
# @param
|
30
|
-
# @
|
35
|
+
# @param [Symbol] key the permission being queried
|
36
|
+
# @return [Boolean] if this API can write the passed permission
|
31
37
|
def can_write?(key)
|
32
38
|
return [20].include?(@permissions[key])
|
33
39
|
end
|
34
40
|
|
35
41
|
# Determine if this API is the API being used to make requests
|
36
|
-
# @
|
42
|
+
# @return [Boolean] if this is the API being used
|
37
43
|
def our_api?
|
38
44
|
return @id == Osm::Api.api_id.to_i
|
39
45
|
end
|
data/lib/osm/due_badges.rb
CHANGED
@@ -3,6 +3,12 @@ module Osm
|
|
3
3
|
class DueBadges
|
4
4
|
|
5
5
|
attr_reader :descriptions, :by_member, :totals
|
6
|
+
# @!attribute [r] descriptions
|
7
|
+
# @return [Hash] descriptions for each of the badges
|
8
|
+
# @!attribute [r] by_member
|
9
|
+
# @return [Hash] the due badges grouped by member
|
10
|
+
# @!attribute [r] totals
|
11
|
+
# @return [Hash] the total number of each nadge which is due
|
6
12
|
|
7
13
|
# Initialize a new Event using the hash returned by the API call
|
8
14
|
# @param data the hash of data for the object returned by the API
|
@@ -44,6 +50,8 @@ module Osm
|
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
53
|
+
# Check if there are no badges due
|
54
|
+
# @return [Boolean]
|
47
55
|
def empty?
|
48
56
|
return @by_member.empty?
|
49
57
|
end
|
data/lib/osm/event.rb
CHANGED
@@ -3,6 +3,22 @@ module Osm
|
|
3
3
|
class Event
|
4
4
|
|
5
5
|
attr_reader :id, :section_id, :name, :start, :end, :cost, :location, :notes
|
6
|
+
# @!attribute [r] id
|
7
|
+
# @return [FixNum] the id for the event
|
8
|
+
# @!attribute [r] section_id
|
9
|
+
# @return [FixNum] the id for the section
|
10
|
+
# @!attribute [r] name
|
11
|
+
# @return [String] the name of the event
|
12
|
+
# @!attribute [r] start
|
13
|
+
# @return [DateTime] when the event starts
|
14
|
+
# @!attribute [r] end
|
15
|
+
# @return [DateTime] when the event ends
|
16
|
+
# @!attribute [r] cost
|
17
|
+
# @return [?] the cost of the event
|
18
|
+
# @!attribute [r] location
|
19
|
+
# @return [String] where the event is
|
20
|
+
# @!attribute [r] notes
|
21
|
+
# @return [String] notes about the event
|
6
22
|
|
7
23
|
# Initialize a new Event using the hash returned by the API call
|
8
24
|
# @param data the hash of data for the object returned by the API
|
data/lib/osm/grouping.rb
CHANGED
@@ -3,6 +3,14 @@ module Osm
|
|
3
3
|
class Grouping
|
4
4
|
|
5
5
|
attr_reader :id, :name, :active, :points
|
6
|
+
# @!attribute [r] id
|
7
|
+
# @return [FixNum] the id for grouping
|
8
|
+
# @!attribute [r] name
|
9
|
+
# @return [String] the name of the grouping
|
10
|
+
# @!attribute [r] id
|
11
|
+
# @return [Boolean] wether the grouping is active
|
12
|
+
# @!attribute [r] points
|
13
|
+
# @return [FixNum] the points awarded to the grouping
|
6
14
|
|
7
15
|
# Initialize a new Grouping using the hash returned by the API call
|
8
16
|
# @param data the hash of data for the object returned by the API
|
data/lib/osm/member.rb
CHANGED
@@ -3,6 +3,67 @@ module Osm
|
|
3
3
|
class Member
|
4
4
|
|
5
5
|
attr_reader :id, :section_id, :type, :first_name, :last_name, :email1, :email2, :email3, :email4, :phone1, :phone2, :phone3, :phone4, :address, :address2, :date_of_birth, :started, :joined_in_years, :parents, :notes, :medical, :religion, :school, :ethnicity, :subs, :grouping_id, :grouping_leader, :joined, :age, :joined_years
|
6
|
+
# @!attribute [r] id
|
7
|
+
# @return [FixNum] the id for the member
|
8
|
+
# @!attribute [r] section_id
|
9
|
+
# @return [FixNum] the section the member belongs to
|
10
|
+
# @!attribute [r] type
|
11
|
+
# @return [?] ?
|
12
|
+
# @!attribute [r] first_name
|
13
|
+
# @return [String] the member's first name
|
14
|
+
# @!attribute [r] last_name
|
15
|
+
# @return [String] the imember's last name
|
16
|
+
# @!attribute [r] email1
|
17
|
+
# @return [String] the 1st email address for the member
|
18
|
+
# @!attribute [r] email2
|
19
|
+
# @return [String] the 2nd email address for the member
|
20
|
+
# @!attribute [r] email3
|
21
|
+
# @return [String] the 3rd email address for the member
|
22
|
+
# @!attribute [r] email4
|
23
|
+
# @return [String] the 4th email address for the member
|
24
|
+
# @!attribute [r] phone1
|
25
|
+
# @return [String] the 1st phone number for the member
|
26
|
+
# @!attribute [r] phone2
|
27
|
+
# @return [String] the 2nd phone number for the member
|
28
|
+
# @!attribute [r] phone3
|
29
|
+
# @return [String] the 3rd phone number for the member
|
30
|
+
# @!attribute [r] phone4
|
31
|
+
# @return [String] the 4th phone number for the member
|
32
|
+
# @!attribute [r] address
|
33
|
+
# @return [String] the member's address
|
34
|
+
# @!attribute [r] address2
|
35
|
+
# @return [String] the member's 2nd address
|
36
|
+
# @!attribute [r] date_of_birth
|
37
|
+
# @return [Date] the member's date of birth
|
38
|
+
# @!attribute [r] started
|
39
|
+
# @return [Date] when the member started Scouting
|
40
|
+
# @!attribute [r] joined_in_years
|
41
|
+
# @return [FixNum] thow many full years the member has been in Scouting
|
42
|
+
# @!attribute [r] parents
|
43
|
+
# @return [String] the member's parent's names
|
44
|
+
# @!attribute [r] notes
|
45
|
+
# @return [String] notes relating to the member
|
46
|
+
# @!attribute [r] medical
|
47
|
+
# @return [String] the member's key medical details
|
48
|
+
# @!attribute [r] religion
|
49
|
+
# @return [String] the member's religion
|
50
|
+
# @!attribute [r] school
|
51
|
+
# @return [String] the school the member attends
|
52
|
+
# @!attribute [r] ethnicity
|
53
|
+
# @return [String] the member's ethnicity
|
54
|
+
# @!attribute [r] subs
|
55
|
+
# @return [String] details about the member's subs
|
56
|
+
# @!attribute [r] grouping_id
|
57
|
+
# @return [FixNum] the grouping within the section that the member belongs to
|
58
|
+
# @!attribute [r] grouping_leader
|
59
|
+
# @return [FixNum] wether the member is the grouping leader (0=no, 1=seconder/APL, 2=sixer/PL)
|
60
|
+
# @!attribute [r] joined
|
61
|
+
# @return [Date] when the member joined the section
|
62
|
+
# @!attribute [r] age
|
63
|
+
# @return [String] the member's current age (yy/mm)
|
64
|
+
# @!attribute [r] joined_years
|
65
|
+
# @return [FixNum] ?
|
66
|
+
|
6
67
|
|
7
68
|
# Initialize a new Member using the hash returned by the API call
|
8
69
|
# @param data the hash of data for the object returned by the API
|
@@ -40,20 +101,20 @@ module Osm
|
|
40
101
|
end
|
41
102
|
|
42
103
|
# Get the years element of this scout's age
|
43
|
-
# @
|
104
|
+
# @return [FixNum] the number of years this scout has been alive
|
44
105
|
def age_years
|
45
106
|
return @age[0..1].to_i
|
46
107
|
end
|
47
108
|
|
48
109
|
# Get the months element of this scout's age
|
49
|
-
# @
|
110
|
+
# @return [FixNum] the number of months since this scout's last birthday
|
50
111
|
def age_months
|
51
112
|
return @age[-2..-1].to_i
|
52
113
|
end
|
53
114
|
|
54
115
|
# Get the full name
|
55
|
-
# @param seperator
|
56
|
-
# @
|
116
|
+
# @param [String] seperator what to split the scout's first name and last name with
|
117
|
+
# @return [String] this scout's full name seperated by the optional seperator
|
57
118
|
def name(seperator=' ')
|
58
119
|
return "#{@first_name}#{seperator.to_s}#{@last_name}"
|
59
120
|
end
|
@@ -3,6 +3,14 @@ module Osm
|
|
3
3
|
class ProgrammeActivity
|
4
4
|
|
5
5
|
attr_reader :evening_id, :activity_id, :title, :notes
|
6
|
+
# @!attribute [r] eveing_id
|
7
|
+
# @return [FixNum] the evening the activity is being done
|
8
|
+
# @!attribute [r] activity_id
|
9
|
+
# @return [FixNum] the activity being done
|
10
|
+
# @!attribute [r] title
|
11
|
+
# @return [String] the activity's title
|
12
|
+
# @!attribute [r] notes
|
13
|
+
# @return [String] tnotes relevant to doing this activity on this evening
|
6
14
|
|
7
15
|
# Initialize a new EveningActivity using the hash returned by the API call
|
8
16
|
# @param data the hash of data for the object returned by the API
|
data/lib/osm/programme_item.rb
CHANGED
@@ -4,6 +4,32 @@ module Osm
|
|
4
4
|
|
5
5
|
attr_accessor :evening_id, :section_id, :title, :notes_for_parents, :games, :pre_notes, :post_notes, :leaders, :meeting_date, :activities, :google_calendar
|
6
6
|
attr_reader :start_time, :end_time
|
7
|
+
# @!attribute [rw] evening_id
|
8
|
+
# @return [FixNum] the id of the evening
|
9
|
+
# @!attribute [rw] sectionid
|
10
|
+
# @return [FixNum] the section the evening belongs to
|
11
|
+
# @!attribute [rw] title
|
12
|
+
# @return [String] the title of the evening
|
13
|
+
# @!attribute [rw] notes_for_parents
|
14
|
+
# @return [String] notes to be shared with parents
|
15
|
+
# @!attribute [rw] games
|
16
|
+
# @return [String] games to be played during the evening
|
17
|
+
# @!attribute [rw] pre_notes
|
18
|
+
# @return [String] notes for the start of the evening
|
19
|
+
# @!attribute [rw] post_notes
|
20
|
+
# @return [String] notes for the end of the evening
|
21
|
+
# @!attribute [rw] leaders
|
22
|
+
# @return [String] the leaders present at the evening
|
23
|
+
# @!attribute [rw] meeting_date
|
24
|
+
# @return [Date] the date of the evening
|
25
|
+
# @!attribute [rw] activities
|
26
|
+
# @return [Array<ProgrammeActivity>] tlist of activities being done during the evening
|
27
|
+
# @!attribute [rw] google_calendar
|
28
|
+
# @return [String] ?
|
29
|
+
# @!attribute [rw] start_time
|
30
|
+
# @return [String] the start time (hh:mm)
|
31
|
+
# @!attribute [rw] end_time
|
32
|
+
# @return [String] the end time (hh:mm)
|
7
33
|
|
8
34
|
# Initialize a new ProgrammeItem using the hash returned by the API call
|
9
35
|
# @param data the hash of data for the object returned by the API
|
@@ -41,6 +67,9 @@ module Osm
|
|
41
67
|
end
|
42
68
|
end
|
43
69
|
|
70
|
+
|
71
|
+
# Get the JSON for the activitied to pass to the OSM API
|
72
|
+
# @return [String]
|
44
73
|
def activities_for_saving
|
45
74
|
to_save = Array.new
|
46
75
|
@activities.each do |activity|
|
data/lib/osm/role.rb
CHANGED
@@ -3,6 +3,18 @@ module Osm
|
|
3
3
|
class Role
|
4
4
|
|
5
5
|
attr_reader :section, :group_name, :group_id, :group_normalized, :default, :permissions
|
6
|
+
# @!attribute [r] section
|
7
|
+
# @return [Osm::Section] the section this role related to
|
8
|
+
# @!attribute [r] group_name
|
9
|
+
# @return [String] the name of the group the section is in
|
10
|
+
# @!attribute [r] group_id
|
11
|
+
# @return [FixNum] the group the section is in
|
12
|
+
# @!attribute [r] group_normalized
|
13
|
+
# @return [FixNum] ?
|
14
|
+
# @!attribute [r] default
|
15
|
+
# @return [Boolean] was this the last section this user used in OSM
|
16
|
+
# @!attribute [r] permissions
|
17
|
+
# @return [Hash] the permissions the user has in this role
|
6
18
|
|
7
19
|
# Initialize a new UserRole using the hash returned by the API call
|
8
20
|
# @param data the hash of data for the object returned by the API
|
@@ -21,27 +33,27 @@ module Osm
|
|
21
33
|
end
|
22
34
|
|
23
35
|
# Determine if this role has read access for the provided permission
|
24
|
-
# @param
|
25
|
-
# @
|
36
|
+
# @param [Symbol] key the permission being queried
|
37
|
+
# @return [Boolean] if this role can read the passed permission
|
26
38
|
def can_read?(key)
|
27
39
|
return [10, 20, 100].include?(@permissions[key])
|
28
40
|
end
|
29
41
|
|
30
42
|
# Determine if this role has write access for the provided permission
|
31
|
-
# @param
|
32
|
-
# @
|
43
|
+
# @param [Symbol] key the permission being queried
|
44
|
+
# @return [Boolean] if this role can write the passed permission
|
33
45
|
def can_write?(key)
|
34
46
|
return [20, 100].include?(@permissions[key])
|
35
47
|
end
|
36
48
|
|
37
|
-
# Get section's
|
38
|
-
# @
|
49
|
+
# Get section's long name in a consistent format
|
50
|
+
# @return [String] e.g. "Scouts (1st Somewhere)"
|
39
51
|
def long_name
|
40
52
|
@group_name.blank? ? @section.name : "#{@section.name} (#{@group_name})"
|
41
53
|
end
|
42
54
|
|
43
55
|
# Get section's full name in a consistent format
|
44
|
-
# @
|
56
|
+
# @return [String] e.g. "1st Somewhere Beavers"
|
45
57
|
def full_name
|
46
58
|
@group_name.blank? ? @section.name : "#{@group_name} #{@section.name}"
|
47
59
|
end
|
data/lib/osm/section.rb
CHANGED
@@ -3,6 +3,37 @@ module Osm
|
|
3
3
|
class Section
|
4
4
|
|
5
5
|
attr_reader :id, :name, :subscription_level, :subscription_expires, :type, :num_scouts, :has_badge_records, :has_programme, :wizard, :column_names, :fields, :intouch_fields, :mobile_fields, :extra_records, :role
|
6
|
+
# @!attribute [r] id
|
7
|
+
# @return [FixNum] the id for the section
|
8
|
+
# @!attribute [r] name
|
9
|
+
# @return [String] the section name
|
10
|
+
# @!attribute [r] subscription_level
|
11
|
+
# @return [Symbol] what subscription the section has to OSM (:bronze, :silver or :gold)
|
12
|
+
# @!attribute [r] subscription_expires
|
13
|
+
# @return [Date] when the section's subscription to OSM expires
|
14
|
+
# @!attribute [r] type
|
15
|
+
# @return [Symbol] the section type (:beavers, :cubs, :scouts, :exporers, :adults, :waiting, :unknown)
|
16
|
+
# @!attribute [r] num_scouts
|
17
|
+
# @return [FixNum] how many members the section has
|
18
|
+
# @!attribute [r] has_badge_records
|
19
|
+
# @return [Boolean] ?
|
20
|
+
# @!attribute [r] has_programme
|
21
|
+
# @return [Boolean] ?
|
22
|
+
# @!attribute [r] wizard
|
23
|
+
# @return [Boolean] ?
|
24
|
+
# @!attribute [r] column_names
|
25
|
+
# @return [Hash] custom names to use for the data columns
|
26
|
+
# @!attribute [r] fields
|
27
|
+
# @return [Hash] which columns are shown in OSM
|
28
|
+
# @!attribute [r] intouch_fields
|
29
|
+
# @return [Hash] which columns are shown in OSM's in touch reports
|
30
|
+
# @!attribute [r] mobile_fields
|
31
|
+
# @return [Hash] which columns are shown in the OSM mobile app
|
32
|
+
# @!attribute [r] extraRecords
|
33
|
+
# @return [Array<hash>] list of the extra records the section has
|
34
|
+
# @!attribute [r] role
|
35
|
+
# @return [Osm::Role] the role linking the user to this section
|
36
|
+
|
6
37
|
|
7
38
|
# Initialize a new SectionConfig using the hash returned by the API call
|
8
39
|
# @param id the section ID used by the API to refer to this section
|
@@ -39,11 +70,31 @@ module Osm
|
|
39
70
|
end
|
40
71
|
end
|
41
72
|
|
73
|
+
# Check if this section is one of the youth sections
|
74
|
+
# @return [Boolean]
|
42
75
|
def youth_section?
|
43
76
|
[:beavers, :cubs, :scouts, :explorers].include?(@type)
|
44
77
|
end
|
45
78
|
|
46
79
|
# Custom section type checkers
|
80
|
+
# @!method beavers?
|
81
|
+
# Check if this is a Beavers section
|
82
|
+
# @return (Boolean)
|
83
|
+
# @!method cubs?
|
84
|
+
# Check if this is a Cubs section
|
85
|
+
# @return (Boolean)
|
86
|
+
# @!method scouts?
|
87
|
+
# Check if this is a Scouts section
|
88
|
+
# @return (Boolean)
|
89
|
+
# @!method explorers?
|
90
|
+
# Check if this is an Explorers section
|
91
|
+
# @return (Boolean)
|
92
|
+
# @!method adults?
|
93
|
+
# Check if this is an Adults section
|
94
|
+
# @return (Boolean)
|
95
|
+
# @!method waiting?
|
96
|
+
# Check if this is a waiting list
|
97
|
+
# @return (Boolean)
|
47
98
|
[:beavers, :cubs, :scouts, :explorers, :adults, :waiting].each do |attribute|
|
48
99
|
define_method "#{attribute}?" do
|
49
100
|
@type == attribute
|
data/lib/osm/term.rb
CHANGED
@@ -3,6 +3,16 @@ module Osm
|
|
3
3
|
class Term
|
4
4
|
|
5
5
|
attr_reader :id, :section_id, :name, :start, :end
|
6
|
+
# @!attribute [r] id
|
7
|
+
# @return [FixNum] the id for the term
|
8
|
+
# @!attribute [r] section_id
|
9
|
+
# @return [FixNum] the section the term belongs to
|
10
|
+
# @!attribute [r] name
|
11
|
+
# @return [FixNum] the name of the term
|
12
|
+
# @!attribute [r] start
|
13
|
+
# @return [Date] when the term starts
|
14
|
+
# @!attribute [r] end
|
15
|
+
# @return [Date] when the term ends
|
6
16
|
|
7
17
|
# Initialize a new Term using the hash returned by the API call
|
8
18
|
# @param data the hash of data for the object returned by the API
|
@@ -15,40 +25,40 @@ module Osm
|
|
15
25
|
end
|
16
26
|
|
17
27
|
# Determine if the term is completly before the passed date
|
18
|
-
# @param date
|
19
|
-
# @
|
28
|
+
# @param [Date] date
|
29
|
+
# @return [Boolean] if the term is completly before the passed date
|
20
30
|
def before?(date)
|
21
31
|
return @end < date.to_date
|
22
32
|
end
|
23
33
|
|
24
34
|
# Determine if the term is completly after the passed date
|
25
|
-
# @param date
|
26
|
-
# @
|
35
|
+
# @param [Date] date
|
36
|
+
# @return [Boolean] if the term is completly after the passed date
|
27
37
|
def after?(date)
|
28
38
|
return @start > date.to_date
|
29
39
|
end
|
30
40
|
|
31
41
|
# Determine if the term is in the future
|
32
|
-
# @
|
42
|
+
# @return [Boolean] if the term starts after today
|
33
43
|
def future?
|
34
44
|
return @start > Date.today
|
35
45
|
end
|
36
46
|
|
37
47
|
# Determine if the term is in the past
|
38
|
-
# @
|
48
|
+
# @return [Boolean] if the term finished before today
|
39
49
|
def past?
|
40
50
|
return @end < Date.today
|
41
51
|
end
|
42
52
|
|
43
53
|
# Determine if the term is current
|
44
|
-
# @
|
54
|
+
# @return [Boolean] if the term started before today and finishes after today
|
45
55
|
def current?
|
46
56
|
return (@start <= Date.today) && (@end >= Date.today)
|
47
57
|
end
|
48
58
|
|
49
59
|
# Determine if the provided date is within the term
|
50
|
-
# @param date the date to test
|
51
|
-
# @
|
60
|
+
# @param [Date] date the date to test
|
61
|
+
# @return [Boolean] if the term started before the date and finishes after the date
|
52
62
|
def contains_date?(date)
|
53
63
|
return (@start <= date) && (@end >= date)
|
54
64
|
end
|
data/spec/osm/api_spec.rb
CHANGED
@@ -465,7 +465,7 @@ describe "API" do
|
|
465
465
|
}
|
466
466
|
|
467
467
|
HTTParty.should_receive(:post).with(url, {:body => post_data}) { DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"1":"Section 1"}'}) }
|
468
|
-
Osm::Api.new('1', '2').get_notepads(
|
468
|
+
Osm::Api.new('1', '2').get_notepads({}, {'userid'=>'user', 'secret'=>'secret'}).should == {1 => 'Section 1'}
|
469
469
|
end
|
470
470
|
end
|
471
471
|
|
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.6
|
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-
|
12
|
+
date: 2012-08-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &80730730 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *80730730
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &80713860 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.2'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *80713860
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: httparty
|
38
|
-
requirement: &
|
38
|
+
requirement: &80710730 !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: *80710730
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &80697000 !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: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *80697000
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &80694320 !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: *80694320
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: fakeweb
|
71
|
-
requirement: &
|
71
|
+
requirement: &80680900 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *80680900
|
80
80
|
description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
|
81
81
|
to retrieve and save data.
|
82
82
|
email:
|