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
# 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 )

  @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



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/unimatrix/authorization/request.rb', line 17

def get( path, parameters = {} )
  response = nil

  begin
    response = Response.new(
      @http.get( compose_request_path( path, parameters ) ),
      path
    )
  rescue Timeout::Error
    response = nil
  end

  response
end

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/unimatrix/authorization/request.rb', line 32

def post( path, parameters = {}, body = {} )
  response = nil

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

    response = Response.new( @http.request( request ), path )
  rescue Timeout::Error
    response = nil
  end

  response
end