lib/bearychat/incoming.rb in bearychat-0.1.1 vs lib/bearychat/incoming.rb in bearychat-1.0.0
- old
+ new
@@ -1,37 +1,39 @@
-require 'httparty'
require 'ostruct'
+require 'bearychat/http_client'
+require 'json'
module Bearychat
class Incoming < OpenStruct
- include HTTParty
DEFAULT_PARAMS = {
text: "text, this field may accept markdown",
- markdown: false,
+ markdown: true,
channel: "",
attachments: []
}
- attr_reader :hook
+ attr_reader :http_client
def initialize(hook, info={})
- @hook = hook
+ @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
+ def send(body = {})
if block_given?
yield self
send()
+ elsif !body.empty?
+ http_client.post_json(body.to_json)
else
- self.class.post(hook, body: { payload: as_json })
+ http_client.post_json(as_json)
end
end
def switch(channel)
self.channel = channel
@@ -42,6 +44,6 @@
def as_json
to_h.to_json
end
end
-end
\ No newline at end of file
+end