Sha256: e949b02033df141cc573a43a18cbfebb9cfd952b8f7061b384441e6f43e50bd9

Contents?: true

Size: 727 Bytes

Versions: 1

Compression:

Stored size: 727 Bytes

Contents

class FleetAPI::Response
  attr_reader :headers, :status, :body, :request

  def initialize(options={})
    @status  = options[:status]
    @headers = options[:headers]
    @body    = options[:body]
    @request = options[:request]
  end

  def successful?
    self.status.to_s =~ /(2\d\d|304)/
  end

  def raise!
    if !successful?
      raise((ClientError).new(self))
    else self
    end
  end

  class ClientError < StandardError
    attr_reader :response

    def initialize(response)
      @response = response
      super({
          :body    => response.body,
          :headers => response.headers,
          :request => response.request,
          :status  => response.status,
        }.inspect)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coreos-fleet-api-0.1.0 lib/fleet_api/response.rb