Updated

app/models/apps/chatwoot / api_client.rb

A
49 lines of codes
4 methods
8.0 complexity/method
4 churn
32.02 complexity
0 duplications
# frozen_string_literal: true class Apps::Chatwoot::ApiClient
  1. Apps::Chatwoot::ApiClient has no descriptive comment
include Apps::Chatwoot::ApiClient::UserProfile def initialize(chatwoot) @chatwoot = chatwoot @request_headers = chatwoot.request_headers @connection = create_connection end def create_connection
  1. Apps::Chatwoot::ApiClient#create_connection has approx 6 statements
retry_options = { max: 5, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2, exceptions: [ Faraday::ConnectionFailed, Faraday::TimeoutError, 'Timeout::Error' ] } Faraday.new(@chatwoot.chatwoot_endpoint_url) do |faraday| faraday.options.open_timeout = 5
  1. Apps::Chatwoot::ApiClient#create_connection calls 'faraday.options' 2 times Locations: 0 1
  2. Apps::Chatwoot::ApiClient#create_connection refers to 'faraday' more than self (maybe move it to another class?) Locations: 0 1 2 3
faraday.options.timeout = 10
  1. Apps::Chatwoot::ApiClient#create_connection calls 'faraday.options' 2 times Locations: 0 1
  2. Apps::Chatwoot::ApiClient#create_connection refers to 'faraday' more than self (maybe move it to another class?) Locations: 0 1 2 3
faraday.headers = { 'api_access_token': @chatwoot.chatwoot_user_token.to_s, 'Content-Type': 'application/json' }
  1. Apps::Chatwoot::ApiClient#create_connection refers to 'faraday' more than self (maybe move it to another class?) Locations: 0 1 2 3
faraday.request :retry, retry_options
  1. Apps::Chatwoot::ApiClient#create_connection refers to 'faraday' more than self (maybe move it to another class?) Locations: 0 1 2 3
end end def get_request(path, params = {}) response = @connection.get(path, params) if response.success?
  1. Apps::Chatwoot::ApiClient#get_request refers to 'response' more than self (maybe move it to another class?) Locations: 0 1 2
{ ok: JSON.parse(response.body), request: response }
  1. Apps::Chatwoot::ApiClient#get_request calls 'response.body' 2 times Locations: 0 1
  2. Apps::Chatwoot::ApiClient#get_request refers to 'response' more than self (maybe move it to another class?) Locations: 0 1 2
else logger_error('Failed get_request', response) { error: response.body, request: response }
  1. Apps::Chatwoot::ApiClient#get_request calls 'response.body' 2 times Locations: 0 1
  2. Apps::Chatwoot::ApiClient#get_request refers to 'response' more than self (maybe move it to another class?) Locations: 0 1 2
end end def logger_error(message, request) Rails.logger.error "Chatwoot Api Client error #{message} - Chatwoot #{@chatwoot.id}"
  1. Apps::Chatwoot::ApiClient#logger_error calls 'Rails.logger' 3 times Locations: 0 1 2
Rails.logger.error "Chatwoot: #{@chatwoot.inspect}"
  1. Apps::Chatwoot::ApiClient#logger_error calls 'Rails.logger' 3 times Locations: 0 1 2
Rails.logger.error "Request: #{request.inspect}"
  1. Apps::Chatwoot::ApiClient#logger_error calls 'Rails.logger' 3 times Locations: 0 1 2
end end