lib/rest_client/jogger/action.rb in rest-client-jogger-1.1.0 vs lib/rest_client/jogger/action.rb in rest-client-jogger-1.2.0
- old
+ new
@@ -12,23 +12,12 @@
def notifier
@notifier ||= ::Rollbar
end
def call(name, start, finish, id, payload)
- start_time = payload.fetch(:start_time)
- render_params = {
- args: payload,
- payload: filter(payload),
- verify_ssl: payload[:verify_ssl],
- read_timeout: payload.fetch(:timeout) { payload[:read_timeout] },
- open_timeout: payload.fetch(:timeout) { payload[:open_timeout] },
- event_id: id,
- timestamp: start,
- time_elapsed: (finish - start_time).round(10),
- ip_address: ip_address
- }
- json = template.render nil, render_params
+ params = render_params(start, finish, id, payload)
+ json = template.render(nil, params)
name =~ /error/ ? logger.error(json) : logger.debug(json)
rescue StandardError => e
notifier.error e, payload: payload
end
@@ -36,11 +25,30 @@
raise NotImplementedError, 'define a #template method in a subclass'
end
private
+ def render_params(start, finish, id, opts)
+ start_time = opts.fetch(:start_time)
+ url = opts.fetch(:url)
+ headers = opts.fetch(:headers) { {} }
+ {
+ method: opts[:method],
+ headers: headers,
+ url: RestClient::Jogger::Filters::QueryParameters.new(data: url).filter,
+ payload: filter(body: opts[:payload], headers: headers),
+ verify_ssl: opts[:verify_ssl],
+ read_timeout: opts.fetch(:timeout) { opts[:read_timeout] },
+ open_timeout: opts.fetch(:timeout) { opts[:open_timeout] },
+ event_id: id,
+ timestamp: start,
+ time_elapsed: (finish - start_time).round(10),
+ ip_address: ip_address
+ }
+ end
+
def filter(opts = {})
- filter_class(opts[:headers] || {}).new(data: opts[:payload].to_s).filter
+ filter_class(opts.fetch(:headers)).new(data: opts[:body].to_s).filter
end
def filter_class(headers = {})
content_type = headers.fetch(:content_type) { 'application/json' }
RestClient::Jogger::Filters::Base.filter_class(content_type)