Class: NexusCli::Connection
- Inherits:
-
Object
- Object
- NexusCli::Connection
- Defined in:
- lib/nexus_cli/connection.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#nexus ⇒ Object
readonly
Returns the value of attribute nexus.
-
#ssl_verify ⇒ Object
readonly
Returns the value of attribute ssl_verify.
Instance Method Summary collapse
-
#initialize(configuration, ssl_verify) ⇒ Connection
constructor
A new instance of Connection.
-
#nexus_url(url) ⇒ String
Joins a given url to the current url stored in the configuraiton and returns the combined String.
-
#running_nexus_pro? ⇒ Boolean
Determines whether or not the Nexus server being connected to is running Nexus Pro.
-
#sanitize_for_id(unsanitized_string) ⇒ String
Transforms a given [String] into a sanitized version by replacing spaces with underscores and downcasing.
-
#status ⇒ Hash
Gets that current status of the Nexus server.
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
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
4 5 6 |
# File 'lib/nexus_cli/connection.rb', line 4 def configuration @configuration end |
#nexus ⇒ Object (readonly)
Returns the value of attribute nexus.
3 4 5 |
# File 'lib/nexus_cli/connection.rb', line 3 def nexus @nexus end |
#ssl_verify ⇒ Object (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.
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.
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.
55 56 57 |
# File 'lib/nexus_cli/connection.rb', line 55 def sanitize_for_id(unsanitized_string) unsanitized_string.gsub(" ", "_").downcase end |
#status ⇒ Hash
Gets that current status of the Nexus server. On a non-error status code, returns a Hash of values from the server.
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 |