Sha256: 5c121f582a3dc45c621877fe7ffe360f871df683e1e3b98ba863e8f447a89c39

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

module Fauna
  # The result of a request. Provided to observers and included within errors.
  class RequestResult
    # The Client.
    attr_reader :client
    # HTTP method. Either +:get+, +:post+, +:put+, +:patch+, or +:delete+
    attr_reader :method
    # Path that was queried. Relative to client's domain.
    attr_reader :path
    # URL query. +nil+ except for +GET+ requests.
    attr_reader :query
    # Request data.
    attr_reader :request_content
    # String value returned by the server.
    attr_reader :response_raw
    ##
    # Parsed value returned by the server.
    # Includes "resource" wrapper hash, or may be an "errors" hash instead.
    # In the case of a JSON parse error, this will be nil.
    attr_reader :response_content
    # HTTP status code.
    attr_reader :status_code
    # A hash of headers.
    attr_reader :response_headers
    # Time the request started.
    attr_reader :start_time
    # Time the response was received.
    attr_reader :end_time

    def initialize(
        client,
        method, path, query, request_content,
        response_raw, response_content, status_code, response_headers,
        start_time, end_time) # :nodoc:
      @client = client
      @method = method
      @path = path
      @query = query
      @request_content = request_content
      @response_raw = response_raw
      @response_content = response_content
      @status_code = status_code
      @response_headers = response_headers
      @start_time = start_time
      @end_time = end_time
    end

    # Real time spent performing the request.
    def time_taken
      end_time - start_time
    end

    # Credentials used by the client.
    def auth
      client.credentials
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
yax-fauna-3.0.1 lib/fauna/request_result.rb
fauna-3.0.0 lib/fauna/request_result.rb
fauna-2.4.0 lib/fauna/request_result.rb
fauna-2.3.0 lib/fauna/request_result.rb
fauna-2.2.0 lib/fauna/request_result.rb
fauna-2.1.2 lib/fauna/request_result.rb
fauna-2.1.1 lib/fauna/request_result.rb
fauna-2.1.0 lib/fauna/request_result.rb
fauna-2.0.0 lib/fauna/request_result.rb