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.37 lib/tickethub/response.rb
tickethub-0.3.36 lib/tickethub/response.rb
tickethub-0.3.35 lib/tickethub/response.rb
tickethub-0.3.34 lib/tickethub/response.rb
tickethub-0.3.33 lib/tickethub/response.rb
tickethub-0.3.32 lib/tickethub/response.rb
tickethub-0.3.31 lib/tickethub/response.rb
tickethub-0.3.30 lib/tickethub/response.rb
tickethub-0.3.29 lib/tickethub/response.rb
tickethub-0.3.28 lib/tickethub/response.rb
tickethub-0.3.27 lib/tickethub/response.rb
tickethub-0.3.26 lib/tickethub/response.rb
tickethub-0.3.25 lib/tickethub/response.rb
tickethub-0.3.24 lib/tickethub/response.rb
tickethub-0.3.23 lib/tickethub/response.rb
tickethub-0.3.22 lib/tickethub/response.rb
tickethub-0.3.21 lib/tickethub/response.rb
tickethub-0.3.20 lib/tickethub/response.rb
tickethub-0.3.18 lib/tickethub/response.rb
tickethub-0.3.17 lib/tickethub/response.rb