class Tumugi::Plugin::WebhookTask
Constants
- BODY_ENCODINGS
- METHODS
Public Instance Methods
run()
click to toggle source
# File lib/tumugi/plugin/task/webhook.rb, line 21 def run validate_parameters! conn = Faraday.new(url: url) do |c| c.request :retry c.request body_encoding.downcase.to_sym c.response :follow_redirects c.response :webhook_logger, logger c.adapter Faraday.default_adapter end m = http_method.downcase.to_sym http_body = [:get, :delete].include?(m) ? nil : body begin res = conn.run_request(m, nil, http_body, nil) if !res.success? raise Tumugi::TumugiError.new("#{m} #{url} failed: #{res.status} #{res.body}") end rescue => e raise Tumugi::TumugiError.new("#{m} #{url} failed", e) end if _output && _output.is_a?(Tumugi::Plugin::FileSystemTarget) _output.open("w") do |f| f.write(res.body) end end end
Private Instance Methods
validate_parameters!()
click to toggle source
# File lib/tumugi/plugin/task/webhook.rb, line 52 def validate_parameters! if !METHODS.include?(http_method.downcase.to_sym) raise Tumugi::TumugiError.new("Unsupported http method: #{http_method}") end if !BODY_ENCODINGS.include?(body_encoding.downcase.to_sym) raise Tumugi::TumugiError.new("Unsupported body encoding: #{body_encoding}") end end