Module: DeltacloudVM::Client::Methods::Api
- Included in:
- Base, Connection
- Defined in:
- lib/deltacloud_vm/client/methods/api.rb
Instance Method Summary collapse
- #api_uri(uri) ⇒ Object
-
#current_driver ⇒ Object
(also: #api_driver, #driver_name)
The current driver the @connection is using.
-
#current_provider ⇒ Object
The current provider the @connection is using.
-
#feature?(collection_name, feature_name) ⇒ Boolean
Check if the current collection support given feature for given collection.
-
#features ⇒ Object
Hash
of all features supported by current connection. -
#must_support!(collection) ⇒ Object
Syntax sugar for Method modules, where you can ‘require’ the support for the given collection before you execute API call.
- #path ⇒ Object
-
#support?(collection) ⇒ Boolean
Syntax sugar for
supported_collections
Return ‘true’ if the collection is supported by current API entrypoint. -
#supported_collections ⇒ Object
(also: #entrypoints)
List of the currently supported collections by @connection.
-
#version ⇒ Object
(also: #api_version)
The current version of DeltacloudVM API.
Instance Method Details
#api_uri(uri) ⇒ Object
24 25 26 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 24 def api_uri(uri) URI.parse([path, uri.gsub(/^(\/+)/,'')].join('/')) end |
#current_driver ⇒ Object Also known as: api_driver, driver_name
The current driver the @connection is using
38 39 40 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 38 def current_driver entrypoint.to_xml.root['driver'] end |
#current_provider ⇒ Object
The current provider the @connection is using
47 48 49 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 47 def current_provider entrypoint.to_xml.root['provider'] end |
#feature?(collection_name, feature_name) ⇒ Boolean
Check if the current collection support given feature for given collection
90 91 92 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 90 def feature?(collection_name, feature_name) features[collection_name.to_s].include?(feature_name.to_s) end |
#features ⇒ Object
Hash
of all features supported by current connection
80 81 82 83 84 85 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 80 def features entrypoint.to_xml.root.xpath('link/feature').inject(Hash.new(Array.new)) do |result, feature| result[feature.parent['rel']] += [feature['name']] result end end |
#must_support!(collection) ⇒ Object
Syntax sugar for Method modules, where you can ‘require’ the support for the given collection before you execute API call
Raise NotSupported
exception if the given collection
is not supported
72 73 74 75 76 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 72 def must_support!(collection) unless support?(collection) raise error(:not_supported).new("Collection '#{collection}' not supported by current API endpoint.") end end |
#path ⇒ Object
20 21 22 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 20 def path connection.url_prefix.path end |
#support?(collection) ⇒ Boolean
Syntax sugar for supported_collections
Return ‘true’ if the collection is supported by current API entrypoint
62 63 64 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 62 def support?(collection) supported_collections.include? collection.to_s end |
#supported_collections ⇒ Object Also known as: entrypoints
List of the currently supported collections by @connection
53 54 55 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 53 def supported_collections entrypoint.to_xml.root.xpath('link').map { |l| l['rel'] } end |
#version ⇒ Object Also known as: api_version
The current version of DeltacloudVM API
30 31 32 |
# File 'lib/deltacloud_vm/client/methods/api.rb', line 30 def version entrypoint.to_xml.root['version'] end |