Module: Deltacloud::Client::Methods::Api

Included in:
Base, Connection
Defined in:
lib/deltacloud/client/methods/api.rb

Instance Method Summary collapse

Instance Method Details

#api_uri(uri) ⇒ Object



24
25
26
# File 'lib/deltacloud/client/methods/api.rb', line 24

def api_uri(uri)
  URI.parse([path, uri.gsub(/^(\/+)/,'')].join('/'))
end

#current_driverObject Also known as: api_driver, driver_name

The current driver the @connection is using



38
39
40
# File 'lib/deltacloud/client/methods/api.rb', line 38

def current_driver
  entrypoint.to_xml.root['driver']
end

#current_providerObject

The current provider the @connection is using



47
48
49
# File 'lib/deltacloud/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

Returns:

  • (Boolean)


90
91
92
# File 'lib/deltacloud/client/methods/api.rb', line 90

def feature?(collection_name, feature_name)
  features[collection_name.to_s].include?(feature_name.to_s)
end

#featuresObject

Hash of all features supported by current connection



80
81
82
83
84
85
# File 'lib/deltacloud/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/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

#pathObject



20
21
22
# File 'lib/deltacloud/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

Returns:

  • (Boolean)


62
63
64
# File 'lib/deltacloud/client/methods/api.rb', line 62

def support?(collection)
  supported_collections.include? collection.to_s
end

#supported_collectionsObject Also known as: entrypoints

List of the currently supported collections by @connection



53
54
55
# File 'lib/deltacloud/client/methods/api.rb', line 53

def supported_collections
  entrypoint.to_xml.root.xpath('link').map { |l| l['rel'] }
end

#versionObject Also known as: api_version

The current version of Deltacloud API



30
31
32
# File 'lib/deltacloud/client/methods/api.rb', line 30

def version
  entrypoint.to_xml.root['version']
end