Updated

app/models/webhook / api_client.rb

A
32 lines of codes
4 methods
5.7 complexity/method
3 churn
22.81 complexity
0 duplications
class Webhook::ApiClient
  1. Webhook::ApiClient has no descriptive comment
def initialize(webhook) @webhook = webhook @connection = create_connection end def create_connection Faraday.new(@webhook.url) do |faraday| faraday.options.timeout = 5
  1. Webhook::ApiClient#create_connection refers to 'faraday' more than self (maybe move it to another class?) Locations: 0 1
faraday.headers = { 'Content-Type': 'application/json' }
  1. Webhook::ApiClient#create_connection refers to 'faraday' more than self (maybe move it to another class?) Locations: 0 1
end end def post_request response = @connection.post if response.success?
  1. Webhook::ApiClient#post_request refers to 'response' more than self (maybe move it to another class?) Locations: 0 1 2
{ ok: response.status, request: response }
  1. Webhook::ApiClient#post_request calls 'response.status' 2 times Locations: 0 1
  2. Webhook::ApiClient#post_request refers to 'response' more than self (maybe move it to another class?) Locations: 0 1 2
else logger_error('Failed to validate webhook URL', response) { error: "Invalid or unreachable URL (status: #{response.status})", request: response }
  1. Webhook::ApiClient#post_request calls 'response.status' 2 times Locations: 0 1
  2. Webhook::ApiClient#post_request refers to 'response' more than self (maybe move it to another class?) Locations: 0 1 2
end end private def logger_error(message, response) Rails.logger.error "Webhook Api Client error: #{message} - Webhook #{@webhook.id || 'new'}"
  1. Webhook::ApiClient#logger_error calls 'Rails.logger' 3 times Locations: 0 1 2
Rails.logger.error "Webhook: #{@webhook.inspect}"
  1. Webhook::ApiClient#logger_error calls 'Rails.logger' 3 times Locations: 0 1 2
Rails.logger.error "Request: #{response.inspect}"
  1. Webhook::ApiClient#logger_error calls 'Rails.logger' 3 times Locations: 0 1 2
end end