Class: Slack::API::Permissions

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-wrapper/api/permissions.rb

Instance Method Summary collapse

Instance Method Details

#request(opts = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/slack-wrapper/api/permissions.rb', line 28

def request(opts={})
  if Slack::API::Auth
    if opts.key?('scopes') && opts.key?("trigger_id")
      Slack::Errors.new({'error' => 'no_scope', 'detail' => 'You must provide a comma separated scope'}) if opts['scopes'].empty?
      Slack::Errors.new({'error' => 'no_trigger_id', 'detail' => 'You must provide a trigger id'}) if opts['trigger_id'].empty?
    else
      Slack::Errors.new({'error' => 'invalid_parameters', 'detail' => 'You must provide both scopes and trigger_id as options'})
    end
    opts['token'] = Slack::Config.token
    uri = URI.parse('https://slack.com/api/apps.permissions.info')
    req = Net::HTTP::Post::Multipart.new(uri.path, opts)
    res = Net::HTTP::new(uri.host, uri.port)
    res.use_ssl = true
    res.verify_mode = OpenSSL::SSL::VERIFY_NONE
    resp = res.start do |http|
      http.request(req)
    end
    false unless resp.code == 200
    if JSON.parse(resp.body)['ok']
      true
    else
      Slack::Errors.new(JSON.parse(resp.body))
    end
  else
    Slack::Errors.new({"error" => "not_authed"})
  end
end

#show(opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slack-wrapper/api/permissions.rb', line 7

def show(opts={})
  if Slack::API::Auth
    opts['token'] = Slack::Config.token
    uri = URI.parse('https://slack.com/api/apps.permissions.info')
    req = Net::HTTP::Post::Multipart.new(uri.path, opts)
    res = Net::HTTP::new(uri.host, uri.port)
    res.use_ssl = true
    res.verify_mode = OpenSSL::SSL::VERIFY_NONE
    resp = res.start do |http|
      http.request(req)
    end
    false unless resp.code == 200
    if JSON.parse(resp.body)['ok']
      JSON.parse(resp.body)['info']
    else
      Slack::Errors.new(JSON.parse(resp.body))
    end
  else
    Slack::Errors.new({"error" => "not_authed"})
  end
end