Class: Apologist::Agent::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/Apologist/agent/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/Apologist/agent/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#pause_agent(request_options: {}, **_params) ⇒ Apologist::Agent::Types::PauseAgentResponse

Pauses the agent globally and fans out pause transition messages to open conversations. Requires an API key.

Examples:

client.agent.pause_agent

Parameters:

  • request_options (Hash) (defaults to: {})
  • _params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/Apologist/agent/client.rb', line 27

def pause_agent(request_options: {}, **_params)
  request = Apologist::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "pause",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Apologist::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Apologist::Agent::Types::PauseAgentResponse.load(response.body)
  else
    error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#resume_agent(request_options: {}, **_params) ⇒ Apologist::Agent::Types::ResumeAgentResponse

Resumes the agent globally and fans out resume transition messages to open conversations. Requires an API key.

Examples:

client.agent.resume_agent

Parameters:

  • request_options (Hash) (defaults to: {})
  • _params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/Apologist/agent/client.rb', line 62

def resume_agent(request_options: {}, **_params)
  request = Apologist::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "resume",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Apologist::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Apologist::Agent::Types::ResumeAgentResponse.load(response.body)
  else
    error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end