11# frozen_string_literal: true
22
3- module TaskService
4- class CheckExternal < ServiceBase
3+ class TaskService
4+ class CheckExternal < TaskService
55 def initialize ( uuid :, account_link :)
66 super ( )
77 @uuid = uuid
88 @account_link = account_link
99 end
1010
1111 def execute
12- response = connection . post do |req |
13- req . headers [ 'Content-Type' ] = 'application/json'
14- req . headers [ 'Authorization' ] = authorization_header
15- req . body = { uuid : @uuid } . to_json
16- end
12+ body = { uuid : @uuid } . to_json
13+ response = self . class . connection . post ( @account_link . check_uuid_url ) { |request | request_parameters ( request , body ) }
1714 response_hash = JSON . parse ( response . body , symbolize_names : true ) . slice ( :uuid_found , :update_right )
1815
1916 { error : false , message : message ( response_hash ) } . merge ( response_hash )
@@ -23,8 +20,12 @@ def execute
2320
2421 private
2522
26- def authorization_header
27- "Bearer #{ @account_link . api_key } "
23+ def request_parameters ( request , body )
24+ request . tap do |req |
25+ req . headers [ 'Content-Type' ] = 'application/json'
26+ req . headers [ 'Authorization' ] = "Bearer #{ @account_link . api_key } "
27+ req . body = body
28+ end
2829 end
2930
3031 def message ( response_hash )
@@ -38,14 +39,5 @@ def message(response_hash)
3839 I18n . t ( 'tasks.task_service.check_external.no_task' )
3940 end
4041 end
41-
42- def connection
43- Faraday . new ( url : @account_link . check_uuid_url ) do |faraday |
44- faraday . options [ :open_timeout ] = 5
45- faraday . options [ :timeout ] = 5
46-
47- faraday . adapter Faraday . default_adapter
48- end
49- end
5042 end
5143end
0 commit comments