Class: Osm::Section
Constant Summary
Constants inherited from Model
Instance Attribute Summary collapse
-
#flexi_records ⇒ Array<FlexiRecord>
List of the extra records the section has.
-
#gocardless ⇒ Boolean
Does the section use gocardless.
-
#group_id ⇒ Fixnum
The id for the group.
-
#group_name ⇒ String
The group name.
-
#id ⇒ Fixnum
The id for the section.
-
#myscout_badges ⇒ Boolean
Whether the section uses the Badges part of My.SCOUT.
-
#myscout_badges_expires ⇒ Date
When the subscription to Badges in My.SCOUT expires.
-
#myscout_badges_partial ⇒ Boolean
Wether parents can see partially completed badges.
-
#myscout_details ⇒ Boolean
Whether the section uses the Personal Details part of My.SCOUT.
-
#myscout_details_email_changes_to ⇒ String
Email address to send changes to personal details made through My.SCOUT to.
-
#myscout_details_expires ⇒ Boolean
Whether the section uses the Personal Details part of My.SCOUT.
-
#myscout_email_address_copy ⇒ String
Which email address to send copys of My.SCOUT emails to.
-
#myscout_email_address_from ⇒ String
Which email address to send My.SCOUT emails as coming from.
-
#myscout_emails ⇒ Hash of Symbol to Boolean
Which email addresses are linked to MyScout for each Member.
-
#myscout_event_reminder_count ⇒ Fixnum
How many event reminders to send to parents who haven’t responded.
-
#myscout_event_reminder_frequency ⇒ Fixnum
How many days to leave between event reminder emails.
-
#myscout_events_expires ⇒ Date
When the subscription to Events in My.SCOUT expires.
-
#myscout_payment_reminder_count ⇒ Fixnum
How many payment reminders to send to parents who haven’t paid yet.
-
#myscout_payment_reminder_frequency ⇒ Fixnum
How many days to leave between payment reminder emails.
-
#myscout_payments ⇒ Boolean
Whether the section uses the Payments part of My.SCOUT.
-
#myscout_programme ⇒ Boolean
Whether the section uses the Programme part of My.SCOUT.
-
#myscout_programme_expires ⇒ Date
When the subscription to Badges in My.SCOUT expires.
-
#myscout_programme_show ⇒ Fixnum
How many programme itemms parents can see (the next 5, 10, 15, 20 meetings, -1 (whole term), 0 (remaining this term) or -2 (all future)).
-
#myscout_programme_summary ⇒ Boolean
Wether parents can see summary of programme items.
-
#myscout_programme_times ⇒ Boolean
Whether parents can see times of programme items.
-
#name ⇒ String
The section name.
-
#subscription_expires ⇒ Date
When the section’s subscription to OSM expires.
-
#subscription_level ⇒ Fixnum
What subscription the section has to OSM (1-bronze, 2-silver, 3-gold, 4-gold+).
-
#type ⇒ Symbol
The section type (:beavers, :cubs, :scouts, :exporers, :network, :adults, :waiting, :unknown).
Class Method Summary collapse
-
.get(api, section_id, options = {}) ⇒ Object
Get a section.
-
.get_all(api, options = {}) ⇒ Array<Osm::Section>
Get the user’s sections.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Compare Section based on group_name type (age order), then name.
-
#adults? ⇒ Boolean
Check if this is an Adults section.
-
#beavers? ⇒ Boolean
Check if this is a Beavers section.
-
#bronze? ⇒ Boolean
Check if this has a Bronze level subscription.
-
#cubs? ⇒ Boolean
Check if this is a Cubs section.
-
#explorers? ⇒ Boolean
Check if this is an Explorers section.
-
#get_notepad(api, options = {}) ⇒ String
Get the section’s notepad from OSM.
-
#gold? ⇒ Boolean
Check if this has a Gold level subscription.
-
#gold_plus? ⇒ Boolean
Check if this has a Gold+ level subscription.
-
#initialize ⇒ Object
constructor
Initialize a new Section.
-
#network? ⇒ Boolean
Check if this is a Network section.
-
#scouts? ⇒ Boolean
Check if this is a Scouts section.
-
#set_notepad(api, content) ⇒ Boolean
Set the section’s notepad in OSM.
-
#silver? ⇒ Boolean
Check if this has a Silver level subscription.
-
#subscription_at_least?(level) ⇒ Boolean
Check if the section has a subscription of a given level (or higher).
-
#subscription_level_name ⇒ String?
deprecated
Deprecated.
Please use Osm::SUBSCRIPTION_LEVEL_NAMES[section.subscription_level instead
-
#waiting? ⇒ Boolean
Check if this is a waiting list.
-
#youth_section? ⇒ Boolean
Check if this section is one of the youth sections.
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Section
|
# File 'lib/osm/section.rb', line 139
|
Instance Attribute Details
#flexi_records ⇒ Array<FlexiRecord>
Returns list of the extra records the section has.
|
# File 'lib/osm/section.rb', line 4
|
#gocardless ⇒ Boolean
Returns does the section use gocardless.
|
# File 'lib/osm/section.rb', line 4
|
#group_id ⇒ Fixnum
Returns the id for the group.
|
# File 'lib/osm/section.rb', line 4
|
#group_name ⇒ String
Returns the group name.
|
# File 'lib/osm/section.rb', line 4
|
#id ⇒ Fixnum
Returns the id for the section.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_badges ⇒ Boolean
Returns whether the section uses the Badges part of My.SCOUT.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_badges_expires ⇒ Date
Returns when the subscription to Badges in My.SCOUT expires.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_badges_partial ⇒ Boolean
Returns Wether parents can see partially completed badges.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_details ⇒ Boolean
Returns whether the section uses the Personal Details part of My.SCOUT.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_details_email_changes_to ⇒ String
Returns email address to send changes to personal details made through My.SCOUT to.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_details_expires ⇒ Boolean
Returns whether the section uses the Personal Details part of My.SCOUT.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_email_address_copy ⇒ String
Returns which email address to send copys of My.SCOUT emails to.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_email_address_from ⇒ String
Returns which email address to send My.SCOUT emails as coming from.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_emails ⇒ Hash of Symbol to Boolean
Returns which email addresses are linked to MyScout for each Member.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_event_reminder_count ⇒ Fixnum
Returns How many event reminders to send to parents who haven’t responded.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_event_reminder_frequency ⇒ Fixnum
Returns How many days to leave between event reminder emails.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_events_expires ⇒ Date
Returns when the subscription to Events in My.SCOUT expires.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_payment_reminder_count ⇒ Fixnum
Returns How many payment reminders to send to parents who haven’t paid yet.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_payment_reminder_frequency ⇒ Fixnum
Returns How many days to leave between payment reminder emails.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_payments ⇒ Boolean
Returns whether the section uses the Payments part of My.SCOUT.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_programme ⇒ Boolean
Returns whether the section uses the Programme part of My.SCOUT.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_programme_expires ⇒ Date
Returns when the subscription to Badges in My.SCOUT expires.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_programme_show ⇒ Fixnum
Returns How many programme itemms parents can see (the next 5, 10, 15, 20 meetings, -1 (whole term), 0 (remaining this term) or -2 (all future)).
|
# File 'lib/osm/section.rb', line 4
|
#myscout_programme_summary ⇒ Boolean
Returns Wether parents can see summary of programme items.
|
# File 'lib/osm/section.rb', line 4
|
#myscout_programme_times ⇒ Boolean
Returns Whether parents can see times of programme items.
|
# File 'lib/osm/section.rb', line 4
|
#name ⇒ String
Returns the section name.
|
# File 'lib/osm/section.rb', line 4
|
#subscription_expires ⇒ Date
Returns when the section’s subscription to OSM expires.
|
# File 'lib/osm/section.rb', line 4
|
#subscription_level ⇒ Fixnum
Returns what subscription the section has to OSM (1-bronze, 2-silver, 3-gold, 4-gold+).
|
# File 'lib/osm/section.rb', line 4
|
#type ⇒ Symbol
Returns the section type (:beavers, :cubs, :scouts, :exporers, :network, :adults, :waiting, :unknown).
|
# File 'lib/osm/section.rb', line 4
|
Class Method Details
.get(api, section_id, options = {}) ⇒ Object
Get a section
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/osm/section.rb', line 238 def self.get(api, section_id, ={}) cache_key = ['section', section_id] if ![:no_cache] && cache_exist?(api, cache_key) && can_access_section?(api, section_id) return cache_read(api, cache_key) end sections = get_all(api, ) return nil unless sections.is_a? Array sections.each do |section| return section if section.id == section_id end return nil end |
.get_all(api, options = {}) ⇒ Array<Osm::Section>
Get the user’s sections
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/osm/section.rb', line 148 def self.get_all(api, ={}) cache_key = ['sections', api.user_id] if ![:no_cache] && cache_exist?(api, cache_key) ids = cache_read(api, cache_key) return get_from_ids(api, ids, 'section', , :get_all) end result = Array.new ids = Array.new = Hash.new api.get_user_roles().each do |role_data| next if role_data['section'].eql?('discount') # It's not an actual section next if role_data['sectionConfig'].nil? # No config for the section = user hasn't got access section_data = role_data['sectionConfig'].is_a?(String) ? ActiveSupport::JSON.decode(role_data['sectionConfig']) : role_data['sectionConfig'] myscout_data = section_data['portal'] || {} section_data['portalExpires'] ||= {} section_id = Osm::to_i_or_nil(role_data['sectionid']) # Make sense of flexi records fr_data = [] flexi_records = [] fr_data = section_data['extraRecords'] if section_data['extraRecords'].is_a?(Array) fr_data = section_data['extraRecords'].values if section_data['extraRecords'].is_a?(Hash) fr_data.each do |record_data| # Expect item to be: {:name=>String, :extraid=>Fixnum} # Sometimes get item as: [String, {"name"=>String, "extraid"=>Fixnum}] record_data = record_data[1] if record_data.is_a?(Array) flexi_records.push Osm::FlexiRecord.new( :id => Osm::to_i_or_nil(record_data['extraid']), :name => record_data['name'], :section_id => section_id, ) end section = new( :id => section_id, :name => role_data['sectionname'], :subscription_level => Osm::to_i_or_nil(section_data['subscription_level']), :subscription_expires => Osm::parse_date(section_data['subscription_expires']), :type => !section_data['sectionType'].nil? ? section_data['sectionType'].to_sym : (!section_data['section'].nil? ? section_data['section'].to_sym : :unknown), :num_scouts => section_data['numscouts'], :flexi_records => flexi_records.sort, :group_id => role_data['groupid'], :group_name => role_data['groupname'], :gocardless => (section_data['gocardless'] || 'false').downcase.eql?('true'), :myscout_events_expires => Osm::parse_date(section_data['portalExpires']['events']), :myscout_badges_expires => Osm::parse_date(section_data['portalExpires']['badges']), :myscout_programme_expires => Osm::parse_date(section_data['portalExpires']['programme']), :myscout_details_expires => Osm::parse_date(section_data['portalExpires']['details']), :myscout_events => myscout_data['events'] == 1, :myscout_badges => myscout_data['badges'] == 1, :myscout_programme => myscout_data['programme'] == 1, :myscout_payments => myscout_data['payments'] == 1, :myscout_details => myscout_data['details'] == 1, :myscout_emails => (myscout_data['emails'] || {}).inject({}) { |n,(k,v)| n[k.to_sym] = v.eql?('true'); n}, :myscout_email_address_from => myscout_data['emailAddress'] ? myscout_data['emailAddress'] : '', :myscout_email_address_copy => myscout_data['emailAddressCopy'] ? myscout_data['emailAddressCopy'] : '', :myscout_badges_partial => myscout_data['badgesPartial'] == 1, :myscout_programme_summary => myscout_data['programmeSummary'] == 1, :myscout_programme_times => myscout_data['programmeTimes'] == 1, :myscout_programme_show => myscout_data['programmeShow'].to_i, :myscout_event_reminder_count => myscout_data['eventRemindCount'].to_i, :myscout_event_reminder_frequency => myscout_data['eventRemindFrequency'].to_i, :myscout_payment_reminder_count => myscout_data['paymentRemindCount'].to_i, :myscout_payment_reminder_frequency => myscout_data['paymentRemindFrequency'].to_i, :myscout_details_email_changes_to => myscout_data['contactNotificationEmail'], ) result.push section ids.push section.id cache_write(api, ['section', section.id], section) .merge!(section.id => Osm.(role_data['permissions'])) end .each do |s_id, perms| api.(s_id, perms) end cache_write(api, cache_key, ids) return result end |
Instance Method Details
#<=>(another) ⇒ Object
Compare Section based on group_name type (age order), then name
380 381 382 383 384 385 386 387 388 |
# File 'lib/osm/section.rb', line 380 def <=>(another) type_order = [:beavers, :cubs, :scouts, :explorers, :network, :adults, :waiting] result = self.group_name <=> another.try(:group_name) if result == 0 result = type_order.find_index(self.type) <=> type_order.find_index(another.try(:type)) end result = self.name <=> another.try(:name) if result == 0 return result end |
#adults? ⇒ Boolean
Check if this is an Adults section
324 325 326 327 328 |
# File 'lib/osm/section.rb', line 324 [:beavers, :cubs, :scouts, :explorers, :network, :adults, :waiting].each do |attribute| define_method "#{attribute}?" do type == attribute end end |
#beavers? ⇒ Boolean
Check if this is a Beavers section
324 325 326 327 328 |
# File 'lib/osm/section.rb', line 324 [:beavers, :cubs, :scouts, :explorers, :network, :adults, :waiting].each do |attribute| define_method "#{attribute}?" do type == attribute end end |
#bronze? ⇒ Boolean
Check if this has a Bronze level subscription
372 373 374 375 376 |
# File 'lib/osm/section.rb', line 372 Osm::SUBSCRIPTION_LEVELS[1..-1].each_with_index do |attribute, index| define_method "#{attribute}?" do subscription_level == (index + 1) end end |
#cubs? ⇒ Boolean
Check if this is a Cubs section
324 325 326 327 328 |
# File 'lib/osm/section.rb', line 324 [:beavers, :cubs, :scouts, :explorers, :network, :adults, :waiting].each do |attribute| define_method "#{attribute}?" do type == attribute end end |
#explorers? ⇒ Boolean
Check if this is an Explorers section
324 325 326 327 328 |
# File 'lib/osm/section.rb', line 324 [:beavers, :cubs, :scouts, :explorers, :network, :adults, :waiting].each do |attribute| define_method "#{attribute}?" do type == attribute end end |
#get_notepad(api, options = {}) ⇒ String
Get the section’s notepad from OSM
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/osm/section.rb', line 259 def get_notepad(api, ={}) require_access_to_section(api, self, ) cache_key = ['notepad', id] if ![:no_cache] && cache_exist?(api, cache_key) && can_access_section?(api, self.id) return cache_read(api, cache_key) end notepads = api.perform_query('api.php?action=getNotepads') return '' unless notepads.is_a?(Hash) notepad = '' notepads.each do |key, value| raw_value = value.fetch('raw', '') cache_write(api, ['notepad', key.to_i], raw_value) notepad = raw_value if key.to_i == id end return notepad end |
#gold? ⇒ Boolean
Check if this has a Gold level subscription
372 373 374 375 376 |
# File 'lib/osm/section.rb', line 372 Osm::SUBSCRIPTION_LEVELS[1..-1].each_with_index do |attribute, index| define_method "#{attribute}?" do subscription_level == (index + 1) end end |
#gold_plus? ⇒ Boolean
Check if this has a Gold+ level subscription
372 373 374 375 376 |
# File 'lib/osm/section.rb', line 372 Osm::SUBSCRIPTION_LEVELS[1..-1].each_with_index do |attribute, index| define_method "#{attribute}?" do subscription_level == (index + 1) end end |
#network? ⇒ Boolean
Check if this is a Network section
324 325 326 327 328 |
# File 'lib/osm/section.rb', line 324 [:beavers, :cubs, :scouts, :explorers, :network, :adults, :waiting].each do |attribute| define_method "#{attribute}?" do type == attribute end end |
#scouts? ⇒ Boolean
Check if this is a Scouts section
324 325 326 327 328 |
# File 'lib/osm/section.rb', line 324 [:beavers, :cubs, :scouts, :explorers, :network, :adults, :waiting].each do |attribute| define_method "#{attribute}?" do type == attribute end end |
#set_notepad(api, content) ⇒ Boolean
Set the section’s notepad in OSM
284 285 286 287 288 289 290 291 292 293 |
# File 'lib/osm/section.rb', line 284 def set_notepad(api, content) require_access_to_section(api, self) data = api.perform_query("users.php?action=updateNotepad§ionid=#{id}", {'raw' => content}) if data.is_a?(Hash) && data['ok'] # Success cache_write(api, ['notepad', id], content) return true end return false end |
#silver? ⇒ Boolean
Check if this has a Silver level subscription
372 373 374 375 376 |
# File 'lib/osm/section.rb', line 372 Osm::SUBSCRIPTION_LEVELS[1..-1].each_with_index do |attribute, index| define_method "#{attribute}?" do subscription_level == (index + 1) end end |
#subscription_at_least?(level) ⇒ Boolean
Check if the section has a subscription of a given level (or higher)
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/osm/section.rb', line 341 def subscription_at_least?(level) if level.is_a?(Symbol) # Convert to Fixnum case level when :bronze level = 1 when :silver level = 2 when :gold level = 3 when :gold_plus level = 4 else level = 0 end end return subscription_level >= level end |
#subscription_level_name ⇒ String?
Please use Osm::SUBSCRIPTION_LEVEL_NAMES[section.subscription_level instead
Get the name for the section’s subscription level
333 334 335 336 |
# File 'lib/osm/section.rb', line 333 def subscription_level_name warn "[DEPRECATION] `subscription_level_name` is deprecated. Please use `Osm::SUBSCRIPTION_LEVEL_NAMES[section.subscription_level` instead." Osm::SUBSCRIPTION_LEVEL_NAMES[subscription_level] end |
#waiting? ⇒ Boolean
Check if this is a waiting list
324 325 326 327 328 |
# File 'lib/osm/section.rb', line 324 [:beavers, :cubs, :scouts, :explorers, :network, :adults, :waiting].each do |attribute| define_method "#{attribute}?" do type == attribute end end |
#youth_section? ⇒ Boolean
Check if this section is one of the youth sections
298 299 300 |
# File 'lib/osm/section.rb', line 298 def youth_section? [:beavers, :cubs, :scouts, :explorers].include?(type) end |