Class: CopyAi::Connection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/copy_ai/connection.rb

Constant Summary collapse

DEFAULT_OPEN_TIMEOUT =

seconds

60
DEFAULT_READ_TIMEOUT =

seconds

60
DEFAULT_WRITE_TIMEOUT =

seconds

60
DEFAULT_DEBUG_OUTPUT =
File.open(File::NULL, "w")
NETWORK_ERRORS =
[
  Errno::ECONNREFUSED,
  Errno::ECONNRESET,
  Net::OpenTimeout,
  Net::ReadTimeout,
  OpenSSL::SSL::SSLError
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, debug_output: DEFAULT_DEBUG_OUTPUT) ⇒ Connection

Returns a new instance of Connection.

[View source]

25
26
27
28
29
30
31
# File 'lib/copy_ai/connection.rb', line 25

def initialize(open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT,
  write_timeout: DEFAULT_WRITE_TIMEOUT, debug_output: DEFAULT_DEBUG_OUTPUT)
  @open_timeout = open_timeout
  @read_timeout = read_timeout
  @write_timeout = write_timeout
  @debug_output = debug_output
end

Instance Attribute Details

#debug_outputObject

Returns the value of attribute debug_output.


23
24
25
# File 'lib/copy_ai/connection.rb', line 23

def debug_output
  @debug_output
end

#open_timeoutObject

Returns the value of attribute open_timeout.


23
24
25
# File 'lib/copy_ai/connection.rb', line 23

def open_timeout
  @open_timeout
end

#read_timeoutObject

Returns the value of attribute read_timeout.


23
24
25
# File 'lib/copy_ai/connection.rb', line 23

def read_timeout
  @read_timeout
end

#write_timeoutObject

Returns the value of attribute write_timeout.


23
24
25
# File 'lib/copy_ai/connection.rb', line 23

def write_timeout
  @write_timeout
end

Instance Method Details

#perform(request:) ⇒ Object

[View source]

33
34
35
36
37
38
39
# File 'lib/copy_ai/connection.rb', line 33

def perform(request:)
  http_client = build_http_client(request.uri.host, request.uri.port)
  http_client.use_ssl = true
  http_client.request(request)
rescue *NETWORK_ERRORS => e
  raise NetworkError, "Network error: #{e}"
end