Class: NexusAPI::NexusConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/nexus_api/nexus_connection.rb

Constant Summary collapse

VALID_RESPONSE_CODES =
[200, 201, 204].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:, hostname:, protocol:) ⇒ NexusConnection

Returns a new instance of NexusConnection.



12
13
14
15
16
17
# File 'lib/nexus_api/nexus_connection.rb', line 12

def initialize(username:, password:, hostname:, protocol:)
  @username = username
  @password = password
  @hostname = hostname
  @protocol = protocol
end

Instance Attribute Details

#continuation_tokenObject

Returns the value of attribute continuation_token.



10
11
12
# File 'lib/nexus_api/nexus_connection.rb', line 10

def continuation_token
  @continuation_token
end

Instance Method Details

#content_length(asset_url:) ⇒ Object



66
67
68
69
70
# File 'lib/nexus_api/nexus_connection.rb', line 66

def content_length(asset_url:)
  response = head(asset_url: asset_url)
  return -1 unless response.respond_to?(:headers)
  response.headers[:content_length]
end

#delete(endpoint:, headers: {'Content-Type' => 'application/json'}, api_version: 'v1') ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/nexus_api/nexus_connection.rb', line 50

def delete(endpoint:, headers: {'Content-Type' => 'application/json'}, api_version: 'v1')
  response = send_request(
    :delete,
    endpoint,
    headers: headers,
    api_version: api_version
  )
  valid?(response)
end

#download(url:) ⇒ Object



72
73
74
75
76
# File 'lib/nexus_api/nexus_connection.rb', line 72

def download(url:)
  catch_connection_error do
    RestClient.get(URI.escape(url), authorization_header)
  end
end

#get(endpoint:, paginate: false, headers: {'Content-Type' => 'application/json'}, api_version: 'v1') ⇒ Object



24
25
26
# File 'lib/nexus_api/nexus_connection.rb', line 24

def get(endpoint:, paginate: false, headers: {'Content-Type' => 'application/json'}, api_version: 'v1')
  valid?(send_get(endpoint, paginate, headers, api_version))
end

#get_response(endpoint:, paginate: false, headers: {'Content-Type' => 'application/json'}, api_version: 'v1') ⇒ Object



19
20
21
22
# File 'lib/nexus_api/nexus_connection.rb', line 19

def get_response(endpoint:, paginate: false, headers: {'Content-Type' => 'application/json'}, api_version: 'v1')
  response = send_get(endpoint, paginate, headers, api_version)
  response.nil? ? Hash.new : jsonize(response)
end

#head(asset_url:) ⇒ Object



60
61
62
63
64
# File 'lib/nexus_api/nexus_connection.rb', line 60

def head(asset_url:)
  catch_connection_error do
    RestClient.head(URI.escape(asset_url))
  end
end

#paginate?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/nexus_api/nexus_connection.rb', line 78

def paginate?
  !@continuation_token.nil?
end

#post(endpoint:, parameters: '', headers: {'Content-Type' => 'application/json'}, api_version: 'v1') ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/nexus_api/nexus_connection.rb', line 28

def post(endpoint:, parameters: '', headers: {'Content-Type' => 'application/json'}, api_version: 'v1')
  response = send_request(
    :post, 
    endpoint,
    parameters: parameters,
    headers: headers,
    api_version: api_version
  )
  valid?(response)
end

#put(endpoint:, parameters: '', headers: {'Content-Type' => 'application/json'}, api_version: 'v1') ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/nexus_api/nexus_connection.rb', line 39

def put(endpoint:, parameters: '', headers: {'Content-Type' => 'application/json'}, api_version: 'v1')
  response = send_request(
    :put,
    endpoint,
    parameters: parameters,
    headers: headers,
    api_version: api_version
  )
  valid?(response)
end