Class: ManageIQ::API::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/manageiq/api/client/api.rb,
lib/manageiq/api/client/error.rb,
lib/manageiq/api/client/action.rb,
lib/manageiq/api/client/client.rb,
lib/manageiq/api/client/version.rb,
lib/manageiq/api/client/identity.rb,
lib/manageiq/api/client/resource.rb,
lib/manageiq/api/client/collection.rb,
lib/manageiq/api/client/connection.rb,
lib/manageiq/api/client/exceptions.rb,
lib/manageiq/api/client/api_version.rb,
lib/manageiq/api/client/null_logger.rb,
lib/manageiq/api/client/server_info.rb,
lib/manageiq/api/client/product_info.rb,
lib/manageiq/api/client/action_result.rb,
lib/manageiq/api/client/authentication.rb,
lib/manageiq/api/client/collection_options.rb

Defined Under Namespace

Classes: API, Action, ActionResult, ApiVersion, Authentication, Collection, CollectionOptions, Connection, Error, Exception, Identity, NullLogger, ProductInfo, Resource, ResourceNotFound, ServerInfo

Constant Summary collapse

DEFAULT_URL =
URI.parse("http://localhost:3000")
VERSION =
"0.5.0".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_options = {}) ⇒ Client

Returns a new instance of Client.



29
30
31
32
33
34
35
# File 'lib/manageiq/api/client/client.rb', line 29

def initialize(client_options = {})
  @client_options = client_options.dup
  @logger = client_options[:logger] || self.class.logger
  @url = extract_url(client_options)
  @authentication = ManageIQ::API::Client::Authentication.new(client_options)
  reconnect
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



11
12
13
# File 'lib/manageiq/api/client/client.rb', line 11

def api
  @api
end

#authenticationObject (readonly)

Returns the value of attribute authentication.



8
9
10
# File 'lib/manageiq/api/client/client.rb', line 8

def authentication
  @authentication
end

#authorizationObject (readonly)

Returns the value of attribute authorization.



14
15
16
# File 'lib/manageiq/api/client/client.rb', line 14

def authorization
  @authorization
end

#client_optionsObject (readonly)

Returns the value of attribute client_options.



5
6
7
# File 'lib/manageiq/api/client/client.rb', line 5

def client_options
  @client_options
end

#collectionsObject (readonly)

Returns the value of attribute collections.



17
18
19
# File 'lib/manageiq/api/client/client.rb', line 17

def collections
  @collections
end

#connectionObject (readonly)

Returns the value of attribute connection.



9
10
11
# File 'lib/manageiq/api/client/client.rb', line 9

def connection
  @connection
end

#identityObject (readonly)

Returns the value of attribute identity.



13
14
15
# File 'lib/manageiq/api/client/client.rb', line 13

def identity
  @identity
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/manageiq/api/client/client.rb', line 6

def logger
  @logger
end

#product_infoObject (readonly)

Returns the value of attribute product_info.



16
17
18
# File 'lib/manageiq/api/client/client.rb', line 16

def product_info
  @product_info
end

#server_infoObject (readonly)

Returns the value of attribute server_info.



15
16
17
# File 'lib/manageiq/api/client/client.rb', line 15

def server_info
  @server_info
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/manageiq/api/client/client.rb', line 7

def url
  @url
end

#user_settingsObject (readonly)

Returns the value of attribute user_settings.



12
13
14
# File 'lib/manageiq/api/client/client.rb', line 12

def 
  @user_settings
end

Class Method Details

.loggerObject



21
22
23
# File 'lib/manageiq/api/client/client.rb', line 21

def self.logger
  @logger ||= NullLogger.new
end

.logger=(logger) ⇒ Object



25
26
27
# File 'lib/manageiq/api/client/client.rb', line 25

def self.logger=(logger)
  @logger = logger
end

Instance Method Details

#load_definitionsObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/manageiq/api/client/client.rb', line 37

def load_definitions
  entrypoint     = connection.get("", :attributes => "authorization")
  @api           = ManageIQ::API::Client::API.new(entrypoint)
  @user_settings = Hash(entrypoint["settings"]).dup
  @identity      = ManageIQ::API::Client::Identity.new(Hash(entrypoint["identity"]))
  @authorization = Hash(entrypoint["authorization"]).dup
  @server_info   = ServerInfo.new(Hash(entrypoint["server_info"]))
  @product_info  = ProductInfo.new(Hash(entrypoint["product_info"]))
  @collections   = load_collections(entrypoint["collections"])
end

#reconnectObject



61
62
63
64
# File 'lib/manageiq/api/client/client.rb', line 61

def reconnect
  @connection = ManageIQ::API::Client::Connection.new(self, client_options.slice(:ssl, :open_timeout, :timeout))
  load_definitions
end

#update_authentication(auth_options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/manageiq/api/client/client.rb', line 48

def update_authentication(auth_options = {})
  return @authentication unless ManageIQ::API::Client::Authentication.auth_options_specified?(auth_options)
  saved_auth = @authentication
  @authentication = ManageIQ::API::Client::Authentication.new(auth_options)
  begin
    reconnect
  rescue
    @authentication = saved_auth
    raise
  end
  @authentication
end