Class: Osm::ApiAccess
Instance Attribute Summary collapse
-
#id ⇒ Fixnum
The id for the API.
-
#name ⇒ String
The name of the API.
-
#permissions ⇒ Hash
The permissions assigned to this API by the user in OSM.
Class Method Summary collapse
-
.get(api, section, for_api, options = {}) ⇒ Osm::ApiAccess
Get API Access for a given API.
-
.get_all(api, section, options = {}) ⇒ Array<Osm::ApiAccess>
Get API access details for a given section.
-
.get_ours(api, section, options = {}) ⇒ Osm::ApiAccess
Get our API access details for a given section.
Instance Method Summary collapse
-
#initialize ⇒ Object
constructor
Initialize a new Term.
Methods inherited from Model
#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Term
|
# File 'lib/osm/api_access.rb', line 108
|
Instance Attribute Details
#id ⇒ Fixnum
Returns the id for the API.
12 |
# File 'lib/osm/api_access.rb', line 12 attribute :id, :type => Integer |
#name ⇒ String
Returns the name of the API.
12 |
# File 'lib/osm/api_access.rb', line 12 attribute :id, :type => Integer |
#permissions ⇒ Hash
Returns the permissions assigned to this API by the user in OSM.
12 |
# File 'lib/osm/api_access.rb', line 12 attribute :id, :type => Integer |
Class Method Details
.get(api, section, for_api, options = {}) ⇒ Osm::ApiAccess
Get API Access for a given API
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/osm/api_access.rb', line 90 def self.get(api, section, for_api, ={}) section_id = section.to_i for_api_id = for_api.to_i cache_key = ['api_access', api.user_id, section_id, for_api] if ![:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end data = get_all(api, section_id, ) data.each do |item| return item if item.id == for_api_id end return nil end |
.get_all(api, section, options = {}) ⇒ Array<Osm::ApiAccess>
Get API access details for a given section
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/osm/api_access.rb', line 31 def self.get_all(api, section, ={}) section_id = section.to_i cache_key = ['api_access', api.user_id, section_id] if ![:no_cache] && cache_exist?(api, cache_key) ids = cache_read(api, cache_key) return get_from_ids(api, ids, cache_key, section, , :get_all) end data = api.perform_query("users.php?action=getAPIAccess§ionid=#{section_id}") = { 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] = [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_ours(api, section, options = {}) ⇒ Osm::ApiAccess
Get our API access details for a given section
79 80 81 |
# File 'lib/osm/api_access.rb', line 79 def self.get_ours(api, section, ={}) get(api, section, api.api_id, ) end |