class IdobataHook::Client
Public Class Methods
new(hook_url)
click to toggle source
# File lib/idobata_hook/client.rb, line 7 def initialize(hook_url) @hook_url = hook_url end
Public Instance Methods
send(messages, format: nil, image_path: nil)
click to toggle source
# File lib/idobata_hook/client.rb, line 11 def send(messages, format: nil, image_path: nil) source = Source.new(messages) params = { source: source.to_s } params[:format] = :html if format.to_s == 'html' || source.force_html? params[:image] = image_io(image_path) if image_path http_client.post(nil, params) end
Private Instance Methods
default_headers()
click to toggle source
# File lib/idobata_hook/client.rb, line 34 def default_headers { 'User-Agent' => "RubyGems::IdobataHook / #{IdobataHook::VERSION} " } end
http_client()
click to toggle source
# File lib/idobata_hook/client.rb, line 26 def http_client @faraday ||= Faraday.new(url: @hook_url, headers: default_headers) do |conn| conn.request :multipart conn.request :url_encoded # form-encode POST params conn.adapter Faraday.default_adapter # make requests with Net::HTTP end end
image_io(image_path)
click to toggle source
# File lib/idobata_hook/client.rb, line 21 def image_io(image_path) mime_type = MIME::Types.type_for(image_path).first.simplified Faraday::UploadIO.new(image_path, mime_type) end