Class: X::Connection
- Inherits:
 - 
      Object
      
        
- Object
 - X::Connection
 
 
- Extended by:
 - Forwardable
 
- Defined in:
 - lib/x/connection.rb
 
Constant Summary collapse
- DEFAULT_HOST =
 "api.twitter.com".freeze
- DEFAULT_PORT =
 443- 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.
 - 
  
    
      #proxy_uri  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute proxy_uri.
 - 
  
    
      #proxy_url  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute proxy_url.
 - 
  
    
      #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, proxy_url: nil)  ⇒ Connection 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Connection.
 - #perform(request:) ⇒ Object
 
Constructor Details
#initialize(open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, debug_output: DEFAULT_DEBUG_OUTPUT, proxy_url: nil) ⇒ Connection
Returns a new instance of Connection.
      33 34 35 36 37 38 39 40  | 
    
      # File 'lib/x/connection.rb', line 33 def initialize(open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, write_timeout: DEFAULT_WRITE_TIMEOUT, debug_output: DEFAULT_DEBUG_OUTPUT, proxy_url: nil) @open_timeout = open_timeout @read_timeout = read_timeout @write_timeout = write_timeout @debug_output = debug_output self.proxy_url = proxy_url unless proxy_url.nil? end  | 
  
Instance Attribute Details
#debug_output ⇒ Object
Returns the value of attribute debug_output.
      25 26 27  | 
    
      # File 'lib/x/connection.rb', line 25 def debug_output @debug_output end  | 
  
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
      25 26 27  | 
    
      # File 'lib/x/connection.rb', line 25 def open_timeout @open_timeout end  | 
  
#proxy_uri ⇒ Object (readonly)
Returns the value of attribute proxy_uri.
      26 27 28  | 
    
      # File 'lib/x/connection.rb', line 26 def proxy_uri @proxy_uri end  | 
  
#proxy_url ⇒ Object
Returns the value of attribute proxy_url.
      26 27 28  | 
    
      # File 'lib/x/connection.rb', line 26 def proxy_url @proxy_url end  | 
  
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
      25 26 27  | 
    
      # File 'lib/x/connection.rb', line 25 def read_timeout @read_timeout end  | 
  
#write_timeout ⇒ Object
Returns the value of attribute write_timeout.
      25 26 27  | 
    
      # File 'lib/x/connection.rb', line 25 def write_timeout @write_timeout end  | 
  
Instance Method Details
#perform(request:) ⇒ Object
      42 43 44 45 46 47 48 49 50  | 
    
      # File 'lib/x/connection.rb', line 42 def perform(request:) host = request.uri.host || DEFAULT_HOST port = request.uri.port || DEFAULT_PORT http_client = build_http_client(host, port) http_client.use_ssl = request.uri.scheme.eql?("https") http_client.request(request) rescue *NETWORK_ERRORS => e raise NetworkError, "Network error: #{e}" end  |