Class: Morpheus::InstanceTypesInterface

Inherits:
APIClient
  • Object
show all
Defined in:
lib/morpheus/api/instance_types_interface.rb

Instance Method Summary collapse

Methods inherited from APIClient

#groups, #instance_types, #instances, #servers, #zones

Constructor Details

#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ InstanceTypesInterface

Returns a new instance of InstanceTypesInterface.



5
6
7
8
9
10
# File 'lib/morpheus/api/instance_types_interface.rb', line 5

def initialize(access_token, refresh_token,expires_at = nil, base_url=nil) 
  @access_token = access_token
  @refresh_token = refresh_token
  @base_url = base_url
  @expires_at = expires_at
end

Instance Method Details

#get(options = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/morpheus/api/instance_types_interface.rb', line 13

def get(options=nil)
  url = "#{@base_url}/api/instance-types"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }

  if options.is_a?(Hash)
    headers[:params].merge!(options)
  elsif options.is_a?(Numeric)
    url = "#{@base_url}/api/instance-types/#{options}"
  elsif options.is_a?(String)
    headers[:params]['name'] = options
  end
  response = RestClient::Request.execute(method: :get, url: url,
                           timeout: 10, headers: headers)
  JSON.parse(response.to_s)
end

#service_plans(layout_id, name = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/morpheus/api/instance_types_interface.rb', line 29

def service_plans(layout_id, name=nil)
  url = "#{@base_url}/api/instance-types/service-plans/#{layout_id}"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }

  if !name.nil?
    headers[:params][:name] = name
  end
  response = RestClient::Request.execute(method: :get, url: url,
                           timeout: 10, headers: headers)
  JSON.parse(response.to_s)
end