Module: Jamf::Connection::DefaultConnection

Included in:
Jamf
Defined in:
lib/jamf/api/connection/default_connection.rb

Overview

Jamf module methods and aliases for dealing with the default connection This is extended into the Jamf module itself

Instance Method Summary collapse

Instance Method Details

#cnxJamf::Connection Also known as: api, api_connection, connection, default_connection

The current default Jamf::Connection instance.

Returns:



40
41
42
# File 'lib/jamf/api/connection/default_connection.rb', line 40

def cnx
  @default_connection ||= Jamf::Connection.new name: :default
end

#cnx=(connection) ⇒ APIConnection Also known as: use_connection, use_api_connection, use_api, activate_connection

Use the given Jamf::Connection object as the default connection, replacing the one that currently exists.

Parameters:

  • connection (Jamf::Connection)

    The default Connection to use for future API calls

Returns:



75
76
77
78
79
# File 'lib/jamf/api/connection/default_connection.rb', line 75

def cnx=(connection)
  raise 'API connections must be instances of Jamf::Connection' unless connection.is_a? Jamf::Connection

  @default_connection = connection
end

#connect(url = nil, **params) ⇒ String Also known as: login, new_api_connection, new_api, new_cnx, new_connection

Create a new Connection object and use it as the default for all future API calls. This will replace the existing default connection with a totally new one

Parameters:

Returns:

  • (String)

    the to_s output of the new connection



56
57
58
59
60
# File 'lib/jamf/api/connection/default_connection.rb', line 56

def connect(url = nil, **params)
  params[:name] ||= :default
  @default_connection = Jamf::Connection.new url, **params
  @default_connection.to_s
end

#disconnectObject

Disconnect the default connection



87
88
89
# File 'lib/jamf/api/connection/default_connection.rb', line 87

def disconnect
  @default_connection.disconnect if @default_connection&.connected?
end

#logoutObject

Log out the default connection This not only disconnects the connection, but tells the server to invalidate the token that was used, meaning that token cannot be used elsewhere before its expiration time.



95
96
97
# File 'lib/jamf/api/connection/default_connection.rb', line 95

def logout
  @default_connection.logout if @default_connection&.connected?
end