Class: Fog::Rackspace::Identity::ServiceCatalog
- Defined in:
- lib/fog/rackspace/models/identity/service_catalog.rb
Instance Attribute Summary collapse
-
#catalog ⇒ Object
readonly
Returns the value of attribute catalog.
Attributes inherited from Model
Class Method Summary collapse
Instance Method Summary collapse
- #display_service_regions(service_type) ⇒ Object
- #get_endpoint(service_type, region = nil) ⇒ Object
- #get_endpoints(service_type) ⇒ Object
-
#initialize(attributes) ⇒ ServiceCatalog
constructor
A new instance of ServiceCatalog.
- #reload ⇒ Object
- #services ⇒ Object
Methods inherited from Model
#inspect, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes) ⇒ ServiceCatalog
Returns a new instance of ServiceCatalog.
9 10 11 12 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 9 def initialize(attributes) @service = attributes.delete(:service) @catalog = {} end |
Instance Attribute Details
#catalog ⇒ Object (readonly)
Returns the value of attribute catalog.
7 8 9 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 7 def catalog @catalog end |
Class Method Details
.from_response(service, hash) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 49 def self.from_response(service, hash) service_catalog = ServiceCatalog.new :service => service services = hash["access"]["serviceCatalog"] services.each do |serv| name = serv["name"].to_sym service_catalog.send(:add_endpoints, name, serv) end service_catalog end |
Instance Method Details
#display_service_regions(service_type) ⇒ Object
23 24 25 26 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 23 def display_service_regions(service_type) endpoints = get_endpoints(service_type) endpoints.collect { |k,v| ":#{k}" }.join(", ") end |
#get_endpoint(service_type, region = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 28 def get_endpoint(service_type, region=nil) endpoint = get_endpoints(service_type) raise "Unable to locate endpoint for service #{service_type}" unless endpoint return endpoint if endpoint.is_a?(String) #There is only one endpoint for service unless region raise "There are multiple endpoints avaliable for #{service_type}. Please specify one of the following regions: #{display_service_regions(service_type)}." end region = region.is_a?(String) ? region.to_sym : region endpoint = get_endpoints(service_type)[region] raise "Unknown region :#{region} for service #{service_type}. Please use one of the following regions: #{display_service_regions(service_type)}" unless endpoint endpoint end |
#get_endpoints(service_type) ⇒ Object
18 19 20 21 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 18 def get_endpoints(service_type) service_type = service_type.is_a?(String) ? service_type.to_sym : service_type catalog[service_type] end |
#reload ⇒ Object
43 44 45 46 47 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 43 def reload @service.authenticate @catalog = @service.service_catalog.catalog self end |
#services ⇒ Object
14 15 16 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 14 def services catalog.keys end |