module Slack::API::IM

Public Instance Methods

close(id, opts={}) click to toggle source
# File lib/slack-wrapper/api/im.rb, line 33
def close(id, opts={})
  if Slack::API::Auth
    opts['channel'] = id
    opts['token'] = Slack::Config.token
    uri = URI.parse('https://slack.com/api/im.close')
    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
history(id, opts={}) click to toggle source
# File lib/slack-wrapper/api/im.rb, line 55
def history(id, opts={})
  if Slack::API::Auth
    opts['channel'] = id
    opts['token'] = Slack::Config.token
    uri = URI.parse('https://slack.com/api/im.history')
    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)['messages']
    else
      Slack::Errors.new(JSON.parse(resp.body))
    end
  else
    Slack::Errors.new({"error" => "not_authed"})
  end
end
list(opts={}) click to toggle source
# File lib/slack-wrapper/api/im.rb, line 77
def list(opts={})
  if Slack::API::Auth
    opts['token'] = Slack::Config.token
    uri = URI.parse('https://slack.com/api/im.list')
    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)['ims']
    else
      Slack::Errors.new(JSON.parse(resp.body))
    end
  else
    Slack::Errors.new({"error" => "not_authed"})
  end
end
open(id, opts={}) click to toggle source
# File lib/slack-wrapper/api/im.rb, line 9
def open(id, opts={})
  if Slack::API::Auth
    opts['user'] = id
    opts['return_im'] = true
    opts['token'] = Slack::Config.token
    opts['include_locale'] = true
    uri = URI.parse('https://slack.com/api/im.open')
    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)['channel']
    else
      Slack::Errors.new(JSON.parse(resp.body))
    end
  else
    Slack::Errors.new({"error" => "not_authed"})
  end
end