Class: CopyAi::Connection
- Inherits:
-
Object
- Object
- CopyAi::Connection
- 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
-
#debug_output ⇒ Object
Returns the value of attribute debug_output.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#write_timeout ⇒ Object
Returns the value of attribute write_timeout.
Instance Method Summary collapse
-
#initialize(open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, debug_output: DEFAULT_DEBUG_OUTPUT) ⇒ Connection
constructor
A new instance of Connection.
- #perform(request:) ⇒ Object
Constructor Details
permalink #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.
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
permalink #debug_output ⇒ Object
Returns the value of attribute debug_output.
23 24 25 |
# File 'lib/copy_ai/connection.rb', line 23 def debug_output @debug_output end |
permalink #open_timeout ⇒ Object
Returns the value of attribute open_timeout.
23 24 25 |
# File 'lib/copy_ai/connection.rb', line 23 def open_timeout @open_timeout end |
permalink #read_timeout ⇒ Object
Returns the value of attribute read_timeout.
23 24 25 |
# File 'lib/copy_ai/connection.rb', line 23 def read_timeout @read_timeout end |
permalink #write_timeout ⇒ Object
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
permalink #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 |