Class: Morpheus::SecurityGroupsInterface

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SecurityGroupsInterface.



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



34
35
36
37
38
39
40
41
42
# File 'lib/morpheus/api/security_groups_interface.rb', line 34

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

#delete(id) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/morpheus/api/security_groups_interface.rb', line 52

def delete(id)
  url = "#{@base_url}/api/security-groups/#{id}"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  response = Morpheus::RestClient.execute(method: :delete, url: url,
                           timeout: 30, headers: headers, verify_ssl: false)
  JSON.parse(response.to_s)
end

#get(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/morpheus/api/security_groups_interface.rb', line 23

def get(options)
  url = "#{@base_url}/api/security-groups/#{options[:id]}"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
  if options.is_a?(Hash)
    headers[:params].merge!(options)
  end
  response = Morpheus::RestClient.execute(method: :get, url: url,
                           timeout: 30, headers: headers, verify_ssl: false)
  JSON.parse(response.to_s)
end

#list(options = nil) ⇒ Object



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

def list(options=nil)
  url = "#{@base_url}/api/security-groups"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
  if options.is_a?(Hash)
    headers[:params].merge!(options)
  end
  response = Morpheus::RestClient.execute(method: :get, url: url,
                           timeout: 30, headers: headers, verify_ssl: false)
  JSON.parse(response.to_s)
end

#update(id) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/morpheus/api/security_groups_interface.rb', line 44

def update(id)
  url = "#{@base_url}/api/security-groups/#{id}"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers, verify_ssl: false)
  JSON.parse(response.to_s)
end