Class: SlackExport::SlackClient
- Inherits:
-
Object
- Object
- SlackExport::SlackClient
- 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
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #get_channels ⇒ Object
- #get_messages ⇒ Object
- #get_users ⇒ Object
-
#initialize(api_key, channel_name) ⇒ SlackClient
constructor
A new instance of SlackClient.
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
#channel ⇒ Object
Returns the value of attribute channel.
12 13 14 |
# File 'lib/slack_export/slack_client.rb', line 12 def channel @channel end |
#token ⇒ Object
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_channels ⇒ Object
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_messages ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/slack_export/slack_client.rb', line 29 def () 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_users ⇒ Object
19 20 21 22 |
# File 'lib/slack_export/slack_client.rb', line 19 def get_users response = post_form(LIST_USERS) response["members"] end |