osm 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## Version 0.1.5
2
+
3
+ * Bug fixes.
4
+
1
5
  ## Version 0.1.4
2
6
 
3
7
  * Osm::Model has new class method get\_user\_permission(api, section_id, permission)
@@ -171,7 +171,7 @@ module Osm
171
171
 
172
172
  # The cached programmes for the section will be out of date - remove them
173
173
  Osm::Term.get_for_section(api, section_id).each do |term|
174
- self.class.cache_delete(api, ['programme', section_id, term.id]) if term.contains_date?(meeting_date)
174
+ cache_delete(api, ['programme', section_id, term.id]) if term.contains_date?(meeting_date)
175
175
  end
176
176
 
177
177
  return response.is_a?(Hash) && (response['result'] == 0)
@@ -186,13 +186,13 @@ module Osm
186
186
  section = Osm::Section.get(api, section_id)
187
187
  cache_key = ['badge_requirements', section.id, id]
188
188
 
189
- if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && get_user_permission(api, section_id, :programme).include?(:read)
190
- return self.class.cache_read(api, cache_key)
189
+ if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, section_id, :programme).include?(:read)
190
+ return cache_read(api, cache_key)
191
191
  end
192
192
 
193
193
  data = api.perform_query("users.php?action=getActivityRequirements&date=#{meeting_date.strftime(Osm::OSM_DATE_FORMAT)}&sectionid=#{section.id}&section=#{section.type}")
194
194
 
195
- self.class.cache_write(api, cache_key, data)
195
+ cache_write(api, cache_key, data)
196
196
  return data
197
197
  end
198
198
 
@@ -159,7 +159,7 @@ module Osm
159
159
  # @param [Osm::Api] api The api to use to make the request
160
160
  # @return [Boolean] wether the update succedded
161
161
  def update(api)
162
- raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.get_user_permission(api, section_id, :events).include?(:write)
162
+ raise Forbidden, 'you do not have permission to write to events for this section' unless get_user_permission(api, section_id, :events).include?(:write)
163
163
 
164
164
  data = api.perform_query("events.php?action=addEvent&sectionid=#{section_id}", {
165
165
  'eventid' => id,
@@ -174,8 +174,8 @@ module Osm
174
174
  })
175
175
 
176
176
  # The cached events for the section will be out of date - remove them
177
- self.class.cache_delete(api, ['event', id])
178
- self.class.cache_delete(api, ['events', section_id])
177
+ cache_delete(api, ['event', id])
178
+ cache_delete(api, ['events', section_id])
179
179
 
180
180
  return data.is_a?(Hash) && (data['id'].to_i == id)
181
181
  end
@@ -184,13 +184,13 @@ module Osm
184
184
  # @param [Osm::Api] api The api to use to make the request
185
185
  # @return [Boolean] wether the delete succedded
186
186
  def delete(api)
187
- raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.get_user_permission(api, section_id, :events).include?(:write)
187
+ raise Forbidden, 'you do not have permission to write to events for this section' unless get_user_permission(api, section_id, :events).include?(:write)
188
188
 
189
189
  data = api.perform_query("events.php?action=deleteEvent&sectionid=#{section_id}&eventid=#{id}")
190
190
 
191
191
  # The cached events for the section will be out of date - remove them
192
- self.class.cache_delete(api, ['events', section_id])
193
- self.class.cache_delete(api, ['event', id])
192
+ cache_delete(api, ['events', section_id])
193
+ cache_delete(api, ['event', id])
194
194
 
195
195
  return data.is_a?(Hash) ? data['ok'] : false
196
196
  end
@@ -206,8 +206,8 @@ module Osm
206
206
  term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i
207
207
  cache_key = ['event_attendance', id]
208
208
 
209
- if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && self.class.get_user_permission(api, section_id, :events).include?(:read)
210
- return self.class.cache_read(api, cache_key)
209
+ if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, section_id, :events).include?(:read)
210
+ return cache_read(api, cache_key)
211
211
  end
212
212
 
213
213
  data = api.perform_query("events.php?action=getEventAttendance&eventid=#{id}&sectionid=#{section_id}&termid=#{term_id}")
@@ -231,7 +231,7 @@ module Osm
231
231
  )
232
232
  end
233
233
 
234
- self.class.cache_write(api, cache_key, attendance)
234
+ cache_write(api, cache_key, attendance)
235
235
  return attendance
236
236
  end
237
237
 
@@ -242,16 +242,16 @@ module Osm
242
242
  # @return [Boolean] wether the update succedded
243
243
  def add_field(api, label)
244
244
  raise ArgumentIsInvalid, 'label is invalid' if label.blank?
245
- raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.get_user_permission(api, section_id, :events).include?(:write)
245
+ raise Forbidden, 'you do not have permission to write to events for this section' unless get_user_permission(api, section_id, :events).include?(:write)
246
246
 
247
247
  data = api.perform_query("events.php?action=addColumn&sectionid=#{section_id}&eventid=#{id}", {
248
248
  'columnName' => label
249
249
  })
250
250
 
251
251
  # The cached events for the section will be out of date - remove them
252
- self.class.cache_delete(api, ['events', section_id])
253
- self.class.cache_delete(api, ['event', id])
254
- self.class.cache_delete(api, ['event_attendance', id])
252
+ cache_delete(api, ['events', section_id])
253
+ cache_delete(api, ['event', id])
254
+ cache_delete(api, ['event_attendance', id])
255
255
 
256
256
  return data.is_a?(Hash) && (data['eventid'].to_i == id)
257
257
  end
@@ -90,6 +90,7 @@ module Osm
90
90
  return (permissions || [])
91
91
  end
92
92
 
93
+
93
94
  # Set access permission for an API user
94
95
  # @param [Osm::Api] The api to use to make the request
95
96
  # @param [Fixnum, nil] section_id to set permissions for, if nil the Hash of all section's permissions is set
@@ -103,6 +104,17 @@ module Osm
103
104
  end
104
105
 
105
106
 
107
+ # Make selected class methods instance methods too
108
+ %w{
109
+ cache_read cache_write cache_exist? cache_delete
110
+ get_user_permissions get_user_permission set_user_permission
111
+ }.each do |method_name|
112
+ define_method method_name do |*options|
113
+ self.class.send(method_name, *options)
114
+ end
115
+ end
116
+
117
+
106
118
  end # Class Model
107
119
 
108
120
  end # Module
@@ -192,8 +192,8 @@ module Osm
192
192
  def get_notepad(api, options={})
193
193
  cache_key = ['notepad', id]
194
194
 
195
- if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && get_user_permissions(api).keys.include?(section_id)
196
- return self.class.cache_read(api, cache_key)
195
+ if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permissions(api).keys.include?(section_id)
196
+ return cache_read(api, cache_key)
197
197
  end
198
198
 
199
199
  notepads = api.perform_query('api.php?action=getNotepads')
@@ -201,7 +201,7 @@ module Osm
201
201
 
202
202
  notepad = ''
203
203
  notepads.each do |key, value|
204
- self.class.cache_write(api, ['notepad', key.to_i], value)
204
+ cache_write(api, ['notepad', key.to_i], value)
205
205
  notepad = value if key.to_i == id
206
206
  end
207
207
 
@@ -217,15 +217,15 @@ module Osm
217
217
  term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, self).id : term.to_i
218
218
  cache_key = ['badge_stock', id, term_id]
219
219
 
220
- if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && self.class.get_user_permission(api, self, :badge).include?(:read)
221
- return self.class.cache_read(api, cache_key)
220
+ if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, self, :badge).include?(:read)
221
+ return cache_read(api, cache_key)
222
222
  end
223
223
 
224
224
  data = api.perform_query("challenges.php?action=getInitialBadges&type=core&sectionid=#{id}&section=#{type}&termid=#{term_id}")
225
225
  data = (data['stock'] || {}).select{ |k,v| !k.eql?('sectionid') }.
226
226
  inject({}){ |new_hash,(badge, level)| new_hash[badge] = level.to_i; new_hash }
227
227
 
228
- self.class.cache_write(api, cache_key, data)
228
+ cache_write(api, cache_key, data)
229
229
  return data
230
230
  end
231
231
 
@@ -159,8 +159,8 @@ module Osm
159
159
  })
160
160
 
161
161
  # The cached terms for the section will be out of date - remove them
162
- self.class.cache_delete(api, ['term', id])
163
- self.class.cache_delete(api, ['terms', api.user_id])
162
+ cache_delete(api, ['term', id])
163
+ cache_delete(api, ['terms', api.user_id])
164
164
 
165
165
  return data.is_a?(Hash) && data['terms'].is_a?(Hash)
166
166
  end
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Osm
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
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.1.4
4
+ version: 0.1.5
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-10-29 00:00:00.000000000Z
12
+ date: 2012-10-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &78318930 !ruby/object:Gem::Requirement
16
+ requirement: &79214890 !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: *78318930
24
+ version_requirements: *79214890
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &78318540 !ruby/object:Gem::Requirement
27
+ requirement: &79214510 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.9'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *78318540
35
+ version_requirements: *79214510
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: active_attr
38
- requirement: &78318210 !ruby/object:Gem::Requirement
38
+ requirement: &79214170 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.6'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *78318210
46
+ version_requirements: *79214170
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activemodel
49
- requirement: &78317870 !ruby/object:Gem::Requirement
49
+ requirement: &79213800 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.2'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *78317870
57
+ version_requirements: *79213800
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &78317510 !ruby/object:Gem::Requirement
60
+ requirement: &79213530 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0.9'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *78317510
68
+ version_requirements: *79213530
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &78317150 !ruby/object:Gem::Requirement
71
+ requirement: &79213300 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '2.11'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *78317150
79
+ version_requirements: *79213300
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: fakeweb
82
- requirement: &78316920 !ruby/object:Gem::Requirement
82
+ requirement: &79213050 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '1.3'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *78316920
90
+ version_requirements: *79213050
91
91
  description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
92
92
  to retrieve and save data.
93
93
  email: