Class: Unimatrix::Request

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

Direct Known Subclasses

Authorization::Request

Instance Method Summary collapse

Constructor Details

#initialize(default_parameters = {}) ⇒ Request

Returns a new instance of Request.



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

def initialize( default_parameters = {} )
  uri   = URI( Unimatrix.configuration.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

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



23
24
25
26
27
28
29
30
31
32
# File 'lib/unimatrix/request.rb', line 23

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

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

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



34
35
36
37
38
39
40
# File 'lib/unimatrix/request.rb', line 34

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

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



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/unimatrix/request.rb', line 42

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