Class: Lita::Handlers::Digitalocean

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/digitalocean.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_config(config) ⇒ Object



6
7
8
9
# File 'lib/lita/handlers/digitalocean.rb', line 6

def self.default_config(config)
  config.client_id = nil
  config.api_key = nil
end

Instance Method Details

#ssh_keys_add(response) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lita/handlers/digitalocean.rb', line 39

def ssh_keys_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

  key = do_response.ssh_key
  response.reply(
    t("ssh_keys.add.created", message: "#{key.id} (#{key.name}): #{key.ssh_pub_key}")
  )
end

#ssh_keys_delete(response) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/lita/handlers/digitalocean.rb', line 56

def ssh_keys_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

#ssh_keys_edit(response) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/lita/handlers/digitalocean.rb', line 66

def ssh_keys_edit(response)
  args = extract_named_args(response.args, :name, :public_key)

  if args[:public_key]
    args[:ssh_pub_key] = args.delete(:public_key)
  end

  do_response = do_call(response) do |client|
    client.ssh_keys.edit(response.matches[0][0], args)
  end or return

  key = do_response.ssh_key
  response.reply(
    t("ssh_keys.edit.updated", message: "#{key.id} (#{key.name}): #{key.ssh_pub_key}")
  )
end

#ssh_keys_list(response) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/lita/handlers/digitalocean.rb', line 83

def ssh_keys_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

#ssh_keys_show(response) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/lita/handlers/digitalocean.rb', line 97

def ssh_keys_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