Class: Castle::API::Session

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/castle/api/session.rb

Overview

this class keeps http config object and provides start/finish methods for persistent connection usage when there is a need of sending multiple requests at once

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



15
16
17
# File 'lib/castle/api/session.rb', line 15

def initialize
  reset
end

Instance Attribute Details

#httpObject

Returns the value of attribute http.



13
14
15
# File 'lib/castle/api/session.rb', line 13

def http
  @http
end

Class Method Details

.getNet::HTTP

Returns:

  • (Net::HTTP)


33
34
35
# File 'lib/castle/api/session.rb', line 33

def get
  instance.http
end

Instance Method Details

#resetObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/castle/api/session.rb', line 19

def reset
  @http = Net::HTTP.new(Castle.config.host, Castle.config.port)
  @http.read_timeout = Castle.config.request_timeout / 1000.0

  if Castle.config.port == 443
    @http.use_ssl = true
    @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  end

  @http
end