Sha256: 6802c968fcd689ac5e18cccd8066fcd7f397d1c6dbc91489361bddbc72c77ef6

Contents?: true

Size: 1.05 KB

Versions: 16

Compression:

Stored size: 1.05 KB

Contents

class Shelly::Client
  class APIException < Exception
    attr_reader :status_code, :body, :request_id

    def initialize(body = {}, status_code = nil, request_id = nil)
      @status_code = status_code
      @body = body
      @request_id = request_id
    end

    def [](key)
      body[key.to_s]
    end
  end

  class UnauthorizedException < APIException; end

  class ForbiddenException < APIException; end

  class ConflictException < APIException; end

  class GemVersionException < APIException; end

  class GatewayTimeoutException < APIException; end

  class LockedException < APIException; end

  class ValidationException < APIException
    def errors
      self[:errors]
    end

    def each_error
      errors.each do |field, message|
        error = if field == 'base'
          message
        else
          [field.gsub('_',' ').capitalize, message].join(" ")
        end

        yield error
      end
    end
  end

  class NotFoundException < APIException
    def resource
      self[:resource].to_sym
    end

    def id
      self[:id]
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
shelly-0.5.7 lib/shelly/client/errors.rb
shelly-0.5.6 lib/shelly/client/errors.rb
shelly-0.5.5 lib/shelly/client/errors.rb
shelly-0.5.4 lib/shelly/client/errors.rb
shelly-0.5.3 lib/shelly/client/errors.rb
shelly-0.5.2 lib/shelly/client/errors.rb
shelly-0.5.1 lib/shelly/client/errors.rb
shelly-0.5.0 lib/shelly/client/errors.rb
shelly-0.4.42 lib/shelly/client/errors.rb
shelly-0.4.41 lib/shelly/client/errors.rb
shelly-0.4.40 lib/shelly/client/errors.rb
shelly-0.4.39 lib/shelly/client/errors.rb
shelly-0.4.38 lib/shelly/client/errors.rb
shelly-0.4.37 lib/shelly/client/errors.rb
shelly-0.4.36 lib/shelly/client/errors.rb
shelly-0.4.35 lib/shelly/client/errors.rb