Class: Earch::Notify
- Inherits:
-
Object
- Object
- Earch::Notify
- Defined in:
- lib/twing_earch/notify.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
Instance Method Summary collapse
- #body(object) ⇒ Object
-
#initialize(setting) ⇒ Notify
constructor
A new instance of Notify.
- #notify(object) ⇒ Object
Constructor Details
#initialize(setting) ⇒ Notify
Returns a new instance of Notify.
6 7 8 9 |
# File 'lib/twing_earch/notify.rb', line 6 def initialize(setting) @setting = setting @client = Slack::Web::Client.new(setting.api_key) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/twing_earch/notify.rb', line 4 def client @client end |
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
4 5 6 |
# File 'lib/twing_earch/notify.rb', line 4 def setting @setting end |
Instance Method Details
#body(object) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/twing_earch/notify.rb', line 20 def body(object) [ { fallback: "#{object.text} by @#{object.user.screen_name}", color: '#4169e1', author_name: "#{object.user.name}(@#{object.user.screen_name})", author_link: object.user.url, author_icon: object.user.profile_image_url_https, text: object.text, fields: [ { value: "<#{object.url}|Tweet>", } ], footer: "#{setting.icon} #{setting.source_user}", ts: object.created_at.to_f } ] end |
#notify(object) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/twing_earch/notify.rb', line 11 def notify(object) client.chat_postMessage( icon_emoji: setting.user_icon, username: 'Earch', channel: setting.notify_channel, attachments: body(object) ) end |