Class: Lita::Handlers::Deploygate

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_config(config) ⇒ Object



34
35
36
37
38
# File 'lib/lita/handlers/deploygate.rb', line 34

def self.default_config(config)
  config.user_name      = nil
  config.api_key        = nil
  config.default_app_id = nil
end

Instance Method Details

#add(response) ⇒ Object



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

def add(response)
  short_name = response.matches[0][2]
  user_identifier = response.matches[0][1]
  if valid_app_name?(short_name)
    result = api_request('post',
                         "/#{app_path(short_name)}/members",
                         'users' => "[#{user_identifier}]")
    if result
      response.reply("#{short_name}: #{user_identifier} added")
    else
      response.reply('There was an error making the request to DeployGate')
    end
  else
    response.reply("#{short_name}: unknown application name")
  end
end

#list(response) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/lita/handlers/deploygate.rb', line 74

def list(response)
  short_name = response.matches[0][1]
  if valid_app_name?(short_name)
    result = api_request('get', "/#{app_path(short_name)}/members")
    if result
      users = result['results']['users']
      if users.count > 0
        users.each do |user|
          response.reply("#{short_name}: #{user['name']}, role: #{user['role']}")
        end
      else
        response.reply("#{short_name}: No users")
      end
    else
      response.reply('There was an error making the request to DeployGate')
    end
  else
    response.reply("#{short_name}: unknown application name")
  end
end

#remove(response) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lita/handlers/deploygate.rb', line 57

def remove(response)
  short_name = response.matches[0][2]
  user_identifier = response.matches[0][1]
  if valid_app_name?(short_name)
    result = api_request('delete',
                         "/#{app_path(short_name)}/members",
                         'users' => "[#{user_identifier}]")
    if result
      response.reply("#{short_name}: #{user_identifier} removed")
    else
      response.reply('There was an error making the request to DeployGate')
    end
  else
    response.reply("#{short_name}: unknown application name")
  end
end