Class: JSS::Server

Inherits:
Object show all
Defined in:
lib/jss/server.rb,
lib/jss.rb

Overview

A class representing the currently-connected JSS Server in a JSS::APIConnection instance.

The APIConnection instance has a JSS::Server instance in its #server attribute. It is created fresh every time APIConnection#connect is called.

That’s the only time it should be instantiated, and all access should be through the #server attribute of the APIConnection instance.

Constant Summary collapse

ACTIVATION_CODE_RSRC =

Constants

'activationcode'.freeze
ACTIVATION_CODE_KEY =
:activation_code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jss_data, api) ⇒ Server

Initialize! THe jss_data to be passed in is the JSON output of the ‘jssuser’ resource on the API server. the jssuser resource is readable by anyone with a JSS acct regardless of their permissions. However, it’s marked as ‘deprecated’. Hopefully jamf will keep this basic level of info available for basic authentication and JSS version checking.

The ‘api’ is a reference to the JSS::APIConnection instance which this JSS::Server instance is a part of.



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/jss/server.rb', line 89

def initialize(jss_data, api)
  @api = api
  @license_type = jss_data[:license_type]
  @product = jss_data[:product]
  @raw_version = jss_data[:version]
  parsed = JSS.parse_jss_version(@raw_version)
  @major_version = parsed[:major]
  @minor_version = parsed[:minor]
  @revision_version = parsed[:revision]
  @version = parsed[:version]
end

Instance Attribute Details

#apiJSS::APIConnection (readonly)

Returns The APIConnection object that contains this instance of Server.

Returns:



72
73
74
# File 'lib/jss/server.rb', line 72

def api
  @api
end

#license_typeString (readonly)

Returns the type of server licence.

Returns:

  • (String)

    the type of server licence



50
51
52
# File 'lib/jss/server.rb', line 50

def license_type
  @license_type
end

#major_versionObject (readonly)

@return [Integer]



59
60
61
# File 'lib/jss/server.rb', line 59

def major_version
  @major_version
end

#minor_versionObject (readonly)

@return [Integer]



62
63
64
# File 'lib/jss/server.rb', line 62

def minor_version
  @minor_version
end

#productString (readonly) Also known as: product_name

Returns the license product name.

Returns:

  • (String)

    the license product name



53
54
55
# File 'lib/jss/server.rb', line 53

def product
  @product
end

#raw_versionObject (readonly)

@return [String]



68
69
70
# File 'lib/jss/server.rb', line 68

def raw_version
  @raw_version
end

#revision_versionObject (readonly)

@return [Integer]



65
66
67
# File 'lib/jss/server.rb', line 65

def revision_version
  @revision_version
end

#versionObject (readonly)

@return [String] The version of the JSS. See the method JSS.parse_jss_version



56
57
58
# File 'lib/jss/server.rb', line 56

def version
  @version
end

Instance Method Details

#activation_codeString

Returns the activation code for the server licence.

Returns:

  • (String)

    the activation code for the server licence



108
109
110
111
# File 'lib/jss/server.rb', line 108

def activation_code
  @act_code_data ||= @api.get_rsrc(ACTIVATION_CODE_RSRC)[ACTIVATION_CODE_KEY]
  @act_code_data[:code]
end

#organizationString Also known as: institution

Returns the organization to which the server is licensed.

Returns:

  • (String)

    the organization to which the server is licensed



102
103
104
105
# File 'lib/jss/server.rb', line 102

def organization
  @act_code_data ||= @api.get_rsrc(ACTIVATION_CODE_RSRC)[ACTIVATION_CODE_KEY]
  @act_code_data[:organization_name]
end

#pretty_print_instance_variablesArray

Remove the api object from the instance_variables used to create pretty-print (pp) output.

Returns:

  • (Array)

    the desired instance_variables



119
120
121
122
123
# File 'lib/jss/server.rb', line 119

def pretty_print_instance_variables
  vars = instance_variables.sort
  vars.delete :@api
  vars
end