Class: Lita::Handlers::Digitalocean::SSHKey
- Defined in:
- lib/lita/handlers/digitalocean/ssh_key.rb
Instance Method Summary collapse
- #add(response) ⇒ Object
- #delete(response) ⇒ Object
- #edit(response) ⇒ Object
- #list(response) ⇒ Object
- #show(response) ⇒ Object
Methods inherited from Base
Instance Method Details
#add(response) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 25 def add(response) name, public_key = response.args[3..4] unless name && public_key return response.reply("#{t('format')}: #{t('help.ssh_keys.add_key')}") end do_response = do_call(response) do |client| client.ssh_keys.add(name: name, ssh_pub_key: public_key) end or return response.reply(t("ssh_keys.add.created", do_response[:ssh_key])) end |
#delete(response) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 39 def delete(response) key_id = response.matches[0][0] do_call(response) do |client| client.ssh_keys.delete(key_id) end or return response.reply(t("ssh_keys.delete.deleted", key_id: key_id)) end |
#edit(response) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 49 def edit(response) kwargs = {} if (name = response.extensions[:kwargs][:name]) kwargs[:name] = name end if (public_key = response.extensions[:kwargs][:public_key]) kwargs[:ssh_pub_key] = public_key end do_response = do_call(response) do |client| client.ssh_keys.edit(response.matches[0][0], kwargs) end or return response.reply(t("ssh_keys.edit.updated", do_response[:ssh_key])) end |
#list(response) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 67 def list(response) do_response = do_call(response) do |client| client.ssh_keys.list end or return if do_response[:ssh_keys].empty? response.reply(t("ssh_keys.list.empty")) else do_response[:ssh_keys].each do |key| response.reply("#{key[:id]} (#{key[:name]})") end end end |
#show(response) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 81 def show(response) do_response = do_call(response) do |client| client.ssh_keys.show(response.matches[0][0]) end or return key = do_response[:ssh_key] response.reply("#{key[:id]} (#{key[:name]}): #{key[:ssh_pub_key]}") end |