Class: JekyllRecker::Social::Slack

Inherits:
Share
  • Object
show all
Defined in:
lib/jekyll_recker/social.rb

Overview

Slack

Slack social sharing backend

Constant Summary collapse

KEY =
'slack'

Instance Attribute Summary

Attributes inherited from Share

#site

Instance Method Summary collapse

Methods inherited from Share

#config, #config_key, #dry?, #initialize, #latest, #latest_title, share

Methods included from Logging

included, #info, #logger

Constructor Details

This class inherits a constructor from JekyllRecker::Social::Share

Instance Method Details

#configure!Object



82
83
84
85
86
87
88
89
90
# File 'lib/jekyll_recker/social.rb', line 82

def configure!
  @creds = {}
  workspaces.each do |key, data|
    webhook = ENV["SLACK_#{key.upcase}_WEBHOOK"] || extract_from_config(data)
    raise "cannot find slack webhook for #{key} workspace!" if webhook.nil?

    @creds[key] = webhook
  end
end

#post(key, config) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/jekyll_recker/social.rb', line 103

def post(key, config)
  ::Slack::Notifier.new(
    @creds[key].strip,
    channel: config.fetch('channel'),
    username: config.fetch('username'),
    icon_emoji: config.fetch('emoji')
  ).post(text: post_body)
end

#post!Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/jekyll_recker/social.rb', line 92

def post!
  workspaces.each do |key, config|
    info "posting to #{key} workspace"
    if @dry
      puts "BEGIN MESSAGE\n#{post_body.strip}\nEND MESSAGE"
    else
      post(key, config)
    end
  end
end

#post_bodyObject



112
113
114
# File 'lib/jekyll_recker/social.rb', line 112

def post_body
  ::Slack::Notifier::Util::LinkFormatter.format(super)
end