class Osm::ApiAccess
Public Class Methods
Get API Access for a given API @param [Osm::Api] api The api to use to make the request @param [Osm::Section, Fixnum, to_i
] section The section (or its ID) to get the details for @param [Osm::Api] for_api The api (or its ID) to get access for @!macro options_get @return [Osm::ApiAccess]
# File lib/osm/api_access.rb, line 90 def self.get(api, section, for_api, options={}) section_id = section.to_i for_api_id = for_api.to_i cache_key = ['api_access', api.user_id, section_id, for_api] if !options[:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end data = get_all(api, section_id, options) data.each do |item| return item if item.id == for_api_id end return nil end
Get API access details for a given section @param [Osm::Api] api The api to use to make the request @param [Osm::Section, Fixnum, to_i
] section The section (or its ID) to get the details for @!macro options_get @return [Array<Osm::ApiAccess>]
# File lib/osm/api_access.rb, line 31 def self.get_all(api, section, options={}) section_id = section.to_i cache_key = ['api_access', api.user_id, section_id] if !options[:no_cache] && cache_exist?(api, cache_key) ids = cache_read(api, cache_key) return get_from_ids(api, ids, cache_key, section, options, :get_all) end data = api.perform_query("ext/settings/access/?action=getAPIAccess§ionid=#{section_id}") permissions_map = { 10 => [:read], 20 => [:read, :write], 100 => [:read, :write, :administer] } result = Array.new ids = Array.new data['apis'].each do |item| attributes = {} attributes[:id] = item['apiid'].to_i attributes[:name] = item['name'] attributes[:permissions] = item['permissions'].is_a?(Hash) ? item['permissions'] : {} # Rubyify permissions hash attributes[:permissions].keys.each do |old_key| new_key = (old_key.to_sym rescue old_key) # Get symbol of the key attributes[:permissions][new_key] = attributes[:permissions].delete(old_key) # Change the key attributes[:permissions][new_key] = permissions_map[attributes[:permissions][new_key].to_i] || [] # Translate permissions value end attributes[:permissions].freeze this_item = new(attributes) result.push this_item ids.push this_item.id cache_write(api, [*cache_key, this_item.id], this_item) end cache_write(api, cache_key, ids) return result end
Get our API access details for a given section @param [Osm::Api] api The api to use to make the request @param [Osm::Section, Fixnum, to_i
] section The section (or its ID) to get the details for @!macro options_get @return [Osm::ApiAccess]
# File lib/osm/api_access.rb, line 79 def self.get_ours(api, section, options={}) get(api, section, api.api_id, options) end