Class: NexusAPI::NexusConnection
- Inherits:
-
Object
- Object
- NexusAPI::NexusConnection
- Defined in:
- lib/nexus_api/nexus_connection.rb
Constant Summary collapse
- VALID_RESPONSE_CODES =
[200, 204].freeze
Instance Attribute Summary collapse
-
#continuation_token ⇒ Object
Returns the value of attribute continuation_token.
Instance Method Summary collapse
- #content_length(asset_url:) ⇒ Object
- #delete(endpoint:, headers: {'Content-Type' => 'application/json'}) ⇒ Object
- #download(url:) ⇒ Object
- #get(endpoint:, paginate: false, headers: {'Content-Type' => 'application/json'}) ⇒ Object
- #get_response(endpoint:, paginate: false, headers: {'Content-Type' => 'application/json'}) ⇒ Object
- #head(asset_url:) ⇒ Object
-
#initialize(username:, password:, hostname:) ⇒ NexusConnection
constructor
A new instance of NexusConnection.
- #paginate? ⇒ Boolean
- #post(endpoint:, parameters: '', headers: {'Content-Type' => 'application/json'}) ⇒ Object
- #put(endpoint:, parameters: '', headers: {'Content-Type' => 'application/json'}) ⇒ Object
Constructor Details
#initialize(username:, password:, hostname:) ⇒ NexusConnection
Returns a new instance of NexusConnection.
10 11 12 13 14 |
# File 'lib/nexus_api/nexus_connection.rb', line 10 def initialize(username:, password:, hostname:) @username = username @password = password @hostname = hostname end |
Instance Attribute Details
#continuation_token ⇒ Object
Returns the value of attribute continuation_token.
8 9 10 |
# File 'lib/nexus_api/nexus_connection.rb', line 8 def continuation_token @continuation_token end |
Instance Method Details
#content_length(asset_url:) ⇒ Object
60 61 62 63 64 |
# File 'lib/nexus_api/nexus_connection.rb', line 60 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
45 46 47 48 49 50 51 52 |
# File 'lib/nexus_api/nexus_connection.rb', line 45 def delete(endpoint:, headers: {'Content-Type' => 'application/json'}) response = send_request( :delete, endpoint, headers: headers ) valid?(response) end |
#download(url:) ⇒ Object
66 67 68 69 70 |
# File 'lib/nexus_api/nexus_connection.rb', line 66 def download(url:) catch_connection_error do RestClient.get(url, ) end end |
#get(endpoint:, paginate: false, headers: {'Content-Type' => 'application/json'}) ⇒ Object
21 22 23 |
# File 'lib/nexus_api/nexus_connection.rb', line 21 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
16 17 18 19 |
# File 'lib/nexus_api/nexus_connection.rb', line 16 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
54 55 56 57 58 |
# File 'lib/nexus_api/nexus_connection.rb', line 54 def head(asset_url:) catch_connection_error do RestClient.head(asset_url) end end |
#paginate? ⇒ Boolean
72 73 74 |
# File 'lib/nexus_api/nexus_connection.rb', line 72 def paginate? !@continuation_token.nil? end |
#post(endpoint:, parameters: '', headers: {'Content-Type' => 'application/json'}) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/nexus_api/nexus_connection.rb', line 25 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
35 36 37 38 39 40 41 42 43 |
# File 'lib/nexus_api/nexus_connection.rb', line 35 def put(endpoint:, parameters: '', headers: {'Content-Type' => 'application/json'}) response = send_request( :put, endpoint, parameters: parameters, headers: headers ) valid?(response) end |