Class: HitorigotoReporter::Hitorigoto
- Inherits:
-
Object
- Object
- HitorigotoReporter::Hitorigoto
- Defined in:
- lib/hitorigoto_reporter/hitorigoto.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#permalink ⇒ Object
readonly
Returns the value of attribute permalink.
-
#stamps ⇒ Object
readonly
Returns the value of attribute stamps.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json, stamps = []) ⇒ Hitorigoto
constructor
A new instance of Hitorigoto.
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_at ⇒ Object (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 |
#permalink ⇒ Object (readonly)
Returns the value of attribute permalink.
3 4 5 |
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 3 def permalink @permalink end |
#stamps ⇒ Object (readonly)
Returns the value of attribute stamps.
3 4 5 |
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 3 def stamps @stamps end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/hitorigoto_reporter/hitorigoto.rb', line 3 def text @text end |
#username ⇒ Object (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.(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 |