Sha256: ce33a53826c126329910918c2e0defb3d83590fb2d799cfa64700730254fd657

Contents?: true

Size: 862 Bytes

Versions: 1

Compression:

Stored size: 862 Bytes

Contents

require 'ostruct'
require 'bearychat/http_client'
require 'json'

module Bearychat
  class Incoming < OpenStruct

    DEFAULT_PARAMS = {
      text: "text, this field may accept markdown",
      markdown: true,
      channel: "",
      attachments: []
    }

    attr_reader :http_client

    def initialize(hook, info={})
      @http_client = HttpClient.new(hook)
      super(DEFAULT_PARAMS.merge(info))
    end

    def reset(info)
      info.each { |key, value| self[key] = value }
      self
    end

    def send(body = {})
      if block_given?
        yield self
        send()
      elsif !body.empty?
        http_client.post_json(body.to_json)
      else
        http_client.post_json(as_json)
      end
    end

    def switch(channel)
      self.channel = channel
      self
    end

    private
    def as_json
      to_h.to_json
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bearychat-1.0.0 lib/bearychat/incoming.rb