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.2.5 lib/tickethub/response.rb
tickethub-0.2.4 lib/tickethub/response.rb
tickethub-0.2.3 lib/tickethub/response.rb
tickethub-0.2.2 lib/tickethub/response.rb
tickethub-0.2.1 lib/tickethub/response.rb
tickethub-0.2.0 lib/tickethub/response.rb
tickethub-0.1.4 lib/tickethub/response.rb
tickethub-0.1.3 lib/tickethub/response.rb
tickethub-0.1.2 lib/tickethub/response.rb
tickethub-0.0.14 lib/tickethub/response.rb
tickethub-0.0.12 lib/tickethub/response.rb
tickethub-0.0.11 lib/tickethub/response.rb
tickethub-0.0.10 lib/tickethub/response.rb
tickethub-0.0.9 lib/tickethub/response.rb
tickethub-0.0.8 lib/tickethub/response.rb
tickethub-0.0.7 lib/tickethub/response.rb
tickethub-0.0.6 lib/tickethub/response.rb
tickethub-0.0.5 lib/tickethub/response.rb
tickethub-0.0.4 lib/tickethub/response.rb
tickethub-0.0.3 lib/tickethub/response.rb