Class: Morpheus::KeyPairsInterface

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

Instance Method Summary collapse

Methods inherited from APIClient

#accounts, #app_templates, #apps, #clouds, #deploy, #deployments, #groups, #instance_types, #instances, #key_pairs, #license, #load_balancers, #logs, #options, #provision_types, #roles, #security_group_rules, #security_groups, #servers, #task_sets, #tasks, #users, #virtual_images

Constructor Details

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

Returns a new instance of KeyPairsInterface.



5
6
7
8
9
10
# File 'lib/morpheus/api/key_pairs_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(account_id, options) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/morpheus/api/key_pairs_interface.rb', line 32

def create(, options)
  url = "#{@base_url}/api/key-pairs"
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  headers[:params]['accountId'] =  if 
  payload = options
  response = Morpheus::RestClient.execute(method: :post, url: url,
                          timeout: 10, headers: headers, payload: payload.to_json)
  JSON.parse(response.to_s)
end

#destroy(account_id, id) ⇒ Object



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

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

#get(account_id, id) ⇒ Object



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

def get(, id)
  raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
  url = "#{@base_url}/api/key-pairs/#{id}"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
  headers[:params]['accountId'] =  if 
  response = Morpheus::RestClient.execute(method: :get, url: url,
                          timeout: 10, headers: headers)
  JSON.parse(response.to_s)
end

#list(account_id, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/morpheus/api/key_pairs_interface.rb', line 22

def list(, options={})
  url = "#{@base_url}/api/key-pairs"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
  headers[:params].merge!(options)
  headers[:params]['accountId'] =  if 
  response = Morpheus::RestClient.execute(method: :get, url: url,
                          timeout: 10, headers: headers)
  JSON.parse(response.to_s)
end

#update(account_id, id, options) ⇒ Object



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

def update(, id, options)
  url = "#{@base_url}/api/key-pairs/#{id}"
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  headers[:params]['accountId'] =  if 
  payload = options
  response = Morpheus::RestClient.execute(method: :put, url: url,
                          timeout: 10, headers: headers, payload: payload.to_json)
  JSON.parse(response.to_s)
end