Class: Slackpolice::Client
- Inherits:
-
Object
- Object
- Slackpolice::Client
- Defined in:
- lib/slackpolice/client.rb
Instance Method Summary collapse
- #archive ⇒ Object
- #delete_expired_files(ts_to = Date.today.prev_day(7)) ⇒ Object
- #expired_files(ts_to = Date.today.prev_day(7)) ⇒ Object
-
#initialize(cli_options = {}) ⇒ Client
constructor
A new instance of Client.
- #no_members_channels ⇒ Object
Constructor Details
#initialize(cli_options = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 |
# File 'lib/slackpolice/client.rb', line 7 def initialize( = {}) @cli_options = @logger ||= Logger.new STDOUT @client = Slack::Client.new @cli_options[:api_token] @client.auth_test end |
Instance Method Details
#archive ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/slackpolice/client.rb', line 15 def archive archives = [] no_members_channels.each do |c| resp = @client.channels_archive('channel' => c['id']) archives << c if resp['ok'] end archives end |
#delete_expired_files(ts_to = Date.today.prev_day(7)) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/slackpolice/client.rb', line 24 def delete_expired_files(ts_to = Date.today.prev_day(7)) Enumerator.new do |y| expired_files(ts_to).each do |f| resp = @client.files_delete('file' => f['id']) y << f if resp['ok'] end end end |
#expired_files(ts_to = Date.today.prev_day(7)) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/slackpolice/client.rb', line 39 def expired_files(ts_to = Date.today.prev_day(7)) page = 1 Enumerator.new do |y| begin resp = @client.files_list('ts_to' => ts_to.to_time.to_i, 'page' => page) if resp['ok'] pages = resp['paging']['pages'] resp['files'].map do |file| y << file end end page += 1 end while pages >= page && 100 > page # over 100 page is not found. api bug? end end |
#no_members_channels ⇒ Object
33 34 35 36 37 |
# File 'lib/slackpolice/client.rb', line 33 def no_members_channels @client.channels_list['channels'].select do |c| c['num_members'] == 0 && c['is_archived'] == false end end |