Sha256: d8069edf153a57b6a9964511c6a1301eeafcf82fa749dc2398fb7fcf921b7501

Contents?: true

Size: 1.51 KB

Versions: 6

Compression:

Stored size: 1.51 KB

Contents

# encoding: utf-8
module Apiary
  module Okapi
    class Resource
      attr_accessor :uri, :method, :params, :expanded_uri,  :headers, :body, :response, :validation_result

      def initialize(uri, method, params, expanded_uri = nil,  headers = nil, body = nil, response = nil, validation_result = nil)
        #p uri, method, params
        @uri          = uri
        @method       = method
        @params       = params
        @expanded_uri = expanded_uri
        @headers      = headers
        @body         = body
        @response     = response
        @validation_result = validation_result
      end
    end

    class Response
      attr_accessor :status,  :headers, :body, :error, :validation_result

      def initialize(status = nil, headers = nil, body = nil, error = nil, validation_result = nil)
        @headers      = headers
        @body         = body
        @status       = status
        @error        = error
        @validation_result = validation_result
      end
    end

    class ValidationResult
      attr_accessor :status, :error, :schema_res , :body_pass, :body_diff, :header_pass, :header_diff

      def status
        @status ||= get_status
      end

      def get_status
        return true if not @error and @header_pass and ((schema and  schema_pass) or (not schema and @body_pass))
        return false
      end

      def schema
        !(@schema_res == false)
      end

      def schema_pass
        not schema or schema and @schema_res and not @schema_res['errors']
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
okapi-0.1.0 lib/okapi/resources.rb
okapi-0.0.9 lib/okapi/resources.rb
okapi-0.0.8 lib/okapi/resources.rb
okapi-0.0.7 lib/okapi/resources.rb
okapi-0.0.6 lib/okapi/resources.rb
okapi-0.0.5 lib/okapi/resources.rb