Class: NexusAPI::NexusConnection

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

Constant Summary collapse

VALID_RESPONSE_CODES =
[200, 204].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of NexusConnection.



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

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

Instance Attribute Details

#continuation_tokenObject

Returns the value of attribute continuation_token.



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

def continuation_token
  @continuation_token
end

Instance Method Details

#content_length(asset_url:) ⇒ Object



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

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'}) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/nexus_api/nexus_connection.rb', line 46

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

#download(url:) ⇒ Object



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

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'}) ⇒ Object



22
23
24
# File 'lib/nexus_api/nexus_connection.rb', line 22

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

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



17
18
19
20
# File 'lib/nexus_api/nexus_connection.rb', line 17

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

#head(asset_url:) ⇒ Object



55
56
57
58
59
# File 'lib/nexus_api/nexus_connection.rb', line 55

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

#paginate?Boolean

Returns:

  • (Boolean)


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

def paginate?
  !@continuation_token.nil?
end

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



26
27
28
29
30
31
32
33
34
# File 'lib/nexus_api/nexus_connection.rb', line 26

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

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



36
37
38
39
40
41
42
43
44
# File 'lib/nexus_api/nexus_connection.rb', line 36

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