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.



23
24
25
# File 'lib/jamf/api/connection/default_connection.rb', line 23

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.



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

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



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

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



70
71
72
# File 'lib/jamf/api/connection/default_connection.rb', line 70

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.



78
79
80
# File 'lib/jamf/api/connection/default_connection.rb', line 78

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