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
Instance Method Details
#add(response) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 27 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
41 42 43 44 45 46 47 48 49 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 41 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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 51 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
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 69 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
83 84 85 86 87 88 89 90 |
# File 'lib/lita/handlers/digitalocean/ssh_key.rb', line 83 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 |