Sha256: 0aa2fb271cd0665f501908625eb9d8b6d2ec220282f4605c2aae03af34f61dac

Contents?: true

Size: 841 Bytes

Versions: 8

Compression:

Stored size: 841 Bytes

Contents

require 'json-schema'

module Fitting
  class Request
    def initialize(env_request, tomogram)
      @method = env_request.request_method
      @path = env_request.env['PATH_INFO']
      @body = env_request.env['action_dispatch.request.request_parameters']
      @schema = tomogram.find_request(method: @method, path: @path)
      @fully_validate = JSON::Validator.fully_validate(@schema['request'], @body) if @schema
      @valid = false
      @valid = true if @fully_validate == []
      self
    end

    def route
      "#{@schema['method']}\t#{@schema['path']}"
    end

    def real_method_with_path
      "#{@method}\t#{@path}"
    end

    def schemas_of_possible_responses(status:)
      if @schema
        @schema.find_responses(status: status).map do |response|
          response['body']
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fitting-1.6.1 lib/fitting/request.rb
fitting-1.6.0 lib/fitting/request.rb
fitting-1.5.0 lib/fitting/request.rb
fitting-1.4.0 lib/fitting/request.rb
fitting-1.3.1 lib/fitting/request.rb
fitting-1.3.0 lib/fitting/request.rb
fitting-1.2.0 lib/fitting/request.rb
fitting-1.1.0 lib/fitting/request.rb