Class: HitorigotoReporter::Hitorigoto

Inherits:
Object
  • Object
show all
Defined in:
lib/hitorigoto_reporter/hitorigoto.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, stamps = []) ⇒ Hitorigoto

Returns a new instance of Hitorigoto.



5
6
7
8
9
10
11
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 5

def initialize(json, stamps = [])
  @username   = json['username']
  @text       = json['text']
  @permalink  = json['permalink']
  @created_at = Time.at(json['ts'].to_f)
  @stamps     = stamps
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



3
4
5
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 3

def created_at
  @created_at
end

Returns the value of attribute permalink.



3
4
5
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 3

def permalink
  @permalink
end

#stampsObject (readonly)

Returns the value of attribute stamps.



3
4
5
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 3

def stamps
  @stamps
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 3

def text
  @text
end

#usernameObject (readonly)

Returns the value of attribute username.



3
4
5
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 3

def username
  @username
end

Class Method Details

.fetch(channel_name, target_date) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 13

def self.fetch(channel_name, target_date)
  date_query = target_date.strftime("%Y-%m-%d")
  query = ["on:#{date_query}", "in:#{channel_name}"].join(' ')
  res = Slack.client.search_messages(query: query)
  res['messages']['matches']
    .select { |m| m['type'] == 'message' }
    .map { |m|
      reaction = Slack.client.reactions_get(channel: m['channel']['id'], timestamp: m['ts'])
      stamps = (reaction['message']['reactions'] || []).map { |r| r['name'] }
      Hitorigoto.new(m, stamps) 
    }
end