Module: WolfCore::Integrations::ClientApiOperations

Includes:
HttpOperations, CustomValueApiOperations
Defined in:
lib/wolf_core/application/integrations/client_api_operations.rb

Instance Method Summary collapse

Methods included from CustomValueApiOperations

#create_custom_value, #create_custom_value!, #fetch_custom_value, #fetch_custom_value!, #fetch_custom_values, #fetch_custom_values!, #update_custom_value, #update_custom_value!, #upsert_custom_value, #upsert_custom_value!

Methods included from HttpOperations

#async_http_get, #async_http_patch, #async_http_post, #async_http_put, #http_get, #http_patch, #http_post, #http_put, #parse_http_response, #parsed_http_get, #parsed_http_patch, #parsed_http_post, #parsed_http_put, #response_success?, #safe_http_get, #safe_http_patch, #safe_http_post, #safe_http_put, #validate_http_response

Methods included from LoggingUtils

#log_object

Methods included from AsyncUtils

#run_async

Methods included from ExceptionOperations

#raise_service_error

Instance Method Details

#create_client(wolf_token:, client:, tenant:, wolf_platform_url:) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 40

def create_client(wolf_token:, client:, tenant:, wolf_platform_url:)
  parsed_http_post(
    headers: { "Authorization" => "Bearer #{wolf_token}" },
    query: { tenant: tenant },
    url: "#{wolf_platform_url}/api/v2/companies",
    body: client
  )
end

#create_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:, error_data: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 28

def create_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:, error_data: nil)
  error_data ||= {}
  safe_http_post(
    headers: { "Authorization" => "Bearer #{wolf_token}" },
    query: { tenant: tenant },
    url: "#{wolf_platform_url}/api/v2/companies",
    body: client,
    error_message: error_message,
    error_data: { client: client }.merge(error_data)
  )
end

#fetch_client(wolf_token:, client_id:, tenant:, wolf_platform_url:) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 20

def fetch_client(wolf_token:, client_id:, tenant:, wolf_platform_url:)
  parsed_http_get(
    headers: { "Authorization" => "Bearer #{wolf_token}" },
    url: "#{wolf_platform_url}/api/v2/companies/#{client_id}",
    query: { tenant: tenant }
  )
end

#fetch_client!(wolf_token:, client_id:, tenant:, wolf_platform_url:, error_message:, error_data: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 7

def fetch_client!(wolf_token:, client_id:, tenant:, wolf_platform_url:, error_message:, error_data: nil)
  error_data ||= {}
  response = safe_http_get(
    headers: { "Authorization" => "Bearer #{wolf_token}" },
    url: "#{wolf_platform_url}/api/v2/companies/#{client_id}",
    query: { tenant: tenant },
    error_message: error_message,
    error_data: { client_id: client_id }.merge(error_data)
  )
  response_body = response.body
  response_body.dig("data", "table", "company")
end

#fetch_client_custom_value!(wolf_token:, tenant:, wolf_platform_url:, client_id:, id: nil, custom_requirement_id: nil, query: nil, error_data: nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 70

def fetch_client_custom_value!(wolf_token:, tenant:, wolf_platform_url:, client_id:, id: nil, custom_requirement_id: nil, query: nil, error_data: nil)
  id || custom_requirement_id || raise_service_error({ message: "custom_requirement_id or id must be provided" })
  query = {
    user_category: 'Company',
    user_code: client_id,
    id: id,
    custom_requirement_friendly_id: custom_requirement_id
  }.compact.merge(query || {})
  fetch_custom_values!(
    wolf_token: wolf_token,
    tenant: tenant,
    wolf_platform_url: wolf_platform_url,
    error_message: "Unable to fetch custom values for #{client_id}",
    error_data: query.merge(error_data || {}),
    query: query
  ).first
end

#update_client(wolf_token:, client:, tenant:, wolf_platform_url:, client_id:) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 61

def update_client(wolf_token:, client:, tenant:, wolf_platform_url:, client_id:)
  parsed_http_put(
    headers: { "Authorization" => "Bearer #{wolf_token}" },
    query: { tenant: tenant },
    url: "#{wolf_platform_url}/api/v2/companies/#{client_id}",
    body: client
  )
end

#update_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:, client_id:, error_data: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 49

def update_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:, client_id:, error_data: nil)
  error_data ||= {}
  safe_http_put(
    headers: { "Authorization" => "Bearer #{wolf_token}" },
    query: { tenant: tenant },
    url: "#{wolf_platform_url}/api/v2/companies/#{client_id}",
    body: client,
    error_message: error_message,
    error_data: { client_id: client_id, client: client }.merge(error_data)
  )
end