Class: CocoapodsNexus::API::NexusConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-nexus/api/connection.rb

Constant Summary collapse

VALID_RESPONSE_CODES =
[200, 201, 204].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname:) ⇒ NexusConnection

Returns a new instance of NexusConnection.



13
14
15
# File 'lib/cocoapods-nexus/api/connection.rb', line 13

def initialize(hostname:)
  @hostname = hostname
end

Instance Attribute Details

#continuation_tokenObject

Returns the value of attribute continuation_token.



11
12
13
# File 'lib/cocoapods-nexus/api/connection.rb', line 11

def continuation_token
  @continuation_token
end

Instance Method Details

#content_length(asset_url:) ⇒ Object



64
65
66
67
68
# File 'lib/cocoapods-nexus/api/connection.rb', line 64

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



48
49
50
51
52
53
54
55
56
# File 'lib/cocoapods-nexus/api/connection.rb', line 48

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



70
71
72
73
74
# File 'lib/cocoapods-nexus/api/connection.rb', line 70

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



22
23
24
# File 'lib/cocoapods-nexus/api/connection.rb', line 22

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



17
18
19
20
# File 'lib/cocoapods-nexus/api/connection.rb', line 17

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

#head(asset_url:) ⇒ Object



58
59
60
61
62
# File 'lib/cocoapods-nexus/api/connection.rb', line 58

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

#paginate?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/cocoapods-nexus/api/connection.rb', line 76

def paginate?
  !@continuation_token.nil?
end

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



26
27
28
29
30
31
32
33
34
35
# File 'lib/cocoapods-nexus/api/connection.rb', line 26

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



37
38
39
40
41
42
43
44
45
46
# File 'lib/cocoapods-nexus/api/connection.rb', line 37

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