Class: Osm::ApiAccess
- Inherits:
-
Object
- Object
- Osm::ApiAccess
- Defined in:
- lib/osm/api_access.rb
Instance Attribute Summary collapse
-
#id ⇒ Fixnum
readonly
The id for the API.
-
#name ⇒ String
readonly
The name of the API.
-
#permissions ⇒ Hash
readonly
The permissions assigned to this API by the user in OSM.
Instance Method Summary collapse
-
#can_read?(key) ⇒ Boolean
Determine if this API has read access for the provided permission.
-
#can_write?(key) ⇒ Boolean
Determine if this API has write access for the provided permission.
-
#initialize(data) ⇒ ApiAccess
constructor
Initialize a new API Access using the hash returned by the API call.
-
#our_api? ⇒ Boolean
Determine if this API is the API being used to make requests.
Constructor Details
#initialize(data) ⇒ ApiAccess
Initialize a new API Access using the hash returned by the API call
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/osm/api_access.rb', line 15 def initialize(data) @id = data['apiid'].to_i @name = data['name'] @permissions = data['permissions'].is_a?(Hash) ? data['permissions'] : {} # Rubyfy permissions hash @permissions.keys.each do |key| @permissions[key] = @permissions[key].to_i @permissions[(key.to_sym rescue key) || key] = @permissions.delete(key) # Symbolize key end end |
Instance Attribute Details
#id ⇒ Fixnum (readonly)
Returns the id for the API.
6 7 8 |
# File 'lib/osm/api_access.rb', line 6 def id @id end |
#name ⇒ String (readonly)
Returns the name of the API.
6 7 8 |
# File 'lib/osm/api_access.rb', line 6 def name @name end |
#permissions ⇒ Hash (readonly)
Returns the permissions assigned to this API by the user in OSM.
6 7 8 |
# File 'lib/osm/api_access.rb', line 6 def @permissions end |
Instance Method Details
#can_read?(key) ⇒ Boolean
Determine if this API has read access for the provided permission
30 31 32 |
# File 'lib/osm/api_access.rb', line 30 def can_read?(key) return [20, 10].include?(@permissions[key]) end |
#can_write?(key) ⇒ Boolean
Determine if this API has write access for the provided permission
37 38 39 |
# File 'lib/osm/api_access.rb', line 37 def can_write?(key) return [20].include?(@permissions[key]) end |