Sha256: 75d5a40ecd7305a8bf62a1c0c09fe9ae31e2de835604331e76c5499c63cb7b57

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

Contents

module Restfully
  module HTTP
    # Container for an HTTP Response. Has <tt>status</tt>, <tt>headers</tt> and <tt>body</tt> properties.
    class Response
      include Headers, Restfully::Parsing
      attr_reader :status, :headers
      
      # <tt>body</tt>:: may be a string (that will be parsed when calling the #body function), or an object (that will be returned as is when calling the #body function)
      def initialize(status, headers, body)
        @status = status.to_i
        @headers = sanitize_http_headers(headers)
        @body = body
      end
      
      def body
        if @body.kind_of?(String)
          if @body.empty?
            nil
          else
            @unserialized_body ||= unserialize(@body, :content_type => @headers['Content-Type'])
          end
        else
          @body
        end
      end
      
      def raw_body
        if @body.kind_of?(String)
          @body
        else
          @serialized_body ||= serialize(@body, :content_type => @headers['Content-Type']) unless @body.nil?
        end
      end
      
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
restfully-0.6.3 lib/restfully/http/response.rb
restfully-0.6.2 lib/restfully/http/response.rb
restfully-0.6.1 lib/restfully/http/response.rb
restfully-0.6.0 lib/restfully/http/response.rb
restfully-0.5.10 lib/restfully/http/response.rb
restfully-0.5.9 lib/restfully/http/response.rb
restfully-0.5.8 lib/restfully/http/response.rb
restfully-0.5.7 lib/restfully/http/response.rb
restfully-0.5.6 lib/restfully/http/response.rb
restfully-0.5.5 lib/restfully/http/response.rb
restfully-0.5.4 lib/restfully/http/response.rb
restfully-0.5.3 lib/restfully/http/response.rb
restfully-0.5.2 lib/restfully/http/response.rb
restfully-0.5.1 lib/restfully/http/response.rb
restfully-0.5.0 lib/restfully/http/response.rb
restfully-0.4.1 lib/restfully/http/response.rb
restfully-0.4.0 lib/restfully/http/response.rb