Class: Opsmgr::Api::EndpointsFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/opsmgr/api/endpoints_factory.rb

Class Method Summary collapse

Class Method Details

.create(environment) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/opsmgr/api/endpoints_factory.rb', line 7

def self.create(environment)
  req = Net::HTTP::Get.new('/api/api_version')
  uri = URI.parse(environment.settings.ops_manager.url)
  req.basic_auth(environment.settings.ops_manager.username, environment.settings.ops_manager.password)

  response = http(uri).request(req)

  api_version = JSON.parse(response.body).fetch('version')
  case api_version
  when '2.0'
    return Opsmgr::Api::Version20::Endpoints.new
  end
end

.http(uri) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/opsmgr/api/endpoints_factory.rb', line 21

def self.http(uri)
  http = Net::HTTP.new(uri.host, uri.port)
  if uri.scheme == 'https'
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  http
end