Class: Oceanarium::SSHKey

Inherits:
Object
  • Object
show all
Defined in:
lib/oceanarium/resources/sshkey.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option, api_key, client_id) ⇒ SSHKey

Returns a new instance of SSHKey.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/oceanarium/resources/sshkey.rb', line 7

def initialize(option, api_key, client_id)
  if api_key.nil? || client_id.nil?
    raise 'No API key/client ID!'
  else
    if option.is_a?(Hash)
      @object = option
    else
      @object = Oceanarium::SSHKey.find(option)
    end
    if @object.nil?
      self.id = nil
    else
      self.id = @object['id']
      self.name = @object['name']
      self.ssh_pub_key = @object['ssh_pub_key']
    end
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/oceanarium/resources/sshkey.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/oceanarium/resources/sshkey.rb', line 5

def name
  @name
end

#ssh_pub_keyObject

Returns the value of attribute ssh_pub_key.



5
6
7
# File 'lib/oceanarium/resources/sshkey.rb', line 5

def ssh_pub_key
  @ssh_pub_key
end

Class Method Details

.allObject

Core API



45
46
47
48
49
50
51
52
# File 'lib/oceanarium/resources/sshkey.rb', line 45

def self.all
  # Returns all ssh keys in Array
  @request = Oceanarium::Request.new
  @get = @request.get('/ssh_keys/')
  if @get.parsed_response['status'] == 'OK'
    @get.parsed_response['ssh_keys']
  end
end

.create(name, key) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/oceanarium/resources/sshkey.rb', line 54

def self.create(name, key)
  # Creates ssh_key
  @request = Oceanarium::Request.new
  @get = @request.get(URI::encode("/ssh_keys/new?name=#{name}&ssh_pub_key=#{key}"))
  if @get.parsed_response['status'] == 'OK'
    @get.parsed_response['ssh_key']['id']
  else
    @get.parsed_response['status']
  end
end

.destroy(id) ⇒ Object



83
84
85
86
87
88
# File 'lib/oceanarium/resources/sshkey.rb', line 83

def self.destroy(id)
  # Destroys ssh key
  @request = Oceanarium::Request.new
  @get = @request.get("/ssh_keys/#{id}/destroy")
  @get.parsed_response['status']
end

.find(id) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/oceanarium/resources/sshkey.rb', line 65

def self.find(id)
  # Returns ssh key
  @request = Oceanarium::Request.new
  @get = @request.get("/ssh_keys/#{id}/")
  if @get.parsed_response['status'] == 'OK'
    @get.parsed_response['ssh_key']
  end
end

.update(id, key) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/oceanarium/resources/sshkey.rb', line 74

def self.update(id, key)
  # Updates ssh key
  @request = Oceanarium::Request.new
  @get = @request.get(URI::encode("/ssh_keys/#{id}/edit?ssh_key_pub=#{key}"))
  if @get.parsed_response['status'] == 'OK'
    @get.parsed_response['ssh_key']
  end
end

Instance Method Details

#destroyObject



39
40
41
# File 'lib/oceanarium/resources/sshkey.rb', line 39

def destroy
  Oceanarium::SSHKey.destroy(self.id)
end

#edit(key) ⇒ Object



35
36
37
# File 'lib/oceanarium/resources/sshkey.rb', line 35

def edit(key)
  Oceanarium::SSHKey.update(self.id, key)
end

#new(name, key) ⇒ Object

User API



28
29
30
31
32
33
# File 'lib/oceanarium/resources/sshkey.rb', line 28

def new(name, key)
  @new_id = Oceanarium::SSHKey.create(name, id)
  unless @new_id == 'ERROR'
    Oceanarium::ssh_key(@new_id)
  end
end