module Osm
@!macro [new] options_get
@param [Hash] options @option options [Boolean] :no_cache (optional) if true then the data will be retreived from OSM not the cache
Constants
- OSM_DATETIME_FORMAT
- OSM_DATETIME_FORMAT_HUMAN
- OSM_DATE_FORMAT
- OSM_DATE_FORMAT_HUMAN
- OSM_DATE_REGEX
- OSM_DATE_REGEX_UNANCHORED
- OSM_EPOCH
Set constants
- OSM_EPOCH_HUMAN
- OSM_TIME_FORMAT
- OSM_TIME_REGEX
- SUBSCRIPTION_LEVELS
- SUBSCRIPTION_LEVEL_NAMES
Public Class Methods
Configure the options used by classes in the module @param [Hash] options @option options [Hash] :api Default options for accessing the API @option options [Symbol] :default_site whether to use OSM (if :osm) or OGM (if :ogm) by default @option options [Hash] :osm (optional but :osm_api or :ogm_api must be present) the api data for OSM @option options[:osm] [String] :id the apiid given to you for using the OSM id @option options[:osm] [String] :token the token which goes with the above api @option options[:osm] [String] :name the name displayed in the External Access tab of OSM @option options [Hash] :ogm (optional but :osm_api or :ogm_api must be present) the api data for OGM @option options[:ogm] [String] :id the apiid given to you for using the OGM id @option options[:ogm] [String] :token the token which goes with the above api @option options[:ogm] [String] :name the name displayed in the External Access tab of OGM @option options [Boolean] :debug if true debugging info is output (optional, default = false) @option options [Hash] :cache_config (optional) How classes in the module will cache data. Whilst this is optional you should remember that caching is required to use the OSM API. @option options [Class] :cache An instance of a cache class, must provide the methods (exist?, delete, write, read), for details see Rails.cache. @option options [Fixnum] :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) @option options [String] :prepend_to_key (optional, default = 'OSMAPI') Text to prepend to the key used to store data in the cache @return nil
# File lib/osm.rb, line 85 def self.configure(options) Osm::Model.configure(options[:cache]) Osm::Api.configure(options[:api]) nil end
Private Class Methods
# File lib/osm.rb, line 169 def self.epoch_date?(date) [OSM_EPOCH, OSM_EPOCH_HUMAN].include?(date) end
# File lib/osm.rb, line 173 def self.inspect_instance(instance, options={}) replace_with = options[:replace_with] || {} values = instance.attributes.sort.map{ |(k,v)| (replace_with.keys.include?(k) && !v.nil?) ? "#{k}.#{replace_with[k]}: #{v.try(replace_with[k]).inspect}" : "#{k}: #{v.inspect}" } return "#<#{instance.class.name} #{values.join(', ')} >" end
# File lib/osm.rb, line 93 def self.make_datetime(date, time, options={}) date = nil if date.nil? || date.empty? || (!options[:ignore_epoch] && epoch_date?(date)) time = nil if time.nil? || time.empty? if (!date.nil? && !time.nil?) begin return DateTime.strptime((date + ' ' + time), OSM_DATETIME_FORMAT) rescue ArgumentError return nil end elsif !date.nil? begin return DateTime.strptime(date, (date.include?('-') ? OSM_DATE_FORMAT : OSM_DATE_FORMAT_HUMAN)) rescue ArgumentError return nil end else return nil end end
# File lib/osm.rb, line 151 def self.make_permissions_hash(permissions) return {} unless permissions.is_a?(Hash) permissions_map = { 10 => [:read], 20 => [:read, :write], 100 => [:read, :write, :administer], } return permissions.inject({}) do |new_hash, (key, value)| if ["badge", "member", "user", "register", "contact", "programme","events", "flexi", "finance", "quartermaster"].include?(key) # This is a permission we care about new_hash[key.to_sym] = permissions_map[value.to_i] end new_hash end end
# File lib/osm.rb, line 123 def self.parse_date(date, options={}) return nil if date.nil? || date.empty? || (!options[:ignore_epoch] && epoch_date?(date)) begin return Date.strptime(date, (date.include?('-') ? OSM_DATE_FORMAT : OSM_DATE_FORMAT_HUMAN)) rescue ArgumentError return nil end end
# File lib/osm.rb, line 113 def self.parse_datetime(date_time) return nil if date_time.nil? || date_time.empty? begin return DateTime.strptime(date_time, OSM_DATETIME_FORMAT) rescue ArgumentError return nil end end
# File lib/osm.rb, line 141 def self.symbolize_hash(hash_in) raise ArgumentError, 'You did not pass in a hash' unless hash_in.is_a?(Hash) hash_out = {} hash_in.each do |key, value| hash_out[key.to_sym] = value end hash_out end
# File lib/osm.rb, line 132 def self.to_i_or_nil(item) return nil if item.nil? begin return item.to_i rescue return nil end end