Class: NexusCli::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/nexus_cli/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, ssl_verify) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
11
# File 'lib/nexus_cli/connection.rb', line 7

def initialize(configuration, ssl_verify)
  @configuration = configuration
  @ssl_verify = ssl_verify
  @nexus = setup_nexus(configuration)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



4
5
6
# File 'lib/nexus_cli/connection.rb', line 4

def configuration
  @configuration
end

#nexusObject (readonly)

Returns the value of attribute nexus.



3
4
5
# File 'lib/nexus_cli/connection.rb', line 3

def nexus
  @nexus
end

#ssl_verifyObject (readonly)

Returns the value of attribute ssl_verify.



5
6
7
# File 'lib/nexus_cli/connection.rb', line 5

def ssl_verify
  @ssl_verify
end

Instance Method Details

#nexus_url(url) ⇒ String

Joins a given url to the current url stored in the configuraiton and returns the combined String.

Parameters:

  • url (String)

Returns:

  • (String)


19
20
21
# File 'lib/nexus_cli/connection.rb', line 19

def nexus_url(url)
  File.join(configuration['url'], url)
end

#running_nexus_pro?Boolean

Determines whether or not the Nexus server being connected to is running Nexus Pro.

Returns:

  • (Boolean)


61
62
63
# File 'lib/nexus_cli/connection.rb', line 61

def running_nexus_pro?
  status['edition_long'] == "Professional"
end

#sanitize_for_id(unsanitized_string) ⇒ String

Transforms a given [String] into a sanitized version by replacing spaces with underscores and downcasing.

Parameters:

  • unsanitized_string (String)

    the String to sanitize

Returns:

  • (String)

    the sanitized String



55
56
57
# File 'lib/nexus_cli/connection.rb', line 55

def sanitize_for_id(unsanitized_string)
  unsanitized_string.gsub(" ", "_").downcase
end

#statusHash

Gets that current status of the Nexus server. On a non-error status code, returns a Hash of values from the server.

Returns:

  • (Hash)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nexus_cli/connection.rb', line 27

def status
  response = nexus.get(nexus_url("service/local/status"))
  case response.status
  when 200
    doc = REXML::Document.new(response.content).elements["/status/data"]
    data = Hash.new
    data['app_name'] = doc.elements["appName"].text
    data['version'] = doc.elements["version"].text
    data['edition_long'] = doc.elements["editionLong"].text
    data['state'] = doc.elements["state"].text
    data['started_at'] = doc.elements["startedAt"].text
    data['base_url'] = doc.elements["baseUrl"].text
    return data
  when 401
    raise PermissionsException
  when 503
    raise CouldNotConnectToNexusException
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end