Sha256: 181967a76e320f450348dd394080e47fae9b5d151a6f31448cb7e6607785bf7a

Contents?: true

Size: 1.11 KB

Versions: 12

Compression:

Stored size: 1.11 KB

Contents

require 'net/http'
require 'addressable/uri'

module Unimatrix::Authorization
  class Request < Unimatrix::Request

    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

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

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

      response
    end

    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 ) )
      rescue Timeout::Error
        response = nil
      end

      response
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
unimatrix-2.6.1 lib/unimatrix/authorization/request.rb
unimatrix-2.6.0 lib/unimatrix/authorization/request.rb
unimatrix-2.5.5 lib/unimatrix/authorization/request.rb
unimatrix-2.5.4 lib/unimatrix/authorization/request.rb
unimatrix-2.5.3 lib/unimatrix/authorization/request.rb
unimatrix-2.5.2 lib/unimatrix/authorization/request.rb
unimatrix-2.5.1 lib/unimatrix/authorization/request.rb
unimatrix-2.5.0 lib/unimatrix/authorization/request.rb
unimatrix-2.4.2 lib/unimatrix/authorization/request.rb
unimatrix-2.3.1 lib/unimatrix/authorization/request.rb
unimatrix-2.2.1 lib/unimatrix/authorization/request.rb
unimatrix-2.1.1 lib/unimatrix/authorization/request.rb