Module: WolfCore::Integrations::ClientApiOperations

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

Instance Method Summary collapse

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, #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



35
36
37
38
39
40
41
42
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 35

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:) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 25

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

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



17
18
19
20
21
22
23
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 17

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:) ⇒ Object



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

def fetch_client!(wolf_token:, client_id:, tenant:, wolf_platform_url:, error_message:)
  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
  )
  response_body = response.body
  response_body.dig("data", "table", "company")
end

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



54
55
56
57
58
59
60
61
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 54

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:) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/wolf_core/application/integrations/client_api_operations.rb', line 44

def update_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:, client_id:)
  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
  )
end