Sha256: 35e439c0ba8f59bbeba50bf3bfd08d7c5beb323f7961060484e432b78a51ab7e

Contents?: true

Size: 1001 Bytes

Versions: 122

Compression:

Stored size: 1001 Bytes

Contents

module Tickethub
  class Response
    attr_reader :response, :body, :headers, :parser

    def initialize(response, parser = nil)
      @response = response
      @body     = response.body
      @headers  = Headers.new(response.to_hash)
      @format   = Formats.for(headers.content_type)
      @parser ||= @format && @format.new
    end

    def as_json
      decoded
    end

    def to_json(*)
      as_json.to_json
    end

    def code
      response.code.to_i
    end

    alias_method :status, :code

    def decoded
      @decoded ||= parser ? parser.decode(body) : body
    end

    def respond_to?(name)
      super || decoded.respond_to?(name) || response.respond_to?(name)
    end

    protected

    def method_missing(name, *args, &block)
      if decoded.respond_to?(name)
        decoded.send(name, *args, &block)
      elsif response.respond_to?(name)
        response.send(name, *args, &block)
      else
        super
      end
    end
  end
end

require_relative 'response/headers'

Version data entries

122 entries across 122 versions & 1 rubygems

Version Path
tickethub-0.3.79 lib/tickethub/response.rb
tickethub-0.3.78 lib/tickethub/response.rb
tickethub-0.3.77 lib/tickethub/response.rb
tickethub-0.3.76 lib/tickethub/response.rb
tickethub-0.3.75 lib/tickethub/response.rb
tickethub-0.3.74 lib/tickethub/response.rb
tickethub-0.3.73 lib/tickethub/response.rb
tickethub-0.3.72 lib/tickethub/response.rb
tickethub-0.3.71 lib/tickethub/response.rb
tickethub-0.3.70 lib/tickethub/response.rb
tickethub-0.3.68 lib/tickethub/response.rb
tickethub-0.3.67 lib/tickethub/response.rb
tickethub-0.3.66 lib/tickethub/response.rb
tickethub-0.3.65 lib/tickethub/response.rb
tickethub-0.3.64 lib/tickethub/response.rb
tickethub-0.3.63 lib/tickethub/response.rb
tickethub-0.3.62 lib/tickethub/response.rb
tickethub-0.3.61 lib/tickethub/response.rb
tickethub-0.3.60 lib/tickethub/response.rb
tickethub-0.3.59 lib/tickethub/response.rb