Class: Morpheus::ZonesInterface

Inherits:
APIClient show all
Defined in:
lib/morpheus/api/zones_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) ⇒ ZonesInterface

Returns a new instance of ZonesInterface.



5
6
7
8
9
10
# File 'lib/morpheus/api/zones_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

#create(options) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/morpheus/api/zones_interface.rb', line 39

def create(options)
  url = "#{@base_url}/api/zones"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  
  payload = {zone: options}
  response = RestClient::Request.execute(method: :post, url: url,
                           timeout: 10, headers: headers, payload: payload.to_json)
  JSON.parse(response.to_s)
end

#destroy(id) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/morpheus/api/zones_interface.rb', line 49

def destroy(id)
  url = "#{@base_url}/api/zones/#{id}"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  response = RestClient::Request.execute(method: :delete, url: url,
                           timeout: 10, headers: headers)
  JSON.parse(response.to_s)
end

#get(options = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/morpheus/api/zones_interface.rb', line 22

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

  if options.is_a?(Hash)
    headers[:params].merge!(options)
  elsif options.is_a?(Numeric)
    url = "#{@base_url}/api/zones/#{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

#zone_typesObject



12
13
14
15
16
17
18
19
# File 'lib/morpheus/api/zones_interface.rb', line 12

def zone_types()
  url = "#{@base_url}/api/zone-types"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }

  response = RestClient::Request.execute(method: :get, url: url,
                           timeout: 10, headers: headers)
  JSON.parse(response.to_s)
end