Class: SlackExport::SlackClient

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_export/slack_client.rb

Constant Summary collapse

BASE_URL =
"https://slack.com/api/"
LIST_USERS =
"users.list"
LIST_CHANNELS =
"groups.list"
LIST_MESSAGES =
"groups.history"
CHANNEL_INFO =
"groups.info"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, channel_name) ⇒ SlackClient



14
15
16
17
# File 'lib/slack_export/slack_client.rb', line 14

def initialize(api_key, channel_name)
  self.token = api_key
  self.channel = get_channel_id(channel_name)
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



12
13
14
# File 'lib/slack_export/slack_client.rb', line 12

def channel
  @channel
end

#tokenObject

Returns the value of attribute token.



12
13
14
# File 'lib/slack_export/slack_client.rb', line 12

def token
  @token
end

Instance Method Details

#get_channelsObject



24
25
26
27
# File 'lib/slack_export/slack_client.rb', line 24

def get_channels
  response = post_form(LIST_CHANNELS)
  response["groups"]
end

#get_messagesObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/slack_export/slack_client.rb', line 29

def get_messages()
  responses = []
  latest = latest.to_i #pages backward, so keep track of most recent message pulled
  oldest = oldest.to_i
  loop do
    responses << post_form(LIST_MESSAGES, { channel: channel, latest: latest, oldest: oldest, count: 1000})
    latest = responses.last["messages"].last["ts"]
    break unless responses.last["has_more"]
  end

  responses.map {|r| r["messages"]}.flatten
end

#get_usersObject



19
20
21
22
# File 'lib/slack_export/slack_client.rb', line 19

def get_users
  response = post_form(LIST_USERS)
  response["members"]
end