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.100 lib/tickethub/response.rb
tickethub-0.3.99 lib/tickethub/response.rb
tickethub-0.3.98 lib/tickethub/response.rb
tickethub-0.3.97 lib/tickethub/response.rb
tickethub-0.3.96 lib/tickethub/response.rb
tickethub-0.3.95 lib/tickethub/response.rb
tickethub-0.3.94 lib/tickethub/response.rb
tickethub-0.3.93 lib/tickethub/response.rb
tickethub-0.3.92 lib/tickethub/response.rb
tickethub-0.3.91 lib/tickethub/response.rb
tickethub-0.3.90 lib/tickethub/response.rb
tickethub-0.3.89 lib/tickethub/response.rb
tickethub-0.3.88 lib/tickethub/response.rb
tickethub-0.3.87 lib/tickethub/response.rb
tickethub-0.3.86 lib/tickethub/response.rb
tickethub-0.3.85 lib/tickethub/response.rb
tickethub-0.3.84 lib/tickethub/response.rb
tickethub-0.3.82 lib/tickethub/response.rb
tickethub-0.3.81 lib/tickethub/response.rb
tickethub-0.3.80 lib/tickethub/response.rb