Class: Morpheus::GroupsInterface

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

Instance Method Summary collapse

Constructor Details

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



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

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



27
28
29
30
31
32
33
# File 'lib/morpheus/api/groups_interface.rb', line 27

def create(options)
  url = "#{@base_url}/api/groups"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  opts = {method: :post, url: url, timeout: 30, headers: headers, payload: payload.to_json}
  execute(opts)
end

#destroy(id) ⇒ Object



43
44
45
46
47
48
# File 'lib/morpheus/api/groups_interface.rb', line 43

def destroy(id)
  url = "#{@base_url}/api/groups/#{id}"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :delete, url: url, timeout: 30, headers: headers}
  execute(opts)
end

#get(options = nil) ⇒ Object



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

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

  if options.is_a?(Hash)
    headers[:params].merge!(options)
  elsif options.is_a?(Numeric)
    url = "#{@base_url}/api/groups/#{options}"
  elsif options.is_a?(String)
    headers[:params]['name'] = options
  end
  opts = {method: :get, url: url, timeout: 30, headers: headers}
  execute(opts)
end

#update(id, options) ⇒ Object



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

def update(id, options)
  url = "#{@base_url}/api/groups/#{id}"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#update_zones(id, options) ⇒ Object



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

def update_zones(id, options)
  url = "#{@base_url}/api/groups/#{id}/update-zones"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  opts = {method: :put, url: url, timeout: 30, headers: headers, payload: payload.to_json}
  execute(opts)
end