Sha256: 26554ff31fb0741b93dd3e6aaee9007d405d76e2112353a9ca9fb8feffe6d1a7

Contents?: true

Size: 807 Bytes

Versions: 1

Compression:

Stored size: 807 Bytes

Contents

module Slack
  class Payload
    attr_accessor :username, :channel, :text, :token, :icon_url, :attachments

    def initialize(options = {})
      @username    = options[:username] || Slack.username
      @channel     = options[:channel]  || Slack.default_channel
      @text        = options[:text]
      @token       = options[:token]
      @icon_url    = options[:icon_url]
      @attachments = options[:attachments]

      unless channel[0] =~ /^(#|@)/
        @channel = "##{@channel}"
      end
    end

    def to_hash
     hash = {
        text:        text,
        username:    username,
        channel:     channel,
        token:       token,
        icon_url:    icon_url,
        attachments: attachments.to_json
      }

      hash.delete_if { |_,v| v.nil? || v == "null"}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack.rb-0.0.6 lib/slack/payload.rb