Updated

app/use_cases/accounts/apps/evolution_apis/webhooks / process_webhook.rb

B
35 lines of codes
3 methods
25.4 complexity/method
14 churn
76.25 complexity
0 duplications
class Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook has no descriptive comment
def self.call(webhook)
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook::call has a flog score of 50
  2. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call has approx 7 statements
evolution_api = Apps::EvolutionApi.find_by(instance: webhook['instance']) if webhook['event'] == 'qrcode.updated'
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['event']' 3 times Locations: 0 1 2
Accounts::Apps::EvolutionApis::Webhooks::Events::QrcodeConnectRefresh.call( evolution_api, webhook['data']['qrcode']['base64']
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']' 5 times Locations: 0 1 2 3 4
) elsif webhook['event'] == 'connection.update'
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['event']' 3 times Locations: 0 1 2
if connection_created?(webhook) Accounts::Apps::EvolutionApis::Webhooks::Events::ConnectionCreated.call(evolution_api, webhook['sender'].gsub(/\D/, '')) elsif connection_deleted?(webhook) Accounts::Apps::EvolutionApis::Webhooks::Events::ConnectionDeleted.call(evolution_api) end elsif webhook['event'] == 'messages.upsert'
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['event']' 3 times Locations: 0 1 2
if webhook['data']['messageType'] == 'extendedTextMessage'
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']' 5 times Locations: 0 1 2 3 4
  2. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']['messageType']' 2 times Locations: 0 1
Accounts::Apps::EvolutionApis::Webhooks::Events::ImportMessage.call(evolution_api, webhook, webhook['data']['message']['extendedTextMessage']['text'])
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']' 5 times Locations: 0 1 2 3 4
  2. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']['message']' 2 times Locations: 0 1
elsif webhook['data']['messageType'] == 'conversation'
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']' 5 times Locations: 0 1 2 3 4
  2. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']['messageType']' 2 times Locations: 0 1
Accounts::Apps::EvolutionApis::Webhooks::Events::ImportMessage.call(evolution_api, webhook, webhook['data']['message']['conversation'])
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']' 5 times Locations: 0 1 2 3 4
  2. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.call calls 'webhook['data']['message']' 2 times Locations: 0 1
end end { ok: evolution_api } end def self.connection_created?(webhook) webhook['data']['statusReason'].to_i == 200 && webhook['data']['state'] == 'open'
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.connection_created? calls 'webhook['data']' 2 times
end def self.connection_deleted?(webhook) (webhook['data']['statusReason'].to_i == 401 || webhook['data']['statusReason'].to_i == 428) && webhook['data']['state'] == 'close'
  1. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.connection_deleted? calls 'webhook['data']' 3 times
  2. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.connection_deleted? calls 'webhook['data']['statusReason']' 2 times
  3. Accounts::Apps::EvolutionApis::Webhooks::ProcessWebhook#self.connection_deleted? calls 'webhook['data']['statusReason'].to_i' 2 times
end end