Class: Unimatrix::Authorization::Request

Inherits:
Request
  • Object
show all
Defined in:
lib/unimatrix/authorization/request.rb

Instance Method Summary collapse

Methods inherited from Request

#destroy

Constructor Details

#initialize(default_parameters = {}) ⇒ Request

Returns a new instance of Request.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/unimatrix/authorization/request.rb', line 7

def initialize( default_parameters = {} )
  uri   = URI( Unimatrix.configuration.authorization_url )
  @http = Net::HTTP.new( uri.host, uri.port )
  
  timeout_limit = ( ENV[ 'TIMEOUT_LIMIT' ] || 60 ).to_i
  
  @http.open_timeout = timeout_limit
  @http.read_timeout = timeout_limit

  @http.use_ssl = ( uri.scheme == 'https' )
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  @default_parameters = default_parameters.stringify_keys
end

Instance Method Details

#get(path, parameters = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/unimatrix/authorization/request.rb', line 22

def get( path, parameters = {} )
  attempt_request do
    Response.new(
      @http.get( compose_request_path( path, parameters ) ),
      path
    )
  end
end

#post(path, parameters = {}, body = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/unimatrix/authorization/request.rb', line 31

def post( path, parameters = {}, body = {} )
  attempt_request do
    request = Net::HTTP::Post.new(
      compose_request_path( path, parameters ),
      { 'Content-Type' =>'application/json' }
    )
    request.body = body.to_json

    Response.new( @http.request( request ), path )
  end
end